Skip to Content

Trigger backups on connect with launchd

The fine folks at macresearch.org have put out an interesting tutorial that walks through setting up launchd and rsync to do automatic backups whenever a specific external drive is mounted. Loyal readers may note that this is similar to the core feature of Martian Lifeboat (which should not be confused with Mojave Shade's Lifeboat, as mentioned in several comments). The script, however, is free; Martian Lifeboat is not.

Although the currently published script leaves out the crucial -E flag to force rsync to copy resource forks (credit to Josh Wisenbaker of afp548.com for spotting the silent E), it's still a good primer on the power of launchd. For a simple way to create your own launchd configuration files, be sure to check out the powerful, open-source and free Lingon utility. If you try this out, let us know how it works for you.

[via macenterprise mailing list]

Categories

OS Terminal Tips

The fine folks at macresearch.org have put out an interesting tutorial that walks through setting up launchd and rsync to do automatic...
 

Add a Comment

*0 / 3000 Character Maximum

4 Comments

Filter by:
David

Try rsnapshot instead of rsync. It will automatically keep snapshots which are just hard links to the original files unless the file has changed, in which case it will copy the file. It requires somewhat more configuration than rsync, but is much more useful as a backup.

January 10 2007 at 11:22 AM Report abuse rate up rate down Reply
Blurred Vision

Have made some updates: backup script now supports multiple source dirs, a minimum interval between backups, and logging (so you can see what has been happening)

available for download at http://www.users.on.net/~aidanandjen/BlurredVisions/files/edc01be85bcd4f5ae1789fd9c290a20e-2.html

December 30 2006 at 9:52 PM Report abuse rate up rate down Reply
Blurred Vision

I have done some testing, and made some changes, and here is what I have found so far:

The script will run EVERY time ANY drive image is mounted or unmounted (including iPods). If you are like me, and your backup drive is connected for hours at a time, it means you will be needlessly backing up again and again. I think I will need to add some "time since last successful backup" checks so it will only run once every 24 hours.

The script also only handled 1 backuo source dir. If yo uare like me, this is not enough. This is fixed in teh script below.

I have converted the tcsh shell script to bashand added a few things, like logging, and multiple source dirs:
-- begin
#!/bin/bash

folderToBackup="/Users/ /Applications"
backupVolume="/Volumes/MyDrive"
backupTo="${backupVolume}/backup"
sleepFor=60

echo -n "[*]-- Autobackup envoked at `date`" | logger
echo -n "[*]-- Sleeping for ${sleepFor} seconds..." | logger
sleep ${sleepFor}

if [ ! -e ${backupVolume} ]
then
echo -n "[*]-- BackupVolume NOT connected - Exiting" | logger
exit 0
else
echo -n "[*]-- BackupVolume Connected - Continuing" | logger
fi

# Create the folder to back up the data to (defined above)

if [ ! -e ${backupTo} ]
then
echo -n "[*]-- Backupdir does not exist... Creating...)" | logger
mkdir -p ${backupTo}
else
echo -n "[*]-- Backupdir exists! - Continuing" | logger
fi

# Copy the files over. Here we are using rsync.
for i in ${folderToBackup}
do
echo -n "[*]-- Starting Rsync of ${i} to ${backupTo}" | logger
rsync -aqE --delete ${i} ${backupTo}
echo -n "[*]-- rsync of ${i} to ${backupTo} complete..."| logger
done
rsync -aqE --delete $folderToBackup $backupTo

# Optionally, once the rsync is done, unmount the drive.

#hdiutil detach $backupVolume

exit 0
-- end

December 29 2006 at 8:07 AM Report abuse rate up rate down Reply
Nik

You can do the same thing with a folder action AppleScript attached to the /Volumes/ directory, or by using Proxi in the same fashion (folder watcher trigger pointing at /Volumes/).

December 26 2006 at 1:15 AM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.