#!/bin/bash # # Extracted from the mailing list # # Date: Wed, 10 Oct 2001 16:12:16 -0500 # From: Rich Puhek # To: isp-linux@isp-linux.com # Subject: [isp-linux] Re: Duplicating Servers # # # Script to backup via rsync -- pull style (to chef). # # Script by Rich Puhek (rpuhek@etnsystems.com) # REMOTE_HOSTS="LIST_GOES_HERE"; #Test hosts singly, then add to list above. Remaining hosts to add: #If a host is specified... just rsync that one... #can also specify multiple hosts... if [ $# -gt 0 ]; then echo "host given on command line, backing up $@"; REMOTE_HOSTS=$@; fi; USER="root"; #USER="BACKUP"; myname=`uname -n`; BACKUPPATH="/var/local/backups"; OLDLOGS="/var/local/oldlogs"; datestamp=`date`; datefile="/var/log/rap_backup.log"; echo "rap backup started on: $datestamp" >> $datefile; # (Sample mostly...) EXCLUDE=" --exclude *.tmp \ --exclude *.temp \ --exclude rap_backup.log"; for host in $REMOTE_HOSTS; do echo "backing up $host"; rsync -a -e ssh $EXCLUDE $USER@$host:/etc/ $BACKUPPATH/$host/etc >> $datefile; rsync -a -e ssh $EXCLUDE $USER@$host:/root/ $BACKUPPATH/$host/root >> $datefile; rsync -a -e ssh $EXCLUDE $USER@$host:/boot/ $BACKUPPATH/$host/boot >> $datefile; rsync -a -e ssh $EXCLUDE $USER@$host:/usr/local/ $BACKUPPATH/$host/usr/local >> $datefile; # # Host specific sections go here!! # case $host in host1.foo.com) # host1.foo.com has his own /home directory, not an NFS mount, so we must back that up # seperately... rsync -a -e ssh $EXCLUDE --exclude Maildir/* $USER@$host:/home/ $BACKUPPATH/$host/home >> $datefile ;; host2.foo.com) # Backup the web pages on this host. Exclude *.pdf files, since one customer has # way too many of them (and are non-critical in this application) rsync -a -e ssh $EXCLUDE --exclude *.pdf $USER@$host:/var/www/ $BACKUPPATH/$host/var/www >> $datefile ;; *) ;; esac done; #Now let's go back and do the log files. I wait until now # so that the critical areas get done first!!! for host in $REMOTE_HOSTS; do echo "backing up log files from $host"; rsync -a -e ssh $EXCLUDE $USER@$host:/var/log/ $OLDLOGS/$host >> $datefile; done; datestamp=`date`; echo "rap backup finished on: $datestamp" >> $datefile; ############################################################################