Luckily, I have a backup

A brief power cut early this evening seems to have knocked out at least two partitions on a big hard drive on my home server/workstation that holds my entire mp3 collection, photos and MySQL backup dumps. Luckily, I have a backup, and the one partition I’ve added data to since the last backup (my photos) appears to be readable, thank fsck.

It is so worth having a backup strategy for home use, so I thought I’d take this opportunity to outline mine. I have three machines – a house server/workstation, a scratch box, and a laptop. I back up the laptop to the house server, ignore the scratch box, and back up the house server to a Seagate USB hard disk. I’ve been thinking about sorting out a NAS of some kind but right now a couple of big-ish disks are adequate.

The reason I’m comtemplating NAS is because right now my backups rely on self discipline – hence the fact that there are a few photos missing from the most recent one. I have to attach the USB hard disk and run a script manually. It would be better to have a NAS appliance sitting in a cupboard and a cron job. Then all I’d have to worry about would be off-site backups. And you think I’m joking.

As for the script/backup method, well if you’re on any kind of *nixen it’s just got to be rsync. There really is not competition here. If you’re stuck in the world of Windows NT then I suppose that you can use the supplied NT Backup software, not a patch on rysnc but functions well enough if you can be arsed with the clunky GUI. Last time I looked the Win32 port of rsync wasn’t doing much.

Anyway, here’s my current crude-but-effective rsync script. The Seagate drive is labelled SEAGATE and formatted ext3. GNOMEs volume manager widget just detects and mounts it on power up. I like to keep things as simple as possible, so the script doesn’t have as much error handling as I might put in normally, but I run a few checks before kicking it off. Comments and queries more than welcome, and if you use this code then not only do I pity you I also disavow all responsibility for any damage you might end up doing to your data.


# $Id: seagate-backup,v 1.4 2007/07/26 21:33:30 sam Exp $

# Array containing list of directories to back up:
"/home" \
"/media/music" \
"/media/photos" \
"/var/spool/mail" \
"/var/www" \

# Mount point for the USB hard disk:

# check we're running as root:
if [ $UID != 0 ]; then
    echo "Script must be run as root! Aborting."
    exit 1

# check mount point:
if [ ! -d $SEAGATE ]; then
    echo "$SEAGATE not found! Check backup medium."
    exit 1

# Set up arguments to use with rsync.
if [ -n "$1" ]; then
    if [ $1 == "--delete" ]; then
	ARGS="-avz --delete"
	echo "bad argument: ${1}, exiting."
	exit 1

# locate rsync and basename
RSYNC=`which rsync`
BASENAME=`which basename`

# go through $BACKUPDIRS doing checks and backing up:
for i in "${BACKUPDIRS[@]}"; do
    if [ ! -d $i ]; then
	echo "Skipping ${i}: not found!"
    elif [ `ls -la ${i}/ | wc -l` = 3 ]; then
	echo "Skipping ${i}: appears to be empty!"
	echo "Backing up ${i}, please wait..."

# bye...
exit 0

This entry was posted in Uncategorized by Sam. Bookmark the permalink.