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 $?;

Trackbacks

Trackback specific URI for this entry

This link is not meant to be clicked. It contains the trackback URI for this entry. You can use this URI to send ping- & trackbacks from your own blog to this entry. To copy the link, right click and select "Copy Shortcut" in Internet Explorer or "Copy Link Location" in Mozilla.

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA