I was inspired by Time Machine for every Unix out there to use the link-dest technique for backing up one external disk to another, however I found some limitations in its implementation, so I modified the script.
- Moved Source and Destination into variables.
- Added a Progress directory so the script can be interrupted and resumed.
- Added an exclude file to the Source directory so that the External disk’s special folders (Spotlight, etc) are not copied.
- Added the -E flag to rsync so it copies Extended Attributes on Mac OS X (remove if you are not using Mac OS X).
- Added the -x flag to rsync so it does not span disks.
- Added the –delete flag to rsync so if rsync fails upon re-running the script files deleted from the source are deleted from the Progress directory.
- Modified the Date format to mimic Time Machine’s.
- Modified the Destination so that it directly uses it rather than a subdirectory.
- Modified the symbolic link command so it removes the old Latest link and creates the new one in one step.
- Use && to ensure commands don’t occur if rsync fails.
The script (Updated to fix bug):
#!/bin/sh
source="/Volumes/Gray"
destination="/Volumes/Gray Backup"
mkdir -p "$destination/Progress"
rsync -aPEx --delete --exclude-from="$source/.exclude" \
--link-dest="$destination/Latest" \
"$source" "$destination/Progress" \
&& date=`date "+%Y-%m-%d-%H%M%S"` \
&& mv "$destination/Progress" "$destination/$date" \
&& ln -sfh "$date" "$destination/Latest"