General Question

phocks's avatar

How do I detect when a file changes and trigger rsync to back it up?

Asked by phocks (137 points ) January 6th, 2011

On a Linux system I want the rsync program to detect when someone modifies a file and automatically trigger a backup at that point. Is this possible?

Kind of like the functionality of Dropbox http://www.dropbox.com/

Observing members: 0 Composing members: 0

2 Answers

koanhead's avatar

rsync does not natively have any way to detect changes to files. The easy way to do this would be to set up a cron job that calls rsync at some (short) time interval. This could be a little wasteful of resources if the rsync functionality is not constantly required by all users, so you could write a script using the at command to call rsync and put it in the user’s .bashrc file.
If you absolutely must detect file changes, both SELinux and AppArmor can track changes to selected parts of the filesystem. You could set up a profile for the filesystem in question, place the profile in audit mode (using aa-audit in AppArmor) and have your script tail the system log, grep for a string that indicates a file change, and call rsync when the string pops up. There might (hopefully) be a more elegant way to make it happen, but a few minutes’ perusal of the AppArmor API wiki didn’t turn up any obvious hooks.

Vincentt's avatar

I know Rhythmbox uses (used to use?) Gamin to track changes. Not sure if it solves your problem, but it might be a good starting point for more investigation.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther