21

I would like to do a two-way automatic sync between folders Directory A andDirectory B. This means that whenever a file in Directory A or one of its sub-directories is changed, that change is immediately applied to Directory B, and whenever a file in Directory B or one of its sub-directories is changed, that change is immediately applied to Directory A. Thus, the two directories would be completely identical, including document properties. How can I achieve this?

I am using Ubuntu 16.10.

Symlinks are not an option.

8
  • @dadexix86 If a change made in Directory A is applied to Directory B, this modifies a file in Directory B or creates a new one. But, this change could not be applied back to Directory A as the two directories are already identical. You cannot modify a file without modifying it. Jan 29, 2016 at 20:43
  • 1
    If this is for backup reasons, be extremely careful in how you implement this (cron+rsync maybe?) because if you accidentally delete a file in one directory, it will be removed from the other - so you've also lost the backup.
    – Carl H
    Jan 29, 2016 at 20:53
  • mv B B.old && ln-s A B =) . If you want A to == B , just make a link of A to B. Otherwise use rsync from A to B or , probably best, some sort of version control.
    – Panther
    Jan 29, 2016 at 20:57
  • 2
    use a link cyberciti.biz/faq/creating-soft-link-or-symbolic-link
    – Panther
    Jan 29, 2016 at 21:06
  • 1
    @CarlH synching is never for a backup ;-)
    – Rinzwind
    Oct 30, 2016 at 16:45

5 Answers 5

13

Unison

Unison is a GUI and terminal-based tool which allows files and directories to be kept in sync with each other, between different local directories and drives or on a network, which could be on different operating systems. The application is available for Unix operating systems (Linux and Mac OS X) and Windows. Changes can be made on the different places, and Unison will update the machines with the correct versions of files and folders, copying, deleting, renaming or deleting files and directories as necessary.

Unison sync app is probably the most used and trusted by the Ubuntu/Debian community. It is available at the Software Center and at the package manager. It has a command-line and a graphic user interface (GUI)(GTK).

Ubuntu Help Community Wiki - Unison

Ubuntu Manual - Unison

A short use example, close to your request, can be found at Rmano answer (screenshot below).

screenshot

FreeFileSync

FreeFileSync is a free data backup software that helps you synchronize files and synchronize folders. It is designed to save your time setting up and running data backups while having nice visual feedback along the way. FreeFileSync is Open Source software, available for Windows, Linux and macOS.

I've never tried but it seems to be worth a shot. It has a default GUI and is under active development.

screenshot

Synkron

Synkron is an application that helps you keep your files and folders always updated. You can easily sync your documents, music or pictures to have their latest versions everywhere. Synkron provides an easy-to-use interface and has lot of features. Moreover, it is free, open-source and cross-platform.

screenshot

4
  • 1
    unison is available in ubuntu repos. apt-get install unison-gtk
    – phil294
    May 7, 2018 at 19:31
  • I know this is old, but which one of those tools, if any, will work with a USB stick that gets removed and inserted from time to time? Ideally it should recognize when the USB stick is plugged in and automatically sync the folders (one of them being on the stick) and not complain or get stuck when the stick gets removed or is not there to start with.
    – Andyc
    Feb 26, 2021 at 9:04
  • @Andyc These software should work with whatever storage device you choose. The port is also irrelevant, as long as the OS recognizes the device connected. Mar 16, 2021 at 4:21
  • @FelipeG.M.Maia Yes, it works indeed (FreeFileSync). The only thing I haven't been able to make work yet is the automatic synchronization when I insert my USB stick. The documentation is to me a little cryptic on this: you are supposed to give it some commands like in a command line, but it doesn't say how this commands should look like. There is an example, but I didn't find it very useful. Manually it's working though and for me a great improvement over rsync.
    – Andyc
    Mar 19, 2021 at 8:40
2

For a long time I used rsync to sync my laptops(2) and a 3rd machine, then I tried with syncthing but this morning a famous search engine offered me this project:

Mirror

Mirror is built to support a two-machine (e.g. desktop+laptop) development workflow where you want to run a command line compile/build process on a powerful/dedicated desktop, but still edit files remotely on a laptop.

You will also find a comparison of different solutions.

His main argument against rsync are : not real time and nor officially two ways.

PS: I'm using it through zerotier, so my machine are always able to communicate together.

1

I would recommend the synkron tool. This is an open-source application available for linux(and other OS's). More recent copy of the file is updated over folders based on the time stamp. The frequency of the sync is user defined.

To install you have to build it which requires Qt 4.3 or recent version.

Check the sourceforge page ( synkron on sourceforge) to download and installation details.

Advantages over rsync+cron and other simple approaches:

  • A temporary backup is created which is saved for certain duration of time.
  • Option to not propagate deletions.
  • Multiple folder can be linked as masters, or slave-master configuration.

Project page - Synkron page / Documentation - Synkron documentation

0

I come late on that question : to do that task often on the same folders, there is Synchrorep.

0

I wrote Poni after getting frustrated with lsyncd, lsyncd wasnt syncing correctly and I had to restart service constantly to pick up inotif changes,

this is a binary written in Crystal that uses inotify lib and rsync to do the actual file/dir sync between 2 hosts, using it in production now, no issues

https://github.com/perfecto25/poni

also have a python version of this,

https://github.com/perfecto25/isync

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.