Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
pxiphx
V2EX  ›  Linux

关于 rsync 的新发现

  •  
  •   pxiphx · May 14, 2021 · 3787 views
    This topic created in 1961 days ago, the information mentioned may be changed or developed.

    我使用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传输时间、大小都一致的文件

    9 replies  •  2021-05-14 21:21:21 +08:00
    xiaket
        1
    xiaket  
       May 14, 2021
    仔细看 man, 有-c 的
    ho121
        2
    ho121  
       May 14, 2021 via Android
    --checksum, -c skip based on checksum, not mod-time & size
    EPr2hh6LADQWqRVH
        3
    EPr2hh6LADQWqRVH  
       May 14, 2021
    修改时间一致大小也一致可以了,难道每次还算个哈希,CPU 不花电钱的么
    pxiphx
        4
    pxiphx  
    OP
       May 14, 2021
    @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
        5
    pxiphx  
    OP
       May 14, 2021
    @xiaket @ho121 我懂了,这里是先检测是否传输某文件,至于文件怎么传是后面的事情
    https://imgur.com/a/qEfkqVR
    pxiphx
        6
    pxiphx  
    OP
       May 14, 2021
    pxiphx
        7
    pxiphx  
    OP
       May 14, 2021   ❤️ 1
    yfugibr
        8
    yfugibr  
       May 14, 2021 via Android
    不同文件系统不是用 `--modify-window`吗
    FindHao
        9
    FindHao  
       May 14, 2021
    我一般是 acvz
    z 还可以压缩下。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2585 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 06:35 · PVG 14:35 · LAX 23:35 · JFK 02:35
    ♥ Do have faith in what you're doing.