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?
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.
rsync works in one direction, so we need to run it twice to sync directories in both directions.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With