is there some sort of catchable trigger when one writes/deletes a new file in linux?

Posted on

is there some sort of catchable trigger when one writes/deletes a new file in linux? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, rsync, synchronization, write, .

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 !


Solution :

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.

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

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

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.

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

Leave a Reply

Your email address will not be published.