blog advertising is good for you


blog advertising is good for you
User login

Complete Bi-Directional Home Sync and Backup with Unison

johnamrhein@gmail.com asks:

Question

Hi, could you give folks who aren’t familiar with the Terminal a little introduction to how we could use Unison for syncing one user account across two computers which are on the same network? The Unison guide is a little thin for those who don’t usually venture to open the Terminal and who don’t know much about Unix style commands. Thanks a million. John

Answer

You’ll need a machine acting as a server for this, and you’ll need Unison1 installed on both machines.

Preparing

All good toys need a little setting up (at least the ones here) and this one is no different. Unison works a lot like rsync in that a local copy calls a remote copy and they chat it up over an SSH-encrypted pipe. Thus, you’ll need a copy of Unison on both machines unless you’re syncing with a second drive, in which case you obviously just need the one copy.

Your Mac

Ensure the Developer Tools are installed on your computer (this is essentially a prerequisite for answers on this site) and then download Darwin Ports and install it. Update it and then get Unison with it.

$ sudo /opt/local/bin/port -d selfupdate
$ sudo /opt/local/bin/port install unison

Darwin Ports will fetch the other utilities Unison depends upon and build them for your machine. I prefer this method for a variety of reasons, but if you would like a binary copy of the program, you can download one from this fellow here.

The Other Mac

If you have a monitor on it, just repeat the above install.

If you decide to build it from source and your remote machine is headless, don’t worry, there’s an answer. Just copy the DMG to the remote machine and then SSH in. Get to that folder and then:

$ hdiutil mount DarwinPorts-1.2.1.pkg
$ sudo installer -pkg /Volumes/DarwinPorts-1.2.1/DarwinPorts-1.2.1.pkg -target /

First Run

You can do this one of two ways: mount the remote volume on the desktop over AFP, or use Unison over SSH. The former is easier (and AFP works over SSH if you tell it to when connecting) and the latter is automatable.

If you chose to do it over AFP, mount the volume and then run something like the following:

/opt/local/bin/unison ~ /Volumes/AFPShare/MyHomeBackup

If you want to do this over SSH, then you need Unison on the remote machine as well and then run something like this:

/opt/local/bin/unison -servercmd /opt/local/bin/unison ~ ssh://mymac.local/Backup

The -servercmd part tells your local copy of Unison where its counterpart on the other machine is, much like rsync. Once it gets started, it’ll ask questions as it needs to and then begin the transfer and sync.

Latter Syncs

If you want this in your crontab, you’ll want passwordless SSH keys between the machines. Otherwise, give it a whirl now and again to keep it updated by using the same procedure as above.

Shell Commands for Non-Junkies

Don’t. That’s the short of it. Don’t learn the shell (“Terminal”) by using programs you’re unfamiliar with to do actual tasks you need done. Get a quick-start book and toy around in a dummy account for a day or two to learn it (some weekend, or pair of Saturdays) and then, once familiar, a lot of this will suddenly click.

There’s a lot of people pushing shell commands to solve any problem that’s hard to do in the GUI, but the vast majority of people don’t need to be using them at all. Those that do, should learn what it is before using it because it’s very likely that if you start to really use it before knowing what’s going on that you’ll roast yourself a few times on live data.

1 No, not that Unison, this Unison. Yeah, had me for a while, too.

Average rating
(0 votes)
About Adam Knight
Adam Knight's picture

Author Biography

Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c.

In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon.

Bug him over AIM or email [link fixed].

I’m looking for a way to do updates, and occasional total syncs between a local folders here on my Mac and folders on a remote server, which I access over VPN through a mounted smb share. I don’t want to mirror all the files locally (there are huge .swfs in some directories) in most cases, but do want to be able to merge (I’ll worry about setting that up with unison later…) and update files at will. So sometimes I’ll want to do a perfect sync, deleting obsolete remote files, but most of the time I’ll want to just add and update from local folders, merging occasionally (when management alerts me at the last moment that they’ve been tinkering with something on the server…).

I’ve tried rsync (both command line and gui) and unison, and have only limited success… rsync seems to choke and do odd things to permissions and modification dates, while I can’t get unison to function at all. Using the rsync gui, I was able to move files, but I wasn’t getting any feedback (Verbosity was on) and, as mentioned, often choked. Plus, the script helper didn’t seem to function at all, and I wasn’t sure if running things through cron was the way to go anymore (10.4.7).

Here’s what I tried with rsync on the command line (I can’t ssh into the remote server):

rsync -vzrun –exclude ’.DSStore’ ~/Sites/HMSandbox/videoconcepts/ /Volumes/docs/accounting/video_concepts/

where the remote sever is smb://coldevs/docs

It started to work, and it looks like it began to update some files, but they now all have a modification date of Dec 1969. Plus weird permissions.

With Unison, I tried much the same: unison ~/Sites/HMSandbox/videoconcepts/ /Volumes/docs/accounting/videoconcepts -force /Users/jamesfishwick/Sites/HMSandbox/video_concepts/

I think perhaps I need to do something with the socket command? I know under windows, it is possible to synchronize with a remote directory using the file: protocol over the Windows Network Neighborhood. For example,

unison foo //host/drive/bar

If you use unison always from the same machine, you can install it with the aqua variant.

sudo port install unison +aqua

Also, you will probably want to define profiles and use them. In the darwinports installation, they are in ~/.unison, for other installs, they can ben in ~/Library/Application Support/unison/.

Hi, I had some problems with mac-mac synchronization using the Unison GUI and ssh. Mac-Linux sync however was fine. I looked around and found that there is a problem with the way Unison was expecting the ssh response under mac. Something about an extra space in the prompt for password, which breaks the GUI. I haven’t seen a fix for it and it would be fairly simple, but I don’t know where the GUI source is. Has this been fixed yet? It seems like a fairly minor thing but big in terms of usability.

Post new comment
The content of this field is kept private and will not be shown publicly.
17 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.