奇怪的rsync行为

所以,我开始比较两个目录:

[root@135759 ]# rsync -av test1/ test2/ building file list ... done sent 128 bytes received 20 bytes 296.00 bytes/sec total size is 6 speedup is 0.04 

他们都同步现在,让我在test1中创build一个文件,并将其复制到test2

 [root@135759 ]# touch test1/hello4.php [root@135759 ]# scp test1/hello4.php test2/hello4.php 

我确认这些是一样的:

 [root@135759 test2]# md5sum test1/hello4.php d41d8cd98f00b204e9800998ecf8427e hello4.php [root@135759 test1]# md5sum test2/hello4.php d41d8cd98f00b204e9800998ecf8427e hello4.php 

因此,运行rsync会显示我0个文件。 为什么输出不正确?

 [root@135759 ]# rsync -avn test1/ test2/ building file list ... done hello4.php sent 116 bytes received 24 bytes 280.00 bytes/sec total size is 6 speedup is 0.04 

文件内容相同,所以rsyinc发送的数据非常less。 但我怀疑文件中的一些元数据是不同的。 我猜测创build与修改时间戳可能是基于你的例子。 检查那些在第二次运行rsync之前。 当rysnc看到不同的时间戳时,即使没有涉及文件数据,也会执行该文件的“传输”,并且只执行元数据。

rsync默认是通过文件mtime和size进行“快速”比较; 即使本地时钟漂移有时也会导致这个问题,所以如果你真的需要知道这些文件是完全相同的,然后决定跳过它们传输,使用rsync的--checksum选项,它将校验每一端的文件,并比较结果。 应预先警告,对于涉及大文件或多个文件的操作,这个选项可能非常耗费CPU时间,并且会大大增加同步所需的时间。