#!/bin/sh # full and incremental backup script # created 07 February 2000 # Based on a script by Daniel O'Callaghan # and modified by Gerhard Mourani # modified more by Joel Aufrecht in 2002 for OpenACS servers # ######################################################################### # # Change the variables below to fit your computer/backup COMPUTER=$HOSTNAME # name of this computer BACKUPUSER=backup # username to own the files BACKUPDIR=/backup # where to store the backups TIMEDIR=$BACKUPDIR/last-full # where to store time of full backup TAR=/bin/tar # name and location of tar CHOWN=/bin/chown CHMOD=/bin/chmod SCP=/usr/bin/scp DIRECTORIES="/etc /root /cvsroot /var/qmail/alias /var/log/aolserver /usr/local/aolserver /web/openacs-prod /backup/openacs" # a list of paths to be backed up ######################################################################### # # OTHERHOST is optional. OTHERHOST= # another server, to receive backup # files # leave blank to skip scp exchange OTHERUSER=backup # the user on the recipient server # must have silent authentication, ie, # certificates ########################################################### # Shouldn't need to change anything below this line DOW=`date +%a` # Day of the week e.g. Mon DOM=`date +%d` # Date of the Month e.g. 27 DM=`date +%d%b` # Date and Month e.g. 27Sep DATE=`date +"%Y-%m-%d"` # Year, Month, Date, e.g. 20020401 mkdir -p $BACKUPDIR mkdir -p $TIMEDIR # On the 1st of the month a permanent full backup is made # Every Sunday a full backup is made # The rest of the time an incremental backup is made. # Each backup has a date-specific filename # # if NEWER = "", then tar backs up all files in the directories # otherwise it backs up files modified since the NEWER date. NEWER # gets its date from the file written every Sunday. # Figure out what to do and set variables case $1 in full) TYPE="full" NEWER="" DELETEOLD=0 ;; automatic) if [[ $DOM = "01" || ($DOW = "Sun") ]] then TYPE="full" NEWER="" NOW=`date +%Y-%m-%d` echo $NOW> $TIMEDIR/$COMPUTER-full-date else TYPE="incremental" NEWER="--newer-mtime `cat $TIMEDIR/$COMPUTER-full-date`" fi ;; *) echo "Usage: $0 full to force full backup, or $0 automatic to run automated. All other variables are set in the script." exit ;; esac # Do the actual work for directory in $DIRECTORIES do # strip directory of slashes when using it in the backup file name FULLNAME=$BACKUPDIR/$DATE-$COMPUTER-${directory//\//-}-backup-$TYPE.tar.bz2 tar -jcpsh $NEWER --file $FULLNAME $directory chown $BACKUPUSER $FULLNAME chmod 770 $FULLNAME if [[ -n $OTHERHOST ]] then scp -oProtocol=2 $FULLNAME $OTHERUSER@$OTHERHOST:$BACKUPDIR fi done