The command-line utility rsync synchronizes files and directories, and can be used as a tool for backing up important data to external or remote drives. The version of rsync that comes with Mac OS X 10.4 has the ability to include "extended attributes" of files (such as resource forks) when invoked with the -E switch. However, rsync -E fails when used with a large number of files because the Spotlight indexer gets overwhelmed. The command exits with the error:
rsync: fstat failed: No such file or directory
To avoid this error, you can switch off Spotlight indexing for the duration of the sync process.
Thus, a simple backup script might look like this:
#!/bin/sh
EXCLUDES="--exclude tmp* --exclude *Cache* --exclude .Trash*"
# Function for toggling Spotlight indexing
spotlight_switch()
{
/usr/bin/mdutil -i $1 /
/usr/bin/mdutil -i $1 /Volumes/Backup
}
# Syncing /Users to /Volumes/Backups
! test -d /Volumes/Backup && echo "Please mount the backup drive!" && exit
spotlight_switch off
/usr/bin/rsync -avE --delete $EXCLUDES /Users /Volumes/Backup
spotlight_switch on
Since mdutil needs superuser privileges to work, the script has to be executed with sudo. For more information on how to use rsync, take a look at its man page.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20051104185525439