
Its been frustrating finding a good way to do tape backups with Linux. Almost all the software I've found out there either costs way too much, or is like the AMANDA package, way to complicated to just backup a single server.
I had found this script a while ago and was using it to do full and differentials to a second hard drive. Now that I'm running a tape drive, I did a few modifications and included some better statistics reporting. This will do a full backup nightly to a single tape.
This is what I've came up with. Save it and make it executable, run it in a cron job.
If you want to ignore individual files and directories, create a file called tbackup.ignore and add your line items there. Then uncomment out the end of the $TAR line with the --exclude-from=tbackup.ignore
#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>
# modified for tape use by Chad Amberg <http://www.bluestream.org>
#Change the 3 variables below to fit your computer/backup
DIRECTORIES="/etc /home /opt /root /var" # directories to backup
BACKUPTO=/dev/st0 # where to store the backups
TAR=/bin/tar # name and locaction of tar
#You should not have to change anything below here
PATH=/usr/local/bin:/usr/bin:/bin
START=`date +%s`
# Daily full backup
NEWER=""
echo "***** start time"
date
echo
if mt -f /$BACKUPTO status | grep "ONLINE"; then
echo "***** finding sockets"
find $DIRECTORIES -type s > sockets
echo
echo "***** setting compression on"
mt -f /$BACKUPTO compression 1
echo
echo "***** setting type to DLT 35 Compressed"
mt -f /$BACKUPTO setdensity 0x85
echo
echo "***** archiving"
$TAR $NEWER -cf $BACKUPTO $DIRECTORIES --exclude-from=sockets --absolute-names --totals # --exclude-from=tbackup.ignore
echo
echo "***** tape-drive status"
mt -f /$BACKUPTO status
echo
echo "***** ejecting tape"
mt -f /$BACKUPTO offline
echo
echo "***** end time"
date
else
echo "***** WARNING TAPE DRIVE IS OFFLINE, NO BACKUPS PERFORMED"
fi
FINISH=`date +%s`
diff=$((FINISH - START))
echo -n "***** Total Run Time: "
HRS=`expr $diff / 3600`
MIN=`expr $diff % 3600 / 60`
SEC=`expr $diff % 3600 % 60`
if [ $HRS -gt 0 ]
then
echo -n "$HRS hrs. "
fi
if [ $MIN -gt 0 ]
then
echo -n "$MIN mins. "
fi
if [ $SEC -gt 0 ]
then
if [ $MIN -gt 0 ]
then
echo "and $SEC secs."
elif [ $HRS -gt 0 ]
then
echo "and $SEC secs."
else
echo "$SEC secs."
fi
fi
#!/bin/bash
MAILTO="email@domain.com"
MAIL="/bin/mail"
if mt status | grep "ONLINE"; then
STATUS="online"
else
$MAIL -s "Backup Tape drive is Offline" $MAILTO < .
fi