synchronization - 如果服务器上的文件不同,rsync 是否会忽略文件时间戳并自动覆盖客户端?

标签 synchronization rsync

我正在尝试设置两台 PC 来同步文件夹树,以便每台 PC 都拥有该树的副本,其中包含每个文件的最新更新。

我考虑过设置 Mercurial,但意识到我并不真正关心版本控制(特别是因为我的磁盘空间不足),而且 rsync 听起来像是我想要的更多 - 只是保持文件最新,没有版本。

然而,页面在http://www.linuxjournal.com/content/synchronizing-your-life说如下:

With rsync, any files that already exist at the destination will not be transferred. This speeds up the transfer time considerably. However, there is still the problem of having modifications made on both sides. By default, the rsync program only looks to see if the files are different in size and timestamp. It doesn't care which file is newer, if it is different, it gets overwritten.

You can pass the '--update' flag to rsync which will cause it to skip files on the destination if they are newer than the file on the source, but only so long as they are the same type of file. What this means is that if, for example, the source file is a regular file and the destination is a symlink, the destination file will be overwritten, regardless of timestamp. Even looking past its quirks, the --update flag does not solve the problem because all it does is skip files on the destination if they are newer, it doesn't pull those changes down to the source computer.



这是正确的吗?

如果是这样,我想它使 rsync 真正仅用于将一台主(“源”)机器备份到一台或多台从主机上,无论时间戳如何,这些从主机都会获得更改。而我真正想要解决的问题是让两台机器成为“对等机”,并且同样只是从另一台机器获取最近更新的文件。

或者你认为我必须硬着头皮使用 git 或 Mercurial 尽管有额外的磁盘空间来跟踪版本?

(是的,我知道 Dropbox;我远远高于 2GB 免费帐户的限制,并且我对每年花费 120-240 美元并不感兴趣,因为我不需要云存储,而且以前必须使用免费和打开工具。)

两台 PC 都运行 XP,但我打算使用 Cygwin 的 rsync 和完成工作所需的任何其他 Unixy 工具。

最佳答案

rsync av --update /loc1 /loc2

所以只有较新的文件才会从 loc1 同步到 loc2。
逻辑规定,任何在 loc2 上较新的文件都将保持不变。
因此,由于 loc1,loc2 上的所有过时文件都将是最新的
rsync av --update /loc2 /loc1

现在我们知道 loc1 拥有的所有更新的文件都被复制到了 loc2。
loc1 上较旧的任何文件(在 loc2 上有较新的文件)保持不变。
第二个 rsync 命令现在将使用 loc2 上较新的文件更新 loc1

等等!在这个例子中,两个位置都是同步的。

关于synchronization - 如果服务器上的文件不同,rsync 是否会忽略文件时间戳并自动覆盖客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3641181/

相关文章:

macos - mac检查网盘是否可用

linux - Rsync 排除除 1 个目录树以外的所有内容

virtual-machine - 同步虚拟机的内容

c - 在多进程环境中读取文件时意外的 EOF

linux - rsync 和(后)处理同步文件

java - 获取多个锁时发生死锁

绘制和计算命令与 BufferMemory 屏障之间的同步

ssh - rsync主机 key 验证失败

JavaScript 同步 promise 返回

java - 非同步线程和同步线程的区别