Introduction
I'm using rsync to backup my data to an external USB disk. I keep forgetting to do it, so automation is what I need. This procedure doesn't just apply to rsnapshot, it should work with any backup method that can be initiated from the command line.
The basic idea
Whenever a disk is plugged, Finder will automatically mount it to /Volumes. Monitoring the /Volumes directory for changes is enough to detect the change and then we can look whether the backup volume is actually present.Configuration
We basically need to create two things: a launchd config file and a shell script.
The launchd configuration file is in the plist format. It's most conveniently created with the Property List Editor, but an ordinary text editor such as vim or TextEdit is fine, too. The format of the configuration file is documented in the launchd.plist man page that can be read using the following command:
man launchd.plist
The plist file needs to go into Library/LaunchAgents (in your home directory) and it needs to have a .plist extension. The rest of its name is arbitrary. On my system the plist file is called Library/LaunchAgents/volume-connected.plist and has the following configuration options defined:
| Label | volume-connected |
|---|---|
| LowPriorityIO | true |
| Program | /Users/user/bin/volume-connected |
| ServiceDescription | Do things upon mounting volumes |
| StandardErrorPath | /tmp/volume-connected.err |
| StandardOutPath | /tmp/volume-connected.out |
| WatchPaths | /Volumes |
#!/bin/sh
# I'm executed on MacOSX when a new volume is conncted.
BACKUP_ROOT=/Volumes/USB/rsnapshot/.sync
if test -d ${BACKUP_ROOT}
then
if [ "`ls -dl --time-style='+%m' ${BACKUP_ROOT} | sed 's!^.* \([0-9]\{2\}\) /.*$!\1!'`" != "`date '+%m'`" ]
then
/where/bin/rsnapshot -v monthly
fi
/where/bin/rsnapshot -v sync
fi
| < Prev | Avanti > |
|---|








