Thanks to Using inotify-wait to check filesystem events I got pointed to How to use inotify-tools to trigger scripts on filesystem events which is now on my research list.
–jeroen
Note that Kristian later on commented this:
The solution shown in the article has race conditions and should not be used.
It is based on
while :
do
inotifywait $options && run-backup
doneand that means that while the backup runs, the directory in question is unmonitored. When the backup finishes, new changes may have been accumulating during backup run, but without being picked up by the backup.
A proper solution would do something like
inotifywait -m $options | while read line
do
do-something-that-logs-multile-changes-and-triggers-backup-once
doneThe important thing is that “inotifywait -m” does not terminate and hence no changes will be lost. It is wrong to run the backup once in full for each change, though.