File Synchronization is the process of mirroring, files and data in two or more locations in accordance with certain protocols. Files and Data are the most valuable thing in this era of Information Technology. By File Synchronization, we ensure that one or more copies of our priceless data is always available in case of disaster of any kind or when we need to work in many locations.
A good File Synchronizer is supposed to have below listed Features:
- Cryptographic synchronisation, as a security Implementation.
- A good ratio data compression.
- A Perfect algorithm implementation to check data duplication.
- Keep track of file source change.
- Scheduled Synchronisation.
One such tool is Unison. Here in this article we will be discussing “Unison” in details, along with its features, functionality and a lot more.
What is Unison?
Unison is a cross platform file synchronization application which is useful in synchronizing data between two or more locations be it computers or storage device.
Features of Unison
- Released under General Public License (GPL)
- Open Source and Cross Platform Available for (Linux, Unix, BSD, Windows, Mac)
- Make available same version of file across different machine, regardless of last modified location.
- Cross Platform Synchronization possible i.e., a Windows machine can be synchronized over a *nix Server.
- Communicate over standard Protocol TCP/IP i.e., possible between any two machines over internet regardless of Geographical Location.
- Smart Management – Show conflict when a file has been modified on both source and show it to the user.
- Secured SSH Connection – An encrypted data transfer.
- rsync algorithm is deployed here, only the modified part is transferred and overwritten. Hence. it’s fast in execution and Maintenance.
- Robust in nature
- Written in “Objective Caml” programming Language.
- Matured and Stable, no active development required.
- It is a user-level program ie., Application don’t need superuser privileged.
- It is known for its clear and precise specification.
Installation of Unison in Linux
The current stable release (Unison-2.40.102) can be downloaded from the link below:
Download Unison 2.40.102 Stable
Alternatively, we can also download and Install “Unison”, if it is available in repo using apt or yum command as shown below.
On Debian/Ubuntu/Linux Mint
Open terminal using “Ctr+Alt+T” and run the following command on the terminal.
$ sudo apt-get install unison
On RHEL/CentOS/Fedora
First, enable EPEL repository and then install using the following command.
$ sudo yum install unison
NOTE: The above command will Install Unison without GUI. If you need to Install Unison with GUI support, install ‘unison-gtk‘ package (Only available for Debian based distros) using the below command.
# apt-get install unison-gtk
How to Use Unison
Unison is used to synchronize a set of files in a directory tree to another location with similar structure, which may be a local host or remote host.
Local File Synchronization
Let’s create 5 files under your Desktop and then synchronize it to a folder called ‘desk-back‘ in your home directory.
$ cd Desktop/ $ touch 1.txt 2.txt 3.txt 4.txt 5.txt
$ ls 1.txt 2.txt 3.txt 4.txt 5.txt
$ mkdir /home/server/desk-back
Now run the ‘unison‘ command to synchronize your Desktop files to under ‘desk-back‘ in your home directory.
$ unison /home/server/Desktop /home/server/desk-back/
Sample Output
Contacting server... Looking for changes Warning: No archive files were found for these roots, whose canonical names are: /home/server/Desktop /home/server/desk-back This can happen either because this is the first time you have synchronized these roots, or because you have upgraded Unison to a new version with a different archive format. Update detection may take a while on this run if the replicas are large. Unison will assume that the 'last synchronized state' of both replicas was completely empty. This means that any files that are different will be reported as conflicts, and any files that exist only on one replica will be judged as new and propagated to the other replica. If the two replicas are identical, then no changes will be reported.If you see this message repeatedly, it may be because one of your machines is getting its address from DHCP, which is causing its host name to change between synchronizations. See the documentation for the UNISONLOCALHOSTNAME environment variable for advice on how to correct this. Donations to the Unison project are gratefully accepted: http://www.cis.upenn.edu/~bcpierce/unison Press return to continue.[] ... ... Saving synchronizer state Synchronization complete at 13:52:15 (5 items transferred, 0 skipped, 0 failed)
Now check the location /home/server/desk-back, if the synchronization process was successful?
$ cd /home/server/desk-back/ $ ls 1.txt 2.txt 3.txt 4.txt 5.txt
Remote File Synchronization
For remote file synchronization, you must have same version of Unison installed on both local and remote server. Run the following command to verify that the local unison can start and connect to the remote unison server.
$ unison -testServer /home/ravisaive/Desktop/ ssh://172.16.25.125//home/ravisaive/Desktop/
Sample Output
Contacting server... [email protected]'s password: Connected [//tecmint//home/ravisaive/Desktop -> //tecmint//home/ravisaive/Desktop]
The above results, indicates that the remote server is connected successfully, now sync the files using below command.
$ unison -batch /home/ravisaive/Desktop/ ssh://172.16.25.125//home/ravisaive/Desktop/
Executing GUI Unison
The first step is to set profile which requires you to set basic information as name of a profile and what you want to synchronize, source and Destination location, etc.
To start Unison GUI, run the following command on the terminal.
$ unison-gtk
Once profile is created and source as well as destination is entered, we are welcomed with the below window.
Just select all the files and click on OK. The files will start synchronising from both the directions, based upon last update time stamp.
Conclusion
Unison is a wonderful tool which makes it possible to have custom synchronisation either way (Bidirectional), available in GUI as well as command Line Utility. Unison provides what it promises. This tool is very easy to use and requires no extra effort. As a tester I was very much impressed with this application. It has a whole lot of features which can be implemented as required. For more information read unison-manual.
Read Also:
That’s all for now. I’ll soon be here again with another interesting article. Till then stay tuned and connected to Tecmint. Don’t forget to provide us with your valuable feedback in our comment section.
To further elaborate on Ulath’s answer, Unison provides 2-way synchronisation. With rsync you have a source and a destination. You can make the destination look like the source but not the other way round. Conflicts can occur if you made changes on both sides but Unison has a variety of ways of dealing with these. I have a central server with 3 client machines that all sync slightly different datasets but there are some overlaps and Unison handles it very well. I take this over RAID any day. Much more portable and reliable.
Thanks @PhiIT for such a nice explanation. I have quoted your comment at a few places where people were asking the difference between rsync and Unison.
Keep connected!
i am using this for years without any breakage, data loss, etc. it is a very efficient and professional tool.
@joe: it tracks the changes on both sides, such that you know if a file was deleted on the one side or created on the other.
Thanks @Ulath for your feedback.
Keep connected for more such posts.
Hello
I need to install unison on CentOS 7. I installed EPEL, it is enabled but it doesn’t find unison in the repo.
I also looked at the repo content here:
http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/
But there is no unison package. Perhaps it wasn’t compiled yet for CentOS 7?
Andrei, seems Unison is not yet made available under CentOS 7 default repo, but you can install it from source.
yum install ocaml ocaml-camlp4-devel ctags ctags-etags
cd ~
wget -> take the link from here http://www.seas.upenn.edu/~bcpierce/unison/download/releases/stable/
For example:
wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.48.3.tar.gz
Extract the file for example:
tar xvfz unison-2.48.3.tar.gz
Enter to the created directory:
cd unison-2.48.3.tar.gz
make
sudo cp -v unison /usr/local/sbin/
sudo cp -v unison /usr/bin
cd ~
rm -fr unison*
Thanks to your post I was finally able to get Unison working again. I’ve been using it for years but it broke recently after upgrading Cygwin. I fixed that but then needed to install Unison 2.48.3 on the remote server. Your instructions worked up until “sudo cp -v unison /usr/local/sbin/”. For some reason I was getting an error about dangling symlinks and it seemed that a symlink was being created and not the executable being copied. I followed the accepted answer here http://goo.gl/CjQXia and it finally worked.
Hi Avishek.
How are you friend?
I read your article about Unison.
If I understood, the Unison do the same that rsync. So, my question is, what the advantage of the Unison about Rsync?
Regards
Daniel Noberto
Thanks Daniel Noberto,
I am fine hope you are fine as well.
Sorry for late reply.
Rsync and Unison are very different. Look at the comment of PhiIT here: https://www.tecmint.com/file-synchronization-in-linux-using-unison/comment-page-1/#comment-639635
What does this offer over just rsync and a gui?
You should go through the comment of PhiIT. He nicely explained the difference between rsync and Unison. Unison is not rsync+gui. Here you may like to go through: https://www.tecmint.com/file-synchronization-in-linux-using-unison/comment-page-1/#comment-639635
Thanks for this wonderful Tool…!
Welcome @abilash,
Hope you are enjoying the post here on Tecmint.
I enjoy you articles.
FYI
GNU Public License
Thanks @scott for your feedback.
Keep connected to Tecmint.