As we work on different computers at different times, it becomes increasingly difficult to keep track of file versions on different computers. For example, you may be working on a development of a new software product on a desktop computer. You may also have the development environment on a laptop and do some work on it occasionally. At the end of the day, you may wish to synchronize the two versions on the laptop and the desktop. Unison is an excellent tool for that. Unison will help you in synchronizing the two directory trees of the software package on the two computers. It will help you in copying the files modified on laptop to desktop and vice-versa. In case some files have changes on both laptop as well as desktop, Unison indicates that giving you the option about the direction you wish to copy each such file, that is, whether a file should be copied from desktop to laptop or vice-versa.
Although pre-compiled binaries may be available, we will look at the most general case of getting the source files and building the executable binaries.
1. To get Unison running on your Linux computer, you need the Objective Caml compiler. You can get the Objective Caml compiler from http://caml.inria.fr. Let's say you have downloaded the file ocaml-X.YY.Z.tar.bz2. Untar the file,
tar -xvjf ocaml-X.YY.Z.tar.bz2
This creates a directory tree under ocaml-X.YY.Z. Change to this directory,
cd ocaml-X.YY.Z
Build the Objective Caml compiler using the steps given in the INSTALL file. These steps involve giving the following commands,
./configure
make world
make bootstrap
make opt
make opt.opt
sudo make install
This should get the Objective Caml compiler built and installed on your computer.
2. Next, download the Unison from http://www.cis.upenn.edu/~bcpierce/unison/. It is required to have the same version of Unison on all your computers on which you wish to synchronize files. So it is best to download Unison manually on all your computers and ensure that the version is the same. Let's say you downloaded unison-A.BC.DE.tar.gz. Untar the file,
tar -xvzf unison-A.BC.DE.tar.gz.
This creates a directory tree under unison-A.BC.DE. Change to this directory,
cd unison-A.BC.DE
As always, the installation instructions are given in the file INSTALL. For installing Unison with text-based user interface, give the command,
make UISTYLE=text
This should result in creation of an executable file, unison in the current directory. Copy it to a convenient location as your PATH settings, say
sudo cp unison /usr/local/bin
Unison works well with the command line interface. However, if you are more comfortable with graphical user interface, you can get Unison with a graphical user interface. For that, first you need to get LablGtk. Get the latest version of LablGtk from http://wwwfun.kurims.kyoto-u.ac.jp/soft/olabl/lablgtk.html. Let's say you have downloaded the file, lablgtk-P.QR.S.tar.gz.
Untar this file,
tar -xvzf lablgtk-P.QR.S.tar.gz
This should create a directory tree, lablgtk-P.QR.S. Change to this directory,
cd lablgtk-P.QR.S
The README file has all the installation instruction. You can install lablGtk by giving the following commands,
./configure
make world
sudo make install
Now go back to the Unison directory, unison-A.BC.DE,
cd unison-A.BC.DE
And give the command,
make UISTYLE=gtk2
This should result in creation of an executable file, unison in the current directory. Copy it to a convenient location as your PATH settings, say
sudo cp unison /usr/local/bin
Now that you have got Unison installed, you can put it to good use of synchronizing files. The rest of this tutorial assumes Unison with text-style user interface.
Unison uses SSH to communicate with remote computer. So, first, you need to have SSH server running on both computers before you can use Unison. Actually, you need SSH server on the remote computer and SSH client on local computer. But, you may wish to either computer as client; so it is convenient to have complete SSH installation on both computers. We refer to the local computer as client and the remote computer as server.
Let's say you have a desktop and a laptop computers in a network and you keep on shuffling between the two. You wish to synchronize the directory tree package-1.01.4 under your home directory on the desktop and the laptop. Let's assume that the laptop and desktop have the IP addresses, 192.168.1.2 and 192.168.1.3 respectively.
Change to your home directory and give the following command on one of the computers, say laptop
unison package-1.01.4 ssh://192.168.1.3/package-1.01.4
Unison analyzes the directory tree on two computers and gives an analysis like this,
local desktop
changed <==== changed uuu []
changed ----> b [f]
<---- changed c/f [f]
<---- changed d [f]
new dir ----> x [f]
Proceed with propagating updates? [] y
Propagating updates
The system prints each line of analysis and you can give your input for each case. Here, file
uuu has changed on both computers. You can enter < if you want to copy
uuu from desktop to laptop. Otherwise, you can enter > if you want to copy
uuu from laptop to desktop. File b has changed
on the laptop; it can be copied (propagated) to desktop. Files c/f and
d have changed on the desktop; these can be propagated to laptop.
x is a new directory on laptop, it can be copied to desktop. Once you confirm with a
y
to Proceed with propagating updates? []
, the files for package-1.01.4
are synchronized.
Unison File Synchronizer, User Manual and Reference Guide
Synchronize Files Between Multiple Computers Using Unison (Advanced)