Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Jan 2013 11:09:19 -0800
From:      Chuck Swiger <cswiger@mac.com>
To:        tundra@tundraware.com
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Syncing Two Dirs With Rsync
Message-ID:  <67BEF7CB-1FC4-43EB-AFF8-8ECD3A68B214@mac.com>
In-Reply-To: <50EF0F1F.8080904@tundraware.com>
References:  <50EF0F1F.8080904@tundraware.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Jan 10, 2013, at 10:57 AM, Tim Daneliuk wrote:
> I have used rsync for many years to make sure a destination
> machine:directory is kept up-to-date with some source master
> directory.
> 
> I now need to find a way to keep two different machine:dirs
> in sync with each other.  But for any given file, I don't know
> which of these is newer so I don't know "which way" to sync.
> 
> For example given:
> 
> machineA::/dir/foo      machineB:/dir/foo
> machineA::/dir/bar      machineB:/dir/bar
> 
> Say the machineA has the newest foo, but machineB has the
> newest bar.  At the end of syncing, I want both machines
> to have the latest copies of everything.
> 
> I'm guessing there's a way to do this with rsync but I'm kind
> of stumped.

rsync's --update flag will not overwrite a file at the destination if it was modified more recently then the source location.  So you can run rsync twice to sync from A to B and then from B to A.  Make very sure both boxes are keeping correct time and/or are mutually sync'ed via NTP or similar.

However, if you make different changes to the same file on A and on B, you will lose one of them.  (That is what version control systems like SVN and git would resolve.  So if you do plan to do 2-way or N-way changes and sync'ing on a regular basis, version control is much less likely to lose changes or otherwise screw up.)

Regards,
--  
-Chuck




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?67BEF7CB-1FC4-43EB-AFF8-8ECD3A68B214>