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!


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.

| improve this answer | |

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.