Master rsync script for many file servers
"Geoffrey Scott" <[email protected]> Wed, 10 May 2006 17:22:30 +1000
| Newsgroups | gmane.org.user-groups.mlug.main |
|---|---|
| Message-ID | <9DE681DC93551E4FA4C5B50D8BD90F3017D5C9@gfh-mail-01.guestsfurniturehire.com.au> |
Hi people,
I have a brainteaser for you.
I am trying to write a grand unified rsync script that will backup a
number of servers spread throughout the country to one central server.
I need some help with dealing with servers that don't conform to the
company standard. What I have got in my bash script so far is this:
========================================================================
==========================
# The servers that we want to rsync
SERV2B="serv1 serv2 serv3"
# Rsync - archive, compress and recursive
OPTS1="-avzrA --delete"
# As above, but the -R option sets relative paths
OPTS2="-Ravzr --delete"
# Rsync but don't delete
OPTS3="-avz"
# We start here on a server by server basis
for b in $SERV2B
do
# Check that each server is up and live.
if [ `ping -c 4 $b | grep "64 bytes" | wc -l` = 4 ]
then
# Shut down some services on the servers defined in SERV2B.
# If we are dealing with Debian boxes the scripts need symlinks to
# bring them in line with the Suse and Redhat boxes.
for s in smb cups
do
ssh root@$b /etc/init.d/$s stop
done
# Rsync /home, /etc/cups, samba things, and then make a new smb.conf
# from the master-smb.conf on backup-serv and the local.conf on each
server.
rsync $OPTS1 root@$b:/home /home/backups/$b/
rsync $OPTS1 root@$b:/etc/cups /home/backups/$b/
rsync $OPTS3 /etc/samba/master-smb.conf root@$b:/etc/samba/
rsync $OPTS3 /root/scripts/createSmbConf.bash
root@$b:/root/scripts/
ssh root@$b /root/scripts/createSmbConf.bash
# Start up some services on the servers defined in SERV2B
for s in smb cups
do
ssh root@$b /etc/init.d/$s start
done
fi
done
========================================================================
==========
But what if serv3 is quite different to the others, and I don't want to
treat it in the same fashion or pull it into line with the company
standard? I considered using "case" somehow, like this:
========================================================================
===================
case $SERV2B in
serv3)
different set of commands to deal with special case
*)
Standard commands for standard servers
;;
========================================================================
=================
But from reading the bash man pages, I don't think that it's going to
work that way. Can anyone suggest something better?
I know I could make another script that called the rsync backup script
with the server name as an argument and then "case" in the rsync script
would be easy to use, like this:
==============================================================
SERV2B="serv1 serv2 serv3"
for b in $SERV2B
do
./rsync-script.bash $b
done
==============================================================
But I was hoping someone could teach me a more pro way........
Regards Geoff Scott
----------------------------------