Unison is a tool to synchronize files and directories between different systems or within the same system. It can also be done between different platforms, for instance between a Linux computer and another computer with a different operating system, since it is a multi-platform program which is available for the best known operating systems.
An important point to understand is that it is not a backup tool. For instance if a file is deleted in one of the two replicas, it will be also deleted in the other one, since the diea is to maintain the two copies synchronized. If there are conflicts, for instance if a file has been modified in different ways in each of the replicas, unison will allow to reconcile the conflict, choosing one of the two versions over the other one.
It may have different applications, In my case, I use it to keep the computer that I have at home (and on the move, since it is a laptop) synchronized with the computer that I have in my office, which is a desktop computer. In this way, when I have to work at home I have to simply synchronize the laptop, and when I finish working at home I have to synchronize again so that my office computer is updated with the work I did at home. In principle, more than one computer could be kept synchronized, choosing in this case a reference computer and synchronizing the other computers against this one. I have used this system to keep a tablet and the laptop synchronized with the office computer.
The synchronization is done over the so called ssh tunnel. In other words, it uses a ssh connection between the computers to perform the transmission of data, and so it uses a secure connection. For this reason, it is convenient to have access through a private ssh key between the computers, to avoid having to enter the password each time that the computers are synchronized.
To install unison in Debian/Ubuntu systems simply issue the following command:
sudo apt install unison
Here I show the command that allows me to synchronize my document folder between the office computer and my home laptop. To do this, I have a Bash script that performs the synchronization. This is the content of the script:
unison -batch /home/wgarcia/Docum ssh:/ordinador.feina.com//home/wgarcia/Docum
I issue this command from the laptop at home, and I synchronize the "Docum" folder of my office computer (the computer is called "ordinador.feina.com"). Simply executing this script at the laptop the two computers are synchronized. If there is any conflict between files, which should not happen if care is taken to synchronize before and after working at home, this command will show us the conflict and allow us to solve it using the procedures shown in several tutorials that can be found in Internet. In any case the easiest way to solve conflicts is to move the conflicting file out of the folders being synchronized, performing a synchronization (no conflict will be found), putting the version that is chosen to keep back in one of the two replicas (in the one that it was originally) and finally synchronize again and there will be no confiict (the file is in only one of the replicas).