Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I synchronize in both directions?

Tags:

rsync

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?

like image 454
java.is.for.desktop Avatar asked Oct 21 '09 17:10

java.is.for.desktop


People also ask

What is two-way synchronization?

Two-Way - in this synchronization type changes introduced on items in source and target folders are reflected in both directions. It doesn't matter if you create, edit or delete items on source or target folder, the change will be replicated to them equally. This type of synchronization is also called a folder ring.

Does rsync go both ways?

rsync works in one direction, so we need to run it twice to sync directories in both directions.

What are one-way and two-way sync?

One-way sync will sync any added or updated content in the destination, for example. On the other hand, two-way sync (or bi-directional syncing) will synchronize whether you update the file in the source or destination.

What is oneway sync?

One-Way - involves synchronizing items only in one direction: from the source folders to the target folders. It means that once you create, delete or change any items in the source folder, this will be reflected in the target folder.


1 Answers

Just run it twice, with "newer" mode (-u or --update flag) plus -t (to copy file modified time), -r (for recursive folders), and -v (for verbose output to see what it is doing):

rsync -rtuv /path/to/dir_a/* /path/to/dir_b rsync -rtuv /path/to/dir_b/* /path/to/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.

like image 117
jsight Avatar answered Nov 08 '22 11:11

jsight