用rsync进行双向同步 [英] Two way sync with rsync

查看:676
本文介绍了用rsync进行双向同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹a/和一个远程文件夹A/. 现在,我在Makefile上运行以下内容:

I have a folder a/ and a remote folder A/. I now run something like this on a Makefile:

get-music:
 rsync -avzru server:/media/10001/music/ /media/Incoming/music/

put-music:
 rsync -avzru /media/Incoming/music/ server:/media/10001/music/

sync-music: get-music put-music

当我做sync-music时,它首先将所有差异从服务器发送到本地,然后将其发送到另一端,将所有差异从本地发送到服务器.

when I make sync-music, it first gets all the diffs from server to local and then the opposite, sending all the diffs from local to server.

仅当将来只有更新或新文件时,此方法才能很好地工作.如果有删除,则不会执行任何操作.

This works very well only if there are just updates or new files on the future. If there are deletions, it doesn't do anything.

在rsync中,有--delete和--delete-after选项可以帮助完成我想要的操作,但事实是,它在2向同步中不起作用.

In rsync there is --delete and --delete-after options to help accomplish what I want but thing is, it doesn't work on a 2-way-sync.

如果我想删除syn上的服务器文件,则删除本地文件后,它可以工作,但是如果由于某种原因(稍后说明),我有一些不在服务器中但位于本地的文件,它们被删除,我想在本地删除它们,而不是服务器复制(发生这种情况).

If I want to delete server files on a syn, when local files have been deleted, it works, but if, for some reason (explained after) I have some files that aren't in the server but exist locally and they were deleted, I want locally to remove them and not server copied (as it happens).

问题是我在上下文中有3台计算机:

Thing is I have 3 machines in context:

  1. 桌面
  2. 笔记本
  3. 家庭服务器

因此,有时,服务器将具有通过笔记本同步删除的文件,例如,然后,当我与台式机运行同步时(已删除的服务器文件仍然存在),我希望删除这些文件并不再再次复制到服务器.

So, sometimes, server will have files that were deleted with a notebook sync, for example and then, when I run a sync with my desktop (where the deleted server files still exist on) I want these files to be deleted and not to be copied again to the server.

我想这只有在数据库和操作轨迹下才可能实现:P

I guess this is only possible with a database and track of operations :P

有没有更简单的解决方案? 谢谢.

Any simpler solutions? Thank you.

推荐答案

尝试Unison: http ://www.cis.upenn.edu/~bcpierce/unison/

语法: unison dirA/ dirB/

Syntax: unison dirA/ dirB/

Unison询问文件不同时该怎么办,但是您可以使用以下接受默认(无冲突)选项的自动化操作:

Unison asks what to do when files are different, but you can automate the process by using the following which accepts default (nonconflicting) options:

unison -auto dirA/ dirB/

unison -batch dirA/ dirB/完全不问任何问题,并写输出忽略了多少文件(因为它们有冲突).

unison -batch dirA/ dirB/ asks no questions at all, and writes to output how many files were ignored (because they conflicted).

这篇关于用rsync进行双向同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆