Say you have 6 hosts that need to have a common file or directory (the common
usage for rsync).  You find that an update every N hours is good enough and
you want to code a cron job to make it happen.  You'd also like any host
that is off-line to 1) not mess up the others, and 2) sync on the way back
up.

The problem that I found most often was that the _master_ host would always
be the one to fail.  Murphy's law rules.


So I found a solution I like a lot, that I thought this list might want to
know about.  I put a unique name in DNS, like
        knowitall.foo.fred.com
that points to the present master for changes.  Then I run the sync cron
job on _all_ the hosts.   In the cron task I have a check at the top that
looks to see if this host is the master, if so exit the script.

If the KnowItAll host fails I move the DNS pointer and everyone else works.
When the old knowitall reboots he is a client rather than the server (and
I didn't have to change anything on the off-line host).

I run that same task at system boot before I start the service that uses
the data. So when any client is off-line for a Very Long Time then she
re-syncs at boot (even when she was just built and was _never_ in sync).

As a bonus you can use the KnowItAll record to guild the update job to
the correct host, if you need to.


A sample way to do this (on a Solairs host where /etc/hostname.* has the
IP addresses of your interfaces -- not the /etc/hosts names).

        # When we are the master we don't need to rsync (to ourself)
        IPLIST=`echo \`cat /etc/hostname.*\` | sed -e 's/ /|/g'`
        if /usr/sbin/nslookup kia.foo.fred.com |/usr/bin/egrep "$IPLIST" >/dev/null
        then
               exit 0
        fi

        # do the rsync...

Of course this is not 100% bullet proof (we should \quote the dots in the
sed command, -e 's/\./\\\\./g'), but it works for any local network address.

--
ksb

Reply via email to