Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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 | 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
  3. Use the timestamp to compare files:

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

I found this for Dropbox:

share|improve this answer
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 '11 at 9:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.