Practicality of backing up huge hard drives (was Re: [mythtv-users] Dieing Hard Drive)

Matthew Schumacher schu at schu.net
Tue Mar 15 16:17:33 UTC 2005


I haven't followed this thread, but thought I would post my backup 
script in case it is useful to someone.

It uses rsync to rotate the backup, and it keeps the disk space down 
because files that remain the same though the rotations are hard links 
to the same physical space on the disk.  This allows you to have a 7 day 
rotation, while the disk space used is kept to the sum of the data and 
the change over the last 7 days.

schu

-------------- next part --------------
#!/bin/bash

#
# Schu's backup rotation script modified from http://www.mikerubel.org/computers/rsync_snapshots/
# 
# Dirs in the includes file are appended to the backupsource and backed up. So if /etc/rotateBackup.includes
# contains 'var' on a line and the backup source is '/' then /var will be backed up.
#

# user changable stuff
BACKUPSOURCE=/
BACKUPDEST=/backup
EXCLUDES=/etc/rotateBackup.excludes
INCLUDES=/etc/rotateBackup.includes

# make sure we're running as root
if (( `id -u` != 0 )); then { echo "Sorry, must be root.  Exiting..."; exit; } fi

# if the excludes file does exist then touch it
if [ ! -f $EXCLUDES ]; then
  touch $EXCLUDES
fi

# if the includes file does exist then touch it
if [ ! -f $INCLUDES ]; then
  touch $INCLUDES
fi

# now rotate snapshots 

# step 1: delete the oldest snapshot, if it exists:
if [ -d $BACKUPDEST/backup.6 ]; then
  rm -rf $BACKUPDEST/backup.6
fi

# step 2: shift the middle snapshots(s) back by one, if they exist
if [ -d $BACKUPDEST/backup.5 ]; then
  mv $BACKUPDEST/backup.5 $BACKUPDEST/backup.6
fi;

if [ -d $BACKUPDEST/backup.4 ]; then
  mv $BACKUPDEST/backup.4 $BACKUPDEST/backup.5
fi;

if [ -d $BACKUPDEST/backup.3 ]; then
  mv $BACKUPDEST/backup.3 $BACKUPDEST/backup.4
fi;

if [ -d $BACKUPDEST/backup.2 ]; then
  mv $BACKUPDEST/backup.2 $BACKUPDEST/backup.3
fi;

if [ -d $BACKUPDEST/backup.1 ]; then
  mv $BACKUPDEST/backup.1 $BACKUPDEST/backup.2
fi

# step 3: make a hard-link-only (except for dirs) copy of the latest snapshot,
# if that exists
if [ -d $BACKUPDEST/backup.0 ]; then
  cp -al $BACKUPDEST/backup.0 $BACKUPDEST/backup.1
fi;

# step 4: rsync from the system into the latest snapshot (notice that
# rsync behaves like cp --remove-destination by default, so the destination
# is unlinked first.  If it were not so, this would copy over the other
# snapshot(s) too!
rsync -va -r --delete --delete-excluded --files-from="$INCLUDES" --exclude-from="$EXCLUDES" $BACKUPSOURCE/ $BACKUPDEST/backup.0

# step 5: update the mtime of hourly.0 to reflect the snapshot time
touch $BACKUPDEST/backup.0


More information about the mythtv-users mailing list