Linux

Synchronize computers with Unison

With a program called <a href="http://www.cis.upenn.edu/%7Ebcpierce/unison/" target="_blank">Unison</a>, you can take advantage of the same synchronization features of rsync, but in more than one direction. With Unison, the files changed on your laptop will get synchronized with those on your desktop, and vice versa.

For individuals with more than one computer, trying to keep files in sync between them can be an exercise in frustration. Typically, tools such as rsync are used to synchronize files from one system to another, but the problem is that it's a one-way sync.

With a program called Unison, you can take advantage of the same synchronization features of rsync, but in more than one direction. With Unison, the files changed on your laptop will get synchronized with those on your desktop, and vice versa.

Unison is also cross-platform, which means you can synchronize your Linux desktop with your Windows desktop and OS X laptop. It also can take advantage of SSH, meaning you can synchronize files from home while you're at work or at a coffee shop on a public Wi-Fi connection.

That being said, Unison insists on having the same version on each system. If every system runs the same version of Mandriva or Ubuntu, it would be feasible to install a vendor-provided binary package. The current stable version is 2.13.16, and binary packages are available for all platforms, including Linux. If you have multiple Linux systems running, for example, one Mandriva and one Ubuntu, instead of installing from the vendor's packages, you may opt to download a binary from the Web site instead to ensure every OS is running the same version.

To begin, once Unison is installed, you can start it in GUI mode by executing unison. To operate in text-mode, use unison -ui text. To become familiar with Unison, test it locally; Unison can synchronize directories on the same system just as well as synchronizing directories with remote systems.

To begin, a simple test as follows is sufficient to demonstrate Unison:

$ cd ~/tmp/
$ mkdir one two
$ touch one/1 two/2
$ echo "3" >one/3
$ unison -ui text one two

Unison will give you a bit of information as to what it intends to do. You'll then see the following output at which point you will need to confirm what you want it to do:

Press return to continue.[<spc>] Reconciling changes

one            two
file     ---->            1  [f] .
         <---- file       2  [f]
file     ---->            3  [f]

Proceed with propagating updates? [] y
Propagating updates


UNISON 2.13.16 started propagating changes at 08:30:32 on 06 Sep 2007
[BGN] Copying 1 from /home/user/tmp/one to /home/user/tmp/two
[END] Copying 1
[BGN] Copying 2 from /home/user/tmp/two to /home/user/tmp/one
[END] Copying 2
[BGN] Copying 3 from /home/user/tmp/one to /home/user/tmp/two
[END] Copying 3
UNISON 2.13.16 finished propagating changes at 08:30:32 on 06 Sep 2007


Saving synchronizer state
Synchronization complete  (3 items transferred, 0 skipped, 0 failures)

As you can see, Unison tells you which way a file will be transferred, and you can change this on a per-file basis. For instance, the [f] noted above tells Unison to follow its own recommendation, which it displays but you can change this by clicking ? to get a list of options. You can tell Unison to ignore files, show differences, change the propagation direction, and more.

To transfer to and from other systems, make sure both Unison and SSH are installed on each system. Then simply call Unison using SSH:

$ unison -ui text one ssh://somehost/home/user/two

This will synchronize the directory one/ with the remote directory /home/user/two on the remote system somehost via SSH.

Unison also has support for profiles, which allow you to create configuration files that can set preferences on different directories and files. Comprehensive documentation on profiles is available on the Web site.

All in all, Unison can be extremely useful and quite powerful. It doesn't take the blind-sync approach by default, but allows you to determine what files to sync, if any, and in what direction. Using profiles, you can largely automate things to suit your situation.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

11 comments
RNR1995
RNR1995

For Windows use ViceVersa Excellent Proggie

LaFong
LaFong

I agree, somewhat, with the other posters. If you just want to sync your own stuff, using a nice GUI, there are other freeware and commercial choices. However, the advantage of Unison is that it supports bi-directional sync. That is, it doesn't just sync your stuff to another directory, it syncs the other way too. For us, it means we can have a directory at all 3 of our sites, users at any of the sites can drop files into their local directory, and the files or changes get synced automatically to the other sites. Most syncing tools are one-way. It also does delta-syncing, copying over just the bytes that have changed, which many other sync tools don't do either. It did require a little scripting/batch file, and a Scheduled Task, but that was trivial. It works over SSH, over the internet, and so is a very handy remote syncing solution.

Tony K
Tony K

...I've tried Unison, and it works, but it's a PITA to configure. In the end, the performance wasn't worth the amount of configuration necessary to keep my computers in sync. Fortunately, Microsoft provides a great tool called "SyncToy", and it's anything but a toy. It took about 10 minutes to get all of the directories I wanted synced in the method I wanted to sync them. It's not as fast as Unison, but since I have it sync in the middle of the night, I don't care.

smarley
smarley

Will Unison synchronize a computer with corporate network storage folders when I return to the office or prepare to go work from home?

Ajax4Hire
Ajax4Hire

sounds like mirrordir. mirrordir has been out for some time and works the same way. also has ability to ssh and ipaddr:/name sync. Best of all, I have been using mirrordir for 3 years, I know it, I know how to use it, I know how to keep her inputs happy. I already have something that works and works well.

GentleRF
GentleRF

There's a minor problem with the author of the software's naming of the utility. There is already a copyrighted program for the Mac called Unison which is a Usenet newsreader application. I sincerely hope they get things straightened out on this as it sounds like a very nice application.

heynen.paul
heynen.paul

Does it work with FTP and/or WebDAV folders?

dave
dave

Been using it for a year now and it just works and is easy to set up with several sync options to pick from.

online
online

SyncToy is great. Too bad it doesn't work on my Mac, like Unison does.

olegkio
olegkio

I've been using it for a few years and it worked very well. I've sync'd files between Linux, Windows and Novell Netware. Easiest way to do it is if you can map a drive to your network resource. Then Unison will just treat your files as if they were local to your computer. If you have admin rights to the server, it would speed things up if you run Unison in server mode. It is pretty well explained in Unison Help file (type unison -help) First sync will be slow (depends on how many files you have to sync) but after that it gets much faster. If you are unhappy with its speed after the first sync, try -fastcheck option. I sync about 200GB worth of files and if there are only minor changes, it doesn't take more than a few minutes. Oleg Kio

Editor's Picks