
我使用rsync从ext4硬盘将文件复制到FAT32硬盘(使用FAT32是为了兼容Windows和Mac)
复制的过程中,我发现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传输时间、大小都一致的文件
1 xiaket 2021-05-14 11:50:31 +08:00 仔细看 man, 有-c 的 |
2 ho121 2021-05-14 11:52:43 +08:00 via Android --checksum, -c skip based on checksum, not mod-time & size |
3 EPr2hh6LADQWqRVH 2021-05-14 11:54:13 +08:00 修改时间一致大小也一致可以了,难道每次还算个哈希,CPU 不花电钱的么 |
4 pxiphx OP |
| td width="auto" valign="top" align="left"> |
6 pxiphx OP |
7 pxiphx OP |
8 yfugibr 2021-05-14 17:22:35 +08:00 via Android 不同文件系统不是用 `--modify-window`吗 |
9 FindHao 2021-05-14 21:21:21 +08:00 我一般是 acvz z 还可以压缩下。 |