1

I am trying to keep two peer directories in sync using rsync. The problem I have is that new files can be added or deleted in either directory before a sync occurs.

If a deletion occurs in one, then the --delete option would delete that file in the other location as long as it was chosen as the target first. Otherwise, if the directory with the stale file still in it was chosen as the source initially, then the file would be copied across to the directory we had previously deleted it from.

If a file is created in one and that directory is not chosen as the source, then the file will be classed as extraneous by the --delete option and be removed, despite being a valid addition.

Is there a way of making more intelligent deletions or excludes based on timestamps? If not, then I only see rsync as a master-slave tool, and not able to cope with a peer-peer relationship.

1 Answer 1

1

You could hack a bash scipt together based on timestamps using CURL -I which gives you header info for the files.

  1. Check the timestamp:

    curl -I http://somesite.com/somefolders/somefile.script | grep Date:
    Date: Fri, 11 Feb 2011 06:24:40 GMT
    
  2. Convert time to timestamp:

    date --utc --date "Fri, 11 Feb 2011 06:24:40 GMT" +%s
    
    1297405480
    
  3. Use the timestamp to compare files:

    if [[ time1 == time2 ]]; then curl (upload file)
    

I found this for Dropbox: http://davehope.co.uk/Blog/backup-your-linux-vps-to-dropbox/

1
  • Thank you Paul that's a good idea, and I hadn't thought of Dropbox. Those guys are doing this sort of peer-to-peer synchronisation professionally. I've been working through the logic, and storing a history of adds and deletes with timestamps seems to be the only true way of unifying equal rights folders.
    – Jeff
    Feb 15, 2011 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .