Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like a simple tool for syncing two folders on remote servers...

Utopically, I only need an OS catchable trigger (or something like that) that could be used to fire rsync automatically ?

Is there anything of the sort, or a simple tool capable of doing this ?

rsync each minute is not at all an elegant solution to the problem ... i would like to call rsync each time a file is written/deleted in any one of the servers, in a specific folder...

the goal is to easily maintain to remote folders in sync

update: maybe something like gamin... ?

thanks !

arod

share|improve this question

4 Answers 4

Try inotify. For your relative simple requirements this should be best suited.

An example script:

while { inotifywait -e create -e delete /directory2watch; }; do
  echo rsync -avz /directory2watch
done

Or something like that.

With inotify you have access to those events:

  • access – file was accessed
  • modify – file was modified
  • attrib – file attributes changed
  • close_write – file closed, after being opened in writeable mode
  • close_nowrite – file closed, after being opened in read-only mode
  • close – file closed, regardless of read/write mode
  • open – file was opened
  • move – a file within watched directory was moved
  • create – a file was created within watched directory
  • delete – a file was deleted within watched directory
  • delete_self – the watched file was deleted
  • unmount – file system on which watched file exists was unmounted
share|improve this answer
    
inotify is excellen, but it get cumbersome when tracking directories and subdirectories... –  arod Jun 29 '10 at 10:52
    
At least inotifywait knows the -r option for recursive monitoring. I don't know how good it works though. –  weeheavy Jun 29 '10 at 11:22

The obvious solution here is afs

There all sorts of complications using DRBD on anything but a small LAN with high levels of connectivity between nodes.

But you could roll your own solution using inotify

share|improve this answer
    
afs seems very cool, and very suited to my needs, i'll take a look ! thank you very much ! : ) –  arod Jun 29 '10 at 10:52

In my answer to this question, I suggested incron. It's easy to set up system-wide and user-specific config files in a manner similar to cron. You can specify scripts that will be run when filesystem events are triggered. It uses the Linux kernel inotify API. You might take a look at it and see if it works for you.

share|improve this answer
1  
Ooh, that's cool. I'll need to add that to my toolbox for future usage. –  EEAA Jun 28 '10 at 2:39
    
Ooh +1, I feel smarter just for now knowing that exists. –  troyengel Jun 28 '10 at 5:52
    
i notify is very cool ! it does not, however, monitor sub directory's... : ( –  arod Jun 28 '10 at 12:32
    
@arod: That's true, inotify doesn't do recursive monitoring. You would need to add an incron rule for each specific directory. –  Dennis Williamson Jun 28 '10 at 12:58
    
yep, and thats a bit cumbersome... directories pop in and out of existence erraticaly ; ) –  arod Jun 28 '10 at 13:22

It seems like DRBD will do just what you need. It works at the block device level, so if you don't want to maintain a separate partition for this synchronized data, you can just create a disk image and mount it loopback, using DRBD to keep things in sync with the remote server.

share|improve this answer
    
it's right that using DRBD sound like the right solution, things like "you can just create a disk image and mount it loopback" are not so clear. i didnt like drbd because i needed to store my files in a different partition, seems like to big a solution for syncing a couple of folders... if you could explain how to "create a disk image and mount it loopback", can this be used to sync a couple of folders ? thanks !! –  arod Jun 28 '10 at 12:35

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.