My super-backup adventure!
Posted by bwakefield on 8th November 2007
So, a few months ago I embarked on an adventure that involved backing up our production webserver to tape. Yes, tape. A really big, hunk of magnetized plastic. It was a long trip, took way more time than one would think is necessary. First, the Powervault unit was not even powered on, go figure. Then a second trip down to the server room reveled that the SCSI cable was not plugged into the correct channel! So after all that was resolved, the trick was getting the data backed up properly. Here is how our data (that needs backed up) is laid out:
/home/clients - all of our clients web files are stored her.
/var/www/[hosted domain] - we have several hosted domains, both from a couple clients and some sites we run ourselves.
We are also making use of AutoMySQLbackup and the files that it creates need to be stored long term on the tape as well. So here is what I did…
# Server Backup - VAR and HOME
# Create individual tar/gz files
#####################################################################################
mkdir /backup/`date +‘%F-%a’`
tar -cvvzf /backup/`date +‘%F-%a’`/hosteddomain1-www-`date +‘%F-%a’`-tar.gz /var/www/hosted1
tar -cvvzf /backup/`date +‘%F-%a’`/hosteddomain2-www-`date +‘%F-%a’`-tar.gz /var/www/hosted2
tar -cvvzf /backup/`date +‘%F-%a’`/clients-`date +‘%F-%a’`-tar.gz /home/clients
#####################################################################################
# Write some information to the log file
#####################################################################################
echo “————————————————————-” >> /home/backup/backup.log
echo “Full Backup for:” >> /home/backup/backup.log
date >> /home/backup/backup.log
echo “————————————————————-” >> /home/backup/backup.log
du -sh /backup/`date +‘%F-%a’`/* >> /home/backup/backup.log
du -sh /backup/sql/latest/ >> /home/backup/backup.log
echo “————————————————————-” >> /home/backup/backup.log
#####################################################################################
# Delete the tar/gz files once they are written to tape
#####################################################################################
#delete the previous backup which is stored on disk for easy access, create the new ‘lastest’ for the files and SQL
rm /backup/latest
mv /backup/`date +‘%F-%a’`/* /backup/latest
cp -R /backup/sql/latest /backup/latest/sql
#####################################################################################
# add total backup size to log file
#####################################################################################
echo “Total backup size:” >> /home/backup/backup.log
du -sh /backup/latest >> /home/backup/backup.log
echo “————————————————————-” >> /home/backup/backup.log
echo “” >> /home/backup/backup.log
#####################################################################################
# Copy backed up tar/gz files to the tape drive with the latest SQL backup
#####################################################################################
tar cfv /dev/tape /backup/latest
This code keeps the latest backup on the disk for easy access as well as puts it to the tape. I try to keep a basic log file to have an idea what has been written and how large it was. I haven’t found a good way to keep a running count of how much has been written to the tape yet. Once I do, the log file will be simplified quite a bit. This script is run M/W/F and a similar script that backups only the SQL files Sa/Su/T/R.
There were a few sites that were of great help getting the tape backup working well:
http://www.whoopis.com/howtos/tapebackup.html
http://www.cyberciti.biz/faq/linux-tape-backup-with-mt-and-tar-command-howto/
There was another site, which I don’t have handy at the moment, but I will update as soon as I find the link.
Posted in Computers & IT, Linux | No Comments »
