I use rsnapshot which uses rsync and does incremental/full backups really well.
I wrote a shell script that I run from a cron job to mount the disk, run rsnapshot, then umount the disk, so it is not mounted all the time.
Here are the scripts I use. The first is /usr/local/sbin/backup.sh, which basically is a wrapper around the script that does the real work, captures its output and exit status, and then emails the results to root:
#!/bin/sh
#
# Run the dobackup script, capturing the output and then mail it to the
# backup alias person with the right subject line.
#
BACKUP_TYPE=daily
if [ "a$1" != "a" ] ; then
BACKUP_TYPE=$1
fi
/usr/local/sbin/dobackup.sh ${BACKUP_TYPE} < /dev/null > /tmp/backup.txt 2>&1
RET=$?
SUBJECT="${BACKUP_TYPE} backup for $(hostname) (ERRORS)"
if [ "a$RET" = "a0" ] ; then
SUBJECT="${BACKUP_TYPE} backup for $(hostname) (successful)"
elif [ "a$RET" = "a2" ] ; then
SUBJECT="${BACKUP_TYPE} backup for $(hostname) (WARNINGS)"
fi
mail -s "$SUBJECT" root < /tmp/backup.txt
exit $RET
And here is /usr/local/sbin/dobackup.sh, which is the real workhorse:
#!/bin/sh
#
# Perform the backup, returning the following return codes:
#
# 0 - backup successful
# 1 - errors
# 2 - backup successful, but with warnings.
#
if [ -e /dev/sdb1 ] ; then
BACKUP_DEV=/dev/sdb1
else
echo "No backup device available."
echo "CANNOT CONTINUE WITH BACKUP."
exit 1
fi
BACKUP_DIR=/mnt/backup
BACKUP_TYPE=daily
if [ "a$1" != "a" ] ; then
BACKUP_TYPE=$1
fi
echo "Performing ${BACKUP_TYPE} backup."
umount $BACKUP_DEV 2> /dev/null
mount $BACKUP_DEV $BACKUP_DIR
if [ "a$?" != "a0" ] ; then
echo "Error occurred trying to mount the external drive with the following command:"
echo " mount $BACKUP_DEV $BACKUP_DIR"
echo "CANNOT CONTINUE WITH BACKUP."
exit 1
fi
date
rsnapshot $BACKUP_TYPE
RET=$?
date
if [ "a$RET" = "a0" ] ; then
echo "Snapshot performed successfully."
elif [ "a$RET" = "a2" ] ; then
echo "Snapshot performed, but with warnings."
else
echo "Snapshot had errors (returned ${RET})."
fi
umount $BACKUP_DIR
if [ "a$?" != "a0" ] ; then
echo "Error occurred trying to unmount the external drive with the following command:"
echo " umount $BACKUP_DIR"
exit 1
fi
exit $RET
Modify the BACKUP_DEV
and BACKUP_DIR
variables to suit.