How this works

every NEW or newly written (modified) file in /home/quake/important or /home/quake/projects is copied to /tmp/mirrored/home/quake/important or /tmp/mirrored/home/projects respectively. Directory structure is saved.

Simple example:

What happens on /home/quake/…

What's done by fs-mirror

/home/quake/important/new-file is created

/home/quake/important/new-file is copied to /tmp/mirrored/home/quake/important/new-file

/home/quake/important/new-directory/ is created

Nothing happens (and there is no /tmp/mirrored/home/quake/new-directory directory)

/home/quake/important/new-directory/some-file is created

/tmp/mirrored/home/quake/new-directory directory is created and /home/quake/important/new-directory/some-file is copied to /tmp/mirrored/home/quake/new-directory/some-file

/home/quake/important/new-directory/some-file is modified

/home/quake/important/new-directory/some-file is copied to /tmp/mirrored/home/quake/new-directory/some-file

What it needs

Limitations

only files are copied over the directories (making dir does not trigger making dir on the mirror)

file removing and renaming events is not watched (there may be some mirrored files even though the original files does not exist)

if you create a file, then delete it and then create a directory with the same name, this is going to be completely ignored when coping files, because there will still exist a file with the name of the directory

some rat-race can happen

after creating directory in watched directory there is some time before we set up a watch on this new one. If you create a file exactly then, this will not be caught

if you modify a file really quickly (twice), two copy workers can get two orders to copy the same file and copy it in the reversed order of adding to files to copy queue

not all files might be copied (inotify does not guarantee delivering all events for sure. It's almost 100% though)

small changes to big files (like logs) triggers copying the file over and over

Coolness

it's small and quite reliable (and readable)

non-obtrusive (if you want a smart mirroring this does not require you to modify anything in your applications)

easy to extend (to remove some limitations)

easy to change number of processes copying files

can work well with sshfs to backup your important files in near real-time, but still asynchronously

you can rsync the dirs from time to time to eliminate small differences that may happen due to some of the limitation of software and inotify architecture