关于 rsync 的新发现

2021-05-14 11:44:54 +08:00
 pxiphx

我使用rsyncext4硬盘将文件复制到FAT32硬盘(使用FAT32是为了兼容WindowsMac

复制的过程中,我发现rsync没有增量传输,而是每次都重新传输

查了一下,得知FAT磁盘的时间存储位比ext少,导致 rsync 认为两边文件时间不一致

据微软所说,NTFStoFAT也有这个问题

When files are copied from NTFS drives to FAT drives, some file time stamp rounding has to occur; the file time stamp is rounded up to the next even second.

...

NTFS time stamp: 7 hours 31 min 0 sec 001.

FAT time stamp becomes 7 hours 31 min 2 sec 000.

至此我才明白,rsync只检查时间和文件大小,就决定两边文件是否一致

如果构造两个文件,内容不一样,但是时间和大小都一样,rsync就会认为两文件一样从而不再传输

比如,创建两个文件,一个内容为 123,一个内容为 321

$ cat file1.txt file2.txt
123
321

然后把他们 touch 成时间相同

$ touch file1.txt file2.txt

然后看一下他们的详细信息

$ stat file1.txt file2.txt
  File: file1.txt
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: 10302h/66306d   Inode: 7471107     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/z)   Gid: ( 1000/z)
Access: 2021-05-14 11:27:13.168183020 +0800
Modify: 2021-05-14 11:27:13.168183020 +0800
Change: 2021-05-14 11:27:13.168183020 +0800
 Birth: -
  File: file2.txt
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: 10302h/66306d   Inode: 7471108     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/z)   Gid: ( 1000/z)
Access: 2021-05-14 11:27:13.168183020 +0800
Modify: 2021-05-14 11:27:13.168183020 +0800
Change: 2021-05-14 11:27:13.168183020 +0800
 Birth: -

然后我们执行rsync

$ rsync -vv -n --no-whole-file --inplace file1.txt file2.txt
delta-transmission enabled
file2.txt is uptodate
total: matches=0  hash_hits=0  false_alarms=0 data=0

sent 46 bytes  received 76 bytes  244.00 bytes/sec
total size is 4  speedup is 0.03 (DRY RUN)

rsync果然没有传输

针对这种情况,还需要加上--ignore-times参数,才能让rsync传输时间、大小都一致的文件

2498 次点击
所在节点    Linux
9 条回复
xiaket
2021-05-14 11:50:31 +08:00
仔细看 man, 有-c 的
ho121
2021-05-14 11:52:43 +08:00
--checksum, -c skip based on checksum, not mod-time & size
EPr2hh6LADQWqRVH
2021-05-14 11:54:13 +08:00
修改时间一致大小也一致可以了,难道每次还算个哈希,CPU 不花电钱的么
pxiphx
2021-05-14 12:09:23 +08:00
@xiaket @ho121 感谢提醒,但是--checksum:skip based on checksum, not mod-time & size 和--ignore-times:don't skip files that match size and time,有什么区别呢?对于时间一样的文件,检查了 hash ;对于时间不一样的文件,还是检查了 hash
pxiphx
2021-05-14 12:25:22 +08:00
@xiaket @ho121 我懂了,这里是先检测是否传输某文件,至于文件怎么传是后面的事情
https://imgur.com/a/qEfkqVR
pxiphx
2021-05-14 12:25:47 +08:00
pxiphx
2021-05-14 12:27:03 +08:00
yfugibr
2021-05-14 17:22:35 +08:00
不同文件系统不是用 `--modify-window`吗
FindHao
2021-05-14 21:21:21 +08:00
我一般是 acvz
z 还可以压缩下。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/776894

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX