views:

622

answers:

2

Hello!

I want to use rsync to synchronize two directories in both directions.

I refer to synchronization in classical sense (not how it is meant in rsync manuals):
I want to update the directories in both directions, depending on which of them is newer.

Can this be done by rsync (preferable in a Linux-way)?
If not, what other solutions exist?

+1  A: 

Just run it twice, with "newer" mode: rsync -u -r dir_a dir_b rsync -u -r dir_b dir_a

This won't handle deletes, but I'm not sure there is a good solution to that problem with only periodic sync'ing.

jsight
Since the question was about rsync, I'll mark this answer as correct.
java.is.for.desktop
But you asked about other solutions also and Unison do a better job, otherwise I would never mentioned another tool. I understand that you perhaps have specific circumstances that favor the use of rsync.
MaD70
Sheesh, you get 6 upvotes and you're still complaining? <j/k> Unison is a really interesting solution, and I'm glad that you mentioned it. :)
jsight
Well I'm not complaining, I'm explaining. Just to check that I'm not missing something (not being a native English speaker).
MaD70
MaD70 - No problem... I was just kidding. :)
jsight
+6  A: 

Do you know Unison File Synchronizer?

Unison is a file-synchronization tool for Unix and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other. ...

Note also that it is resilient to failure:

Unison is resilient to failure. It is careful to leave the replicas and its own private structures in a sensible state at all times, even in case of abnormal termination or communication failures.

MaD70
+1. Unison is the best way to do this. Double-rsync is hard to get right and doesn't handle deletes at all.
Avdi
Yes, Unison is fault resilient. I'm updating my answer to emphasize this.
MaD70
Hadn't heard of Unison. You are responsible of making me redo my backup scripts at home today.
voyager
I'm glad that my answer is so useful (this shows how could be practical a tool based on a sound theoretical foundation).
MaD70