keep 2 dirs in sync

Michael Makuch koodawg at gmail.com
Fri Jul 1 09:50:52 MDT 2011


I don't think there's a direct way to do this with rsync but I want to make sure 
I'm not missing something.

I have two hosts (my portable and my desktop). I work on both hosts at different 
times and so I keep a few dirs sync'd between the two. I have a docs dir where I 
may be modifying files, adding files, renaming files and deleting files on 
*either* host.

I have a nightly cron script (run on hosta) sync the docs dir on the two hosts 
that does;

rsync -au --delete hostb:docs/ docs # sync0
rsync -au --delete docs/ hostb:docs # sync1

which takes care of modified files on either host - last mod wins. That works.

Problem is adding, deleting and renaming files. I'm sure most know the problem 
here but I'll illustrate it to be clear;

If I add a new file91 on hostb then the nightly script copies file91 from hostb 
to hosta and I'm happy.

But if I add a new file92 on hosta then the sync0 deletes file92 from hosta. Not 
happy.

Then there is a corresponding opposite problem with deleting (and renaming) 
files. If I intentionally delete a file92 on hostb (which was previously sync'd 
on both hosts) then it gets copied back to hostb from hosta by sync1, which is 
not desired.

What I've been doing, for years, is doing the rsyncs without the --delete and 
then when I want to delete something I have to remember to delete it from both 
hosts manually.

Am I missing something? Is there some other direct way to do this? It appears 
that one would need a utility that maintained a separate copy of the dirs in 
order to know what had been deleted before performing the sync. This has 
probably been discussed ad nauseam in the rsync community but I haven't been 
able to find it. Other solutions?

Thanks
Mike


More information about the rsync mailing list