Automatic Backup of USB Drive
I’ve started to keep some regularly-updated critical information on my USB thumb drive. Apple’s Time Machine doesn’t seem to be willing to back up external disks (or at least VFAT-formatted external disks). I figured I’d piggyback on Time Machine’s hourly backups by using rsync to copy the thumb drive periodically to my MacBook’s hard drive. OS X 10.5 still supports cron, but I keep running across references to launchd. After some googling, I came up with the following script:
#!/bin/bash test -e /Volumes/MCZ && rsync -avr --delete /Volumes/MCZ $HOME/Metabackup/ >& $HOME/Metabackup/MCZ.log
and the following plist describing the new “service” I wanted launchd to handle:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>znet.backups.mczthumb</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Users/mzwier/bin/backup-thumb.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>52</integer>
</dict>
</dict>
</plist>
This is exactly equivalent to the cron line
52 * * * * /bin/bash /Users/mzwier/bin/backup-thumb.sh
I saved the plist in ~/Library/LaunchAgents (as znet.backups.mczthumb) and ran launchctl:
launchd% load /Users/mzwier/Library/LaunchAgents/znet.backups.mczthumb
Worked on the first try. It may be useful to perform an update every time the drive is mounted, but that’s a challenge for another day.
Tags: OS X
You can comment below, or link to this permanent URL from your own site.