技术解析
我使用rsync
从ext4
硬盘将文件复制到FAT32
硬盘(使用FAT32
是为了兼容Windows
和Mac
)
复制的过程中,我发现rsync
没有增量传输,而是每次都重新传输
查了一下,得知FAT
磁盘的时间存储位比ext
少,导致 rsync 认为两边文件时间不一致
据微软所说,NTFS
toFAT
也有这个问题
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
传输时间、大小都一致的文件