Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been using rsync to sync a bunch of files between my two servers. I set a cron job that would run rsync every minute. However, I'd prefer if I could have it run always, so that files are synced the moment they are changed. What would be the best way to do this?

Thanks.

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

If you have inotify in your kernel, check out inotify-tools.

There's an example on that page:

#!/bin/sh
# A slightly complex but actually useful example
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %f' \
 -e close_write /home/billy | while read date time file; do
    rsync /home/billy/${file} rsync://billy@example.com/backup/${file} && \
    echo "At ${time} on ${date}, file ${file} was backed up via rsync"
done
share|improve this answer
    
I'm interested in this solution @Doug. Would you mind explaining what the different parts of this script do? –  user815423426 Aug 5 '11 at 20:11
    
FWIW (four years later), lsyncd is a daemon-like program that wraps up this functionality in a very elegant and fairly cross-platform way: code.google.com/p/lsyncd –  Zac B Sep 17 '13 at 18:28
add comment

use the inotify system of linux, in combination with incron.

share|improve this answer
    
Doug Harris has a nice example usage. Care to further document yours as well? –  Nerdling Sep 24 '09 at 21:53
    
doug copyNpasted the sample direct from that page :) to avoid doing the same: inotify.aiken.cz/?section=incron&page=doc&lang=en (rtfm) ... it works just like cron, just in a different directory (/etc/incron.d/) –  akira Sep 25 '09 at 5:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.