RSync: How do I synchronize in both directions?

人盡茶涼 提交于 2019-12-29 02:32:39

问题


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:


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.




回答2:


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.




回答3:


Thanks jsight

rsync -urv --progress dir_a dir_b && rsync -urv  --progress dir_b dir_a

This would result in the second sync happening immediately after 1st sync is over. In case the directory structure is huge, this will save time, as one does not need to sit before the pc. If the structure is huge, remove the verbose and progress stuff

rsync -ur dir_a dir_b && rsync -ur dir_b dir_a



回答4:


Use rsync <OPTIONS> [hostname:]source-dir [hostname:]dest-dir

for example:

rsync -pogtEtvr --progress --bwlimit=2000 xxx-files different-stuff

Will sync xxx-files to different-stuff/xxx-files .If different-stuff/xxx-files did not exist, it will create it - i.e. copy it.

-pogtEtv - just bunch of options to preserve file metadata, plus v - verbose and r - recursive

--progress - show progress of syncing in real time - super useful if you copy big files

--bwlimit=2000 - sets maximum speed of copying/syncing (bw = bandwidth)

P.S. rsync is critically important when you work over network in case of local machine you can use commands like cp.

Good Luck!




回答5:


I'm using rsync with inotifywait. When you change any file, rsync will be executed.

inotifywait -m --exclude "$_LOG_FILE" -r -e create,delete,delete_self,modify,moved_to --format "%w%f" "$folder"

You need run inotifywait on both host. Please check example inotifywait




回答6:


What you need is Rclone. Rclone ("rsync for cloud storage") is a command line Linux program to sync files and directories to and from different cloud storage providers (box,dropbox,ftp etc) and local filesystems. Rlone supports mirror syncing only.

Another more graphical solution which includes real-time syncing would be to use FreeFileSync, which includes the program RealTimeSync. FreefileSync support 2-way bidirectional syncing which includes handling deletes.



来源:https://stackoverflow.com/questions/1602324/rsync-how-do-i-synchronize-in-both-directions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!