Synchronize Files with Unison on Ubuntu/Debian

Unison is a free, cross platform file synchronization tool that enables us to keep two set of file replicas (instances) on two different systems or on different disks of the same system. Unlike simple mirroring or backup utilities, it updates both replicas of a distributed directory structure. It detects and displays the conflicting updates. Unlike a distributed filesystem, Unison is a user-level program; there is no need to modify the kernel or to have root user privileges on either host.

Unison works between any pair of machines connected to the internet, communicating over either a direct socket link or tunneling over an encrypted ssh connection. It is careful with network bandwidth, and runs well over slow links such as PPP connections. Transfers of small updates to large files are optimized using a compression protocol similar to rsync.

In this how-to i am using two systems running with Ubuntu. The local system is running with Ubuntu Desktop and its ip address is 192.168.1.100/24 and remote one is running with Ubuntu Server and its ip address is 192.168.1.201/24. And i am going to synchronize the directory /home/sk/Unixmen between two systems. Change the values as per your scenario.

Install Unison

On Local & Remote Server System:

Update and Upgrade the both systems with following commands.

sudo apt-get update
sudo apt-get upgrade

Install Unison on both systems.

sudo apt-get install unison unison-gtk

Configuration

Now on your local system, launch the Unison GUI tool from Menu or Dash. It should look like below.

Unison_001First we have to create a new profile for the synchronization process. Click on Add to create a new profile. Click Forward.

Profile Creation_002Enter the name for the new profile and click Forward.

Profile Creation_003Here you will be prompted for Synchronization method. I want to synchronize the files between my local desktop to remote server using SSH. So here i choose Using SSH from the Synchronization Kind drop-down box. Enter the remote host server ip address and user name as below and click Forward.

Profile Creation_004Now we have to mention the local and remote folders to be replicated. Enter the local folder path in the Local Directory (i.e in my case its /home/sk/Unixmen) box and Enter remote  folder path in the Remote Directory box. Click Forward.

Profile Creation_005If you sync any folders in the FAT partitions, check the FAT Partition and click Forward.

Profile Creation_006Finally click Apply.

Profile Creation_007We have successfully created the profile. Click on Open to start.

Profile Selection_009It will ask you the remote system user password. Enter the password and click Ok.

Unison_010You will get a warning message as shown below if you are first time using this application. Click Ok to continue.

unison-2.40.65-gtk_011Now you will get a screen something like this.

Unison [Unixmen Sync]_012Put the folders or files in your sync folders (/home/sk/unixmen) that you want to replicate and click Go. Everything will be done behind the screen.

Now check for the files in your remote system. They certainly should be there. If you added a new file or directory click Rescan, after that click Go to start the sync.

sk@server1:~$ ls /home/sk/Unixmen/
New1  New2  New3

Thats it. Enjoy. Here what you have just read is a basic concept of Unison. You can do lot of things using Unison. I suggest you read the official documentation for more information.