Implementing a conditional branch within rsync based on modified time of a file

Jeff Allen jeffreydavidallen at
Sat Jan 10 21:01:20 GMT 2009


I've been looking through archives, googling, and reading through man pages to no avail for some time now. I believe I need some combination of rsync -u (update) and rsync --del, and I'm not quite sure how to get it.

I'm looking to build a rough implementation of a multi-client rdiff-backup system; in order to do this I'm using rsync before rdiff-backup.

(We'll say there's a server, Client A, and Client B. Files should be synced between A and B but the server should keep a master list of all differences and changes made in any file, by any client in the directory I'm syncing).
Essentially, I envision that syncing client A would go something like this:
1. Rsync down from the server to Client A in order to ensure that any newly-created files added recently by Client B (which would have already been uploaded - via rdiff-backup - to the server) is added to the local directory on Client A.
2. Rdiff-backup from Client A to the server. This will not increment the freshly downloaded files created by client B, as the modified times are equal. However, it would update those newly-created/edit files on Client A since the last sync.

However, I will run into problems when I delete a file.
If I delete a file off of either client, the file will be un-deleted when I rsync down in step one, as the file would still exist on the server. But if I use rsync --del, it would just delete any and all new files created on a client since the last sync.

The best solution I can envision is to write a shell script (or modify the rsync source) which would alter step 1 above to the following:

global variable lastSync; //last synchronization for this client
function syncFile(file, modifiedDate){
  if (modifiedDate > lastSync){
     //this must be a new file created from another client.
     download the file from the server
     //the file has been deleted on the client since the last sync, delete it.
     delete the file.

I suppose I would first be interested to hear if anyone see any pitfalls/logical errors in the above implementation? 

More pertinently to this list, what approach should I take with this? Would it be possible to implement something of this nature with shell scripts or would I really need to modify the source? Has anyone tried anything comperable?

Thank you for your help and time


Windows Live™ Hotmail®: Chat. Store. Share. Do more with mail.
-------------- next part --------------
HTML attachment scrubbed and removed

More information about the rsync mailing list