Sync specific folder between two Ubuntu machines when connected to the same LAN
Solution 1:
[Answering my own question as I found a nice way to do this]
Use unison
tool developed by Benjamin Pierce at U Penn.
Let us assume you have two directories,
/home/user/Documents/dirA/
and /home/user/Documents/dirB/
To synchronize these two, you may use:
~$unison -ui text /home/user/Documents/dirA/ /home/user/Documents/dirB/
In output, unison
will display each and every directory and file that is different in the two directories you have asked to sync. It will recommend to additively synchronize (replicate missing file in both locations) on the initial run, then create and maintain a synchronization tree on your machine, and on subsequent runs it will implement true synchronization (i.e., if you delete a file from .../dirA
, it will get deleted from .../dirB
as well. You can also compare each and every change and optionally choose to forward or reverse synchronize between the two directories.
Optionally, to launch graphical interface, simply remove the -ui text
option from your command, although I find the cli
simpler and faster to use.
More on this: Unison tutorial at Unison user documentation.