15/04/2008

Synchronise via unison and ssh

I've seen one crashed hard disk too many last week, so I decided to tackle my long overdue synchronisation issues.
Situation: 3 computers (Archimedes, Xanthippe and Tisiphone), creative work-in-progress chaos on all three of them and one ssh-accessed backup account on our server to synchronise all three accounts.
Rsync is a nice simple console backup tool which also works with ssh, but neither runs a diff nor a modification date comparison of duplicate files. Files in the source directory are written over those in the destination directory, no matter what.
Unison is more sophisticated. It comes with a nice Gtk GUI capable of diff viewing and setting file replacement rules (e.g. last modified).

Setting it up is not altogether trivial, though.
Install unison on both systems ;-). The version numbers have to match more or less; on our slightly dated server (no recent RPM available) this meant compiling from the tarball: install gcc and ocaml compilers, run make (set UISTYLE=text flag for simple console app or UISTYLE=gtk2 for a GUI) and copy the unison executable to /usr/bin or wherever you want it to be. Everything is described in detail in the INSTALL file packed in the tarball. On the server side, the non-GUI version should suffice, on the client machine I prefer the GUI.
For openSuSE 10.3 you will find an up-to-date GUI package in the main repository anyhow.

Start Unison on your client computer, create a new profile. After choosing a directory on the client side, select SSH for the server, give the absolute path of your backup directory, server IP and username. Try connecting, which is going to fail due to a bug in Unison.
Fix that by editing your profile file, which is ~/.unison/<profilename>.prf
# Unison preferences file
root = /home/avocadohead/
root = ssh://avocadohead@<serverIP>//home/avocadohead/backup/

The automatically created version for obscure reasons sports an additional colon after the server IP which messes up the ssh connection.
Connect. The GUI is more or less self-explanatory.
Note: unison can't do versioning. However, it should be possible to run Unison on a rdiff-backup "time machine" directory, as blogged here.

No comments: