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

Click here to return to the 'Persistent Growl notifications for long tasks' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Persistent Growl notifications for long tasks
Authored by: tedw on Oct 15, '10 08:31:43AM
Sure thing. Sorry if the script isn't as elegant as it could be ( I'm a b-class unix programmer - :-] ). I launch this from a Folder Action that's attached to /Volumes. When I mount the backup disk the folder action starts this script, and when the disk unmounts the folder action checks to see if this process is still running (and if necessary kills it). I've added a few extra comment lines for your benefit; let me know if something's not clear (or if there's something I could have coded better)

One important point: I'm using an updated version of rsync (3.0.7), hence the /usr/local/bin/rsync path. Leopard and Snow Leopard ship with an older version of rsync (2.6.9), and the rsync people changed the options in a non-backward compatible way. the -X option is the 3.0.x option for including extended attributes. That doesn't exist in 2.6.9 (which uses -E for extended attributed; -E in 3.0.x is for preserving executability), so these rsync commands would throw an 'unknown option' error on a standard install. I updated because 3.0.x handles resource forks better, fyi.

#! /bin/bash

# store the rsync pid so that I can abort the process if the drive gets disconnected
launchctl setenv backupPID $$

# create a sticky notification
/usr/local/bin/growlnotify -d note -a Finder -s 'Backup Begun'

# set main backup path

# backup downloads folder, without revisions
/usr/local/bin/rsync -aXq --delete --prune-empty-dirs $HOME/Downloads $backupPath 

# backup movies folder, without revisions
/usr/local/bin/rsync -aXq --prune-empty-dirs $HOME/Movies $backupPath \

# modify sticky notification to show first stage done
/usr/local/bin/growlnotify -d note -a Finder -s 'Downloads & Movies Complete'

# revisioned backups stored in a folder called 'dated backups
datedDirectory="$backupPath"'Dated backups/'

# set comparison list for link-dest for home files. this collects a list of all
# the current dated backup folders and hard-links against all of them (slight increase
# in rsync time, slightly more efficient storage)
list=$(ls -1 "$datedDirectory")
for item in $list; do
	if [ -d "$path" ]; then

# create a new dated backup folder
date=`date "+%Y-%m-%d_%H.%M.%S"`

# back up selected home directories with revisions
/usr/local/bin/rsync -aXq "${linkDirs[@]}" $HOME/ "$datedPath" \
	--filter='+ /Library' \
	--filter='+ /Library/LaunchAgents' \
	--filter='+ /Library/Scripts' \
	--filter='+ /Library/Mail' \
	--filter='+ /Library/StickiesDatabase' \
	--filter='+ /Library/Desktop Pictures' \
	--filter='+ /Library/Application Support' \
	--filter='- /Library/*' \
	--filter='+ /Xcode Projects' \
	--filter='+ /Documents' \
	--filter='+ /Desktop' \
	--filter='+ /Music' \
	--filter='+ /Sites' \
	--filter='+ /Pictures' \
	--filter='+ /Applications' \
	--filter='- /*' 
# redo link-dest comparison list.  I lump all my modified system files in
# a single folder, so I need to focus the comparison folders there.
for item in $list; do	
	if [ -d "$path" ]; then

# back up selected system files with revisions
/usr/local/bin/rsync -aXq "${linkDirs[@]}" /etc/ "$datedPath/system" \
	--filter='+ /apache2' \
	--filter='+ /fstab' \
	--filter='+ /hosts' \
	--filter='+ /php.ini*' \
	--filter='- /*' \

# delete the stored rsync pid
launchctl unsetenv backupPID

# modify notification to give 'all clear' notice, and remove stickiness 
/usr/local/bin/growlnotify -d note -a Finder 'Full Backup Complete'

[ Reply to This | # ]