Sync specific folder between two Ubuntu machines when connected to the same LAN

10,454

[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.

Share:
10,454

Related videos on Youtube

axolotl
Author by

axolotl

Updated on September 18, 2022

Comments

  • axolotl
    axolotl over 1 year

    I have two Ubuntu machines, a laptop and a desktop. What I wish to do is, to create a folder in both machines at paths 'path1' and 'path2'. I want to set up sync between the two folders whenever they are connected to the same local area network (Desktop through Ethernet and Laptop through WLAN). So for example, if I create a file path1/x, it will also appear in path2 as path2/x.

    Is there a way I can get this done? [It's ok if deletion sync doesn't work and I have to manually delete a file from both directories simultaneously]

  • Jason Southwell
    Jason Southwell over 7 years
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
  • Ale
    Ale about 6 years
    For the community to be more effective, it is necessary to provide more detail in the answers, a link is not enough, in which case it is not an answer but rather a comment.