Posted Oct 22, 05:04 PM in News by Scott Conley
Someone asked-- ok so it was months ago-- but nonetheless, they asked. So here's the core of my Unison setup.
There are files stored in two directories. One is the usual executable script-type stuff, often in ~/bin. The other is Unison's user-specific path, typically ~/Library/Application Support/Unison.
Taking the latter first, I built a simple Unison configuration file for my hourly backup process. This I intended to cover my core user path, but exclude the heavy media and some assorted cache and log files (including Unison's own archive files- wouldn't that be fun). Note that my local and remote user IDs are both 14to9uid, by chance. The script will operate on any users/paths.
~/Library/Application Support/Unison/hourly.prf#Unison preferences file for hourly backup root = /Users/14to9uid/ root = ssh://14to9uid@ssh.14to9.org:9999//Users/14to9uid/ ui = text batch = true path = Documents path = Downloads path = Desktop path = backup path = bin path = Public path = Library/Application Support/Scorecard path = Library/Application Support/Unison path = Library/Application Support/Adium 2.0/Users/Default/Logs path = Library/Application Support/Cultured Code ignore = Path */.svn/* ignore = Name .DS_Store ignore = Path Users/14to9uid/backup/logs ignore = Regex .*key/thumbs/.* ignore = Regex Library/Application Support/Unison/ar.* log = true logfile = /Users/14to9uid/backup/logs/hourly.log
This is testable with a brief, straightforward script: Clean up the log file from the previous run and kick off the 'hourly' preference file. The various other command line params are described in the Unison docs, but primarily are geared towards making the script as quiet as possible (Unsion, please don't launch your GUI!).
~/bin/unisonHourly.sh#!/bin/bash echo "Running unison hourly sync process." rm -f /Users/scranky/backup/logs/hourly.log unison -ui text -silent -batch hourly -prefer ssh://14to9uid@ssh.14to9.org:9999//Users/14to9uid/
You can test this thing directly from your Terminal:
limejello-air:~ $ bin/unisonHourly.sh Running unison hourly sync process. 2008-10-22 15:51:32.347 Unison[466:100b] *** _NSAutoreleaseNoPool(): Object 0x209ea0 of class NSThread autoreleased with no pool in place - just leaking Stack: (0x90247cdf 0x90154562 0x9015a2c4 0xabf5 0x2c1c 0x2b86) 2008-10-22 15:51:32.351 Unison[466:100b] Calling nonGuiStartup 2008-10-22 15:51:33.238 Unison[5859:110b] *** _NSAutoreleaseNoPool(): Object 0x209dd0 of class NSThread autoreleased with no pool in place - just leaking Stack: (0x966c4cdf 0x965d1562 0x965d72c4 0xabf5 0x2c1c 0x2b86) 2008-10-22 15:51:33.241 Unison[5859:110b] Calling nonGuiStartup Connected [//limejello-air.local//Users/14to9uid -> //orangejello.local//Users/14to9uid] limejello-air:~ $ limejello-air:~ $ limejello-air:~ $
Ok, the NSautoreleaseNoPool garbage is irritating, but harmless in this case. (If only I knew someone in Apple's Objective-C runtime team... Josh!)
Finally, I had to register a scheduled process with Apple's LaunchAgent (man launchd for further detail) to run the thing every hour (at twenty past).
~/Library/LaunchAgents/org.14to9.sync.hourly.plist<?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>Label</key>
<string>org.14to9.sync.hourly</string>
<key>ProgramArguments</key>
<array>
<string>/Users/14to9uid/bin/unisonHourly.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>20</integer>
</dict>
</dict>
</plist>
Register this thing with launchctl and you're good to go.
limejello-air:~ $ launchctl load Library/LaunchAgents/org.14to9.sync.hourly.plist limejello-air:~ $ launchctl start org.14to9.sync.hourly limejello-air:~ $ limejello-air:~ $
You can use other .prf files to manage the more-or-less volatile areas of your system and register them with different launchd configurations.
Hope this helps!
Rate this article:
