0

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

arod
  • 542
  • 6
  • 19

4 Answers4

3

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.

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
2

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
weeheavy
  • 4,039
  • 1
  • 27
  • 41
  • inotify is excellen, but it get cumbersome when tracking directories and subdirectories... – arod Jun 29 '10 at 10:52
  • 1
    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
1

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.

EEAA
  • 108,414
  • 18
  • 172
  • 242
  • 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
0

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

symcbean
  • 19,931
  • 1
  • 29
  • 49
  • 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