This is the backup script that I use for my weekly backups. You will need to create the file /var/log/backup.log. If you are running logrotate, make sure you add this log file to it. Download the source here.
#!/bin/bash
cd / # set directory
HOST=`/bin/hostname -s` # Set the hostname variable
DATE=`/bin/date +'%m-%d-%Y'` # Set the date variable
BKDEV='/dev/sda11' # Set the backup device variable
MCMD='mount -t smbfs -o username=user,password=password //pc/dir /mnt/backup' # Set the mount command variable
BKDIR='/mnt/backup' # Set the backup directory variable
LOGDIR='/var/log' # Set log directory variable
LOG='backup.log' # Set log file variable
# Check for log file, if non exsistant, create one
FILETEST=0
while [ $FILETEST = 0 ];
do
FILETEST=`ls $LOGDIR | grep $LOG | grep -v grep | wc -l`
if [ $FILETEST = 0 ]; then
touch $LOGDIR/$LOG
fi
done
# Log start time to /var/log/backup.log.
echo "start weekly backup "${DATE} >> $LOGDIR/$LOG
# See if share is mounted, if not, mount it
MTEST=0
while [ $MTEST = 0 ];
do
MTEST=`df -h | grep backup | grep -v grep | wc -l`
if [ $MTEST = 0 ] ; then
$MCMD
fi
done
# Log mounted share confirmation to /var/log/backup.log.
echo "share mounted" >> $LOGDIR/$LOG
# start backup
tar cvfz $BKDIR/${HOST}-scripts-${DATE}.tar.gz bin sbin
tar cvfz $BKDIR/${HOST}_boot-${DATE}.tar.gz boot
tar cvfz $BKDIR/${HOST}_etc-${DATE}.tar.gz etc
tar cvfz $BKDIR/${HOST}_home-${DATE}.tar.gz home
tar cvfz $BKDIR/${HOST}_usr-${DATE}.tar.gz usr
tar cvfz $BKDIR/${HOST}_lib-${DATE}.tar.gz lib lib64
tar cvfz $BKDIR/${HOST}_root-${DATE}.tar.gz root
tar cvfX $BKDIR/${HOST}-var_${DATE}.tar /root/setup/scripts/tarex /var
gzip $BKDIR/${HOST}-var_${DATE}.tar
# Unmount share
while [ $MTEST = 1 ];
do
MTEST=`df -h | grep $BKDIR | grep -v grep | wc -l`
if [ $MTEST = 1 ] ; then
umount $BKDIR
fi
done
# Log mounted share confirmation to /var/log/backup.log.
echo "share umounted" >> $LOGDIR/$LOG
# Log stop time to /var/log/backup.log.
echo "stop weekly backup "${DATE} >> $LOGDIR/$LOG
echo >> $LOGDIR/$LOG
cd / # set directory
HOST=`/bin/hostname -s` # Set the hostname variable
DATE=`/bin/date +'%m-%d-%Y'` # Set the date variable
BKDEV='/dev/sda11' # Set the backup device variable
MCMD='mount -t smbfs -o username=user,password=password //pc/dir /mnt/backup' # Set the mount command variable
BKDIR='/mnt/backup' # Set the backup directory variable
LOGDIR='/var/log' # Set log directory variable
LOG='backup.log' # Set log file variable
# Check for log file, if non exsistant, create one
FILETEST=0
while [ $FILETEST = 0 ];
do
FILETEST=`ls $LOGDIR | grep $LOG | grep -v grep | wc -l`
if [ $FILETEST = 0 ]; then
touch $LOGDIR/$LOG
fi
done
# Log start time to /var/log/backup.log.
echo "start weekly backup "${DATE} >> $LOGDIR/$LOG
# See if share is mounted, if not, mount it
MTEST=0
while [ $MTEST = 0 ];
do
MTEST=`df -h | grep backup | grep -v grep | wc -l`
if [ $MTEST = 0 ] ; then
$MCMD
fi
done
# Log mounted share confirmation to /var/log/backup.log.
echo "share mounted" >> $LOGDIR/$LOG
# start backup
tar cvfz $BKDIR/${HOST}-scripts-${DATE}.tar.gz bin sbin
tar cvfz $BKDIR/${HOST}_boot-${DATE}.tar.gz boot
tar cvfz $BKDIR/${HOST}_etc-${DATE}.tar.gz etc
tar cvfz $BKDIR/${HOST}_home-${DATE}.tar.gz home
tar cvfz $BKDIR/${HOST}_usr-${DATE}.tar.gz usr
tar cvfz $BKDIR/${HOST}_lib-${DATE}.tar.gz lib lib64
tar cvfz $BKDIR/${HOST}_root-${DATE}.tar.gz root
tar cvfX $BKDIR/${HOST}-var_${DATE}.tar /root/setup/scripts/tarex /var
gzip $BKDIR/${HOST}-var_${DATE}.tar
# Unmount share
while [ $MTEST = 1 ];
do
MTEST=`df -h | grep $BKDIR | grep -v grep | wc -l`
if [ $MTEST = 1 ] ; then
umount $BKDIR
fi
done
# Log mounted share confirmation to /var/log/backup.log.
echo "share umounted" >> $LOGDIR/$LOG
# Log stop time to /var/log/backup.log.
echo "stop weekly backup "${DATE} >> $LOGDIR/$LOG
echo >> $LOGDIR/$LOG