inotify and rsync on large number of files

If the server has a slow processor avoid checksums and compression with rsync. I would remove ht "-z" option in the rsync command.

rsync --update -alvr --exclude '*cache*' --exclude '*.git*' /var/www/* root@secondwebserver:/var/www/

Note that it will not avoid rsync to compare the 650k files. You could rsync subdirectories of /var/www one by one to reduce the number of files checked at one time.


Thank you for posting your answer - it really helped me. I think you can simplify the loop:

EVENTS="CREATE,DELETE,MODIFY,MOVED_FROM,MOVED_TO"

sync() {
  rsync --update -alvzr --exclude '*cache*' --exclude '*.git*' /var/www/* root@secondwebserver:/var/www/

}
watch() {
  inotifywait -e "$EVENTS" -m -r --format '%:e %f' /var/www/ --exclude '/var/www/.*cache.*' 
}


watch | (
while true ; do
  read -t 1 LINE && sync
done
)

You may need to adjust that slightly but the gist should be clear. I'm using a variant with Amazon's AWS s3 sync, so I may have substituted your rsync command in incorrectly.

Tags:

Rsync

Inotify