HOWTO: Backup and Sync with Unison
Unison is a nifty utility that allows you to keep directories and files in sync across separate machines. It is pretty configurable, and I’ll walk you through how to set it up using my setup as the example.
Install and Configuration
Installation is straight-forward in Ubuntu. A simple sudo apt-get install unison will do the trick. Once installed, you need to go about creating a configuration file, which is ~/.unison/default.prf. Below is a copy of my configuration file from the laptop:
# General prefs
logfile = /home/fubar/.logs/unison.log
root = /home/fubar
root = ssh://scooby//home/fubar
# Paths to keep in sync
path = projects
path = personal
path = mail
path = photos
path = .mutt
path = .getmail
path = archive
#path = media/music
# Individual files
path = .muttrc
path = .procmailrc
path = .vimrc
# Some regexps specifying names and paths to ignore
ignore = Name temp.*
ignore = Name *~
ignore = Name .*~
ignore = Name *.o
ignore = Name *.tmp
ignore = Name {,.}*{.lock}
ignore = Path projects/.metadata
Here’s a breakdown of the parameters:
logfile - Path and filename of the logfile.
root - Defines the root path to keep in sync. The first root entry is for the local machine. The second root entry points to the desktop’s home directory, connecting via SSH. For information on connection options can be found on the Unison website.
path - Define the path to keep in sync, relative to the root. These entries can be directories and files. I use both, as you can see.
ignore - Tells Unison what files to ignore. Useful if you don’t want to sync temporary files.
Running Unison
With configuration complete, it’s time to fire up Unison. From a terminal, type unison and press enter. Unison enters interactive mode and attempts to connect to the remote machine. It first checks the defined paths to determine if any files have been changed, added or deleted, after which it will present you with a prompt, asking what you’d like to do. In most cases, the default action will suffice, but sometimes Unison may not be sure, so you’ll need to specify which file to use. The prompts are straight-forward, and help is available.
Unison can also be run in a batch mode, but I won’t cover that here since I do all of this interactively.
Wrapping up
I use unison to keep my mail, pictures and projects in sync since I use both machines on a regular basis. It also ensures that I have a backup of my important files on another machine in case of failure. It’s a useful utility, and I recommend it.
Unison website: http://www.cis.upenn.edu/~bcpierce/unison/

