Unison

Basics

The config files are stored in ~/.unison/

A basic profile could look like this (stored in e.g. /home/me/.unison/data.prf:

label = Profile for personal data backup
root = /home/me/data
root = [ssh://remotehost:22//srv/backup/me/](ssh://remotehost:22//srv/backup/me/)
sshargs = -i /home/me/.ssh/id_for_server_rsa -o StrictHostKeyChecking=yes
ignore = Path dir_in_data/to/ignore
ignore = Path other/dir/in/data/to/ignore
ignore = Path the/paths/are/relative/to/data

You can then run the profile with

unison data

Or, to avoid questions for each file

unison data -batch

The result will then be available through the return value:

0: successful synchronization; everything is up-to-date now.
1: some files were skipped, but all file transfers were successful.
2: non-fatal failures occurred during file transfer.
3: a fatal error occurred, or the execution was interrupted.

See more details in the unison documentation

Includes

Unison configuration can be organized with include directives. E.g. the following config allows to use varying network configuration based on whether you are syncing from within the LAN or from a remote location:

# Unison preferences file local.prf
label = Profile for personal data backup from home lan
include data
include lan

# Unison preferences file remote.prf
label = Profile for personal data backup from remote locations
include data
include wan

# Unison preferences file lan.prf
root = [ssh://lanserver:22//srv/backup/me/](ssh://lanserver:22//srv/backup/me/)
sshargs = -o StrictHostKeyChecking=yes -i /home/me/.ssh/password_free_rsa

# Unison preferences file wan.prf
root = [ssh://www.myhost.dyn-dns.de:22//srv/backup/me/](ssh://www.myhost.dyn-dns.de:22//srv/backup/me/)
sshargs = -o StrictHostKeyChecking=yes -i /home/me/.ssh/password_protected_rsa

# Unison preferences file data.prf
root = /home/me/data
ignore = Path dir_in_data/to/ignore
ignore = Path other/dir/in/data/to/ignore
ignore = Path the/paths/are/relative/to/data

Compatibility issues between different versions

I am using unison to sync my files between different machines. Since I am using different distros on each of them, unison versions tend to differ and this causes problems. After a lot of fiddling I have resolved to a "hack" which does not feel very clean but is easy to implement and tends to produce the most reliable results. I choose one machine as the master (in my case my home server running Debian) which gets to decide the unison version to be used. This version is installed through the standard package management and the resulting unison binary is copied to /usr/local/bin on the other machines. Done.