Real Time Local File Sync

11,968

A filesystem overlay would probably work better for this. Using something like aufs you can create a 'virtual' directory out of several combined directories. You can configure whether writes should propagate back to the original directories, or use a copy-on-write method to leave the originals alone, or disallow writes altogether.

However to answer your original question, you can use something like lsyncd to trigger an rsync as soon as a file is modified. lsyncd uses rsync, which is capable of syncing directory contents without keeping the directory name. Generally the way to do this is to sync sourcea/. to /some/destdir/. The important part is the dot at the end of the source path. This is a general trick that can be used for things other than rsync, like cp.

Share:
11,968

Related videos on Youtube

Adrian Schneider
Author by

Adrian Schneider

Updated on September 18, 2022

Comments

  • Adrian Schneider
    Adrian Schneider about 1 year

    How can I set up an instant file sync for two local directories? The catch is I need it in real time (15, 10 or even 5 seconds is too slow), and I don't want the target root directory created.

    For example, something similar to...

    cp -fr sourcea/* /some/destdir
    cp -fr sourceb/* /some/destdir
    cp -fr sourcec/* /some/destdir
    

    Catching deletions would be nice too, though it's not a deal breaker.

    I do not want the "sourcex" created within destdir. (hence the *). I've tried using rsync, which apparently wasn't close or even close to real-time, as well as several generic sync systems. However, most will want a 1 to 1 sync, rather than contents only.

    Any suggestions? I've been fighting this for a while now, so any help would be greatly appreciated!