Sync one directory to another

I've had to sync one local fileserver directory (and all subdirs) to a remote server on the fly so whatever gets written to the local server appears to the remote.
I did have tried iocron but it's not recursive.
Tested some solutions but all they had some issues.
I ended up using watcher.py: https://github.com/greggoryhz/Watcher
Works flawlessly for 2months now. (local copy: http://www.valqk.com/assets/user/watcher.py )
install dependent libs:

#> sudo apt-get install python python-pyinotify python-yaml

Another example - if you want to sync two local dirs - you do it like this:

jobs.yml file:


job1:
label: Watch user/dir for added and changed files and cp to user1/dir/
watch: /home/user/dir/
events: ['atrribute_change', 'modify', 'create', 'move']
recursive: true
command: /home/user/cpfile.sh /home/user/dir/ $filename /home/user1/dir/
job2:
label: Watch user/dir for remove files and cp to user1/dir
watch: /home/user/dir/
events: ['delete','self_delete']
recursive: true
command: /home/user/dir/delfile.sh /home/user/dir/ $filename /home/user1/dir/


and the .sh sctipts:

cpfile.sh
#!/bin/bash

prefix="$1";
file="$2";
dst="$3";
plen=${#prefix};
echo "RUN $0 $1 $2 $3" >> /tmp/a
echo cp -a $file $dst/${file:$plen} >> /tmp/a;
cp -a "$file" "$dst/${file:$plen}";
exit $?;


delfile.sh
#!/bin/bash

prefix="$1";
file="$2";
dst="$3";
plen=${#prefix};
rm "$dst/${file:$plen}";
exit $?;

Sync one directory to another

I've had to sync one local fileserver directory (and all subdirs) to a remote server on the fly so whatever gets written to the local server appears to the remote.
I did have tried iocron but it's not recursive.
Tested some solutions but all they had some issues.
I ended up using watcher.py: https://github.com/greggoryhz/Watcher
Works flawlessly for 2months now. (local copy: http://www.valqk.com/assets/user/watcher.py )