Thanks so much for all of your suggestions guys. I ended up with something like this which resulted in part from a need to get my backups onto a Windows Server and to get an email when it happens (or if it doesn't).
#!/bin/bash BACKUPDIR="/home/USERNAME/backup" WHATTOBACKUP="/var/www" SERVERNAME="SERVERNAME" BACKUPADMIN="[email protected]" MESSAGE="/tmp/message.txt" if [ -d $BACKUPDIR -a -d $WHATTOBACKUP ] #make sure the source & dest dirs exist then #backup the directory /bin/tar -cpzf $BACKUPDIR/`date +%a"-"%d"-"%b"-"%Y"-"`backup.tar.gz $WHATTOBACKUP #then remove anything over 7 days old find $BACKUPDIR/*.tar.gz -mtime +7 -exec rm -f {} \; #And let us know what happened SUBJECT="Backup Completed" TO=$BACKUPADMIN echo "Backup of $SERVERNAME completed" >> $MESSAGE echo "Result of backup" >> $MESSAGE echo "`ls -alt` $BACKUPDIR" >> $MESSAGE /usr/bin/mail -s "$SUBJECT" "$TO" < $MESSAGE rm $MESSAGE else #if backup dir does not exist, tell us SUBJECT="Backup Failure" TO=$BACKUPADMIN echo "Error backing up $SERVERNAME" >> $MESSAGE echo "One of the following directories is missing: $BACKUPDIR $WHATTOBACKUP " >> $MESSAGE echo "Date: `date`" >> $MESSAGE /usr/bin/mail -s "$SUBJECT" "$TO" < $MESSAGE rm $MESSAGE fi
-- [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
