File Synchronization with Unison

On this blog, I previously covered file synchronization with rsync. The benefit of rsync is that it allows for incremental synchronization of files and directories and is very fast and secure over local and remote connections. The drawback of rsync is that it only syncs files one way or the other. In other words, the file that was last modified takes precedence and overwrites the older file.

In some situations, however, you may have two unique servers with files that are regularly modified on both ends. In such a case, having one file overwrite the other, would erase the data from the other file. Unison is a file synchronizer that takes the changes from each file and copies or merges them. This is useful for backups, synching, and server clusters.

To sync two directories containing files, simply enter from the command line:

unison /path/to/files /path/to/otherfiles

The output will look like
Contacting server…
Connected [//home-computer//path/to/files -> //home-computer//path/to/otherfiles]
Looking for changes
Warning: No archive files were found for these roots, whose canonical names are:

It will then present you with options:

Press return to continue.[] Reconciling changes

test1 test2
file —-> file1 [f]
file —-> file2 [f]
file —-> file3 [f]

And then it will ask you to proceed.

Proceed with propagating updates? [] y
Propagating updates

Unison is free and open source software, released under the GNU General Public License. It is available for most Linux distributions and other Unix-like operating systems, as well as Microsoft Windows.