Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Trigger backups on connect with launchd' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Trigger backups on connect with launchd
Authored by: ptb@mac.com on Jan 10, '07 10:33:42AM

I've been using a similar script for a while now, except instead of rsync'ing to a hard drive, I rsync over the network to my home server (Mac mini). The problem is that when I'm at home, I need to use the Bonjour name (for this example I'm using "afp.local"), versus at work, I need to use it's public Internet hostname (for this example I'm using "afp.example.com"). The method I use to determine whether I'm at work or at home is to find the BSSID of the current AirPort base station and that gives me enough info.

I'm using launchd to execute a backup on a regular (timed) basis, instead of using a watch folder. Since I have a Mac on both ends of the line, I installed RsyncX on both systems and specify that binary so I can keep my resource forks (and other Mac specific bits).

I have also set launchd to run this as root, and I have set up ssh keys on both systems as root (in /var/root/.ssh/).


#!/bin/sh

username="steve"
hostname="mymac"

/bin/sleep 2

bssid=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | /usr/bin/awk '/BSSID/ { print $2 }'`

if [ $bssid = "00:60:1d:1e:26:39" ]
then
  location="Work"
  destuser="admin"
  desthost="afp.example.com"

elif [ $bssid = "00:0a:95:f1:e9:bc" ]
then
  location="Home"
  destuser="admin"
  desthost="afp.local"

fi

results1=`/usr/bin/sudo /usr/local/bin/rsync --archive --links --safe-links --delete --delete-excluded \
  --exclude=".DS_Store" --exclude=".Trash/" --exclude=".Trashes/" --exclude="Cache/" \
  --exclude="Caches/" --rsh=/usr/bin/ssh --rsync-path=/usr/local/bin/rsync --eahfs --stats \
  /Users/${username}/ ${destuser}@${desthost}:/Users/Shared/Backups/${hostname}/${username}/`

/usr/local/bin/growlnotify -n "Rsync Backup" -a "/Applications/Backup.app/" -m "Results of backup of \"${username}\""
/usr/local/bin/growlnotify -n "Rsync Backup" -a "/Applications/Backup.app/" -m "${results1}"
/usr/bin/logger -i -p daemon.notice Results of backup of "${username}" - "${results1}"

results2=`/usr/bin/sudo /usr/local/bin/rsync --archive --links --safe-links --delete --delete-excluded \
  --exclude=".DS_Store" --exclude=".Trash/" --exclude=".Trashes/" --exclude="Cache/" \
  --exclude="Caches/" --rsh=/usr/bin/ssh --rsync-path=/usr/local/bin/rsync --eahfs --stats \
  /Users/Shared/ ${destuser}@${desthost}:/Users/Shared/Backups/${hostname}/Shared/ --stats`

/usr/local/bin/growlnotify -n "Rsync Backup" -a "/Applications/Backup.app/" -m "Results of backup of \"Shared\""
/usr/local/bin/growlnotify -n "Rsync Backup" -a "/Applications/Backup.app/" -m "${results2}"
/usr/bin/logger -i -p daemon.notice Results of backup of "Shared" - "${results2}"

exit 0
Other possibly useful reading:

[ Reply to This | # ]
10.4: Trigger backups on connect with launchd
Authored by: macosx4me on Jan 11, '07 04:43:53AM
Please be very careful about using RsyncX. It is now quite dated and you should not really use it with 10.4 Rsync in 10.4 is at best a difficult proposition. I would suggest downloading and compiling 2.6.9 from source - samba.anu.edu.au and follow the instructions in patches/xattr.diff , compiling without ACL support (the provided ACL patch is for Linux ACLs).

[ Reply to This | # ]