One-step backup and burn to CD/DVD

May 20, '04 10:13:00AM

Contributed by: ataraxia

There seems to be a lot of interest in The Backup Problem lately, so I thought I'd give mine away. It's a shell script that contains a list of things to backup, and produces a burned disc in one step. It also includes a NetInfo dump.

Read the rest of the hint for the script...

This must be run as root (I use sudo) and if you run it with -e, it will skip erasing the disc first. Obviously you must change the list of contents to something useful to you.

#!/bin/sh

if [ "$USER" != "root" ]; then
  echo "You must be root to use this program"
  exit 1;
fi

[ "$1"x = "-e"x ] || erase="-erase"

tgt=/tmp/stagebackup
contents=" /Users/ataraxia/Documents \
  /Users/ataraxia/Library \
  /Users/ataraxia/Pictures \
  /Users/ataraxia/.tin \
  /Users/ataraxia/.vimrc \
  /Users/ataraxia/.zshenv \
  /Users/ataraxia/.zshrc \
  /Users/ataraxia/.cvsrc \
  /Users/ataraxia/.newsrc \
  /private/etc \
  /usr/local \
  /var/root \
  /Library/Preferences \
  /Library/StartupItems "

for item in $contents; do
  ditto -v --rsrc $item $tgt$item
done

echo "Dumping NetInfo"
nidump -r / . > $tgt/netinfo.local

echo "Size of backup: `du -sh $tgt | cut -f1`"
set -o errexit
hdiutil makehybrid -o /tmp/bkup $tgt -default-volume-name "Backup `date +%m/%d`"
hdiutil burn $erase /tmp/bkup.iso
echo "Cleaning Up"
rm -rf $tgt /tmp/bkup.iso

echo "Done!"
[robg adds: Have I mentioned lately the importance of backing up your critical files? With the latest threats running around, and (at least in my case) the occasional stupid user error, backups are very important. Find a method you like, stick with it, and (very important) test your backups occasionally!]

Comments (15)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2004051722071147