V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
pxiphx
V2EX  ›  Linux

关于 rsync 的新发现

  •  
  •   pxiphx · 2021-05-14 11:44:54 +08:00 · 2464 次点击
    这是一个创建于 1049 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    9 条回复    2021-05-14 21:21:21 +08:00
    xiaket
        1
    xiaket  
       2021-05-14 11:50:31 +08:00
    仔细看 man, 有-c 的
    ho121
        2
    ho121  
       2021-05-14 11:52:43 +08:00 via Android
    --checksum, -c skip based on checksum, not mod-time & size
    EPr2hh6LADQWqRVH
        3
    EPr2hh6LADQWqRVH  
       2021-05-14 11:54:13 +08:00
    修改时间一致大小也一致可以了,难道每次还算个哈希,CPU 不花电钱的么
    pxiphx
        4
    pxiphx  
    OP
       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
        5
    pxiphx  
    OP
       2021-05-14 12:25:22 +08:00
    @xiaket @ho121 我懂了,这里是先检测是否传输某文件,至于文件怎么传是后面的事情
    https://imgur.com/a/qEfkqVR
    pxiphx
        6
    pxiphx  
    OP
       2021-05-14 12:25:47 +08:00
    pxiphx
        7
    pxiphx  
    OP
       2021-05-14 12:27:03 +08:00   ❤️ 1
    yfugibr
        8
    yfugibr  
       2021-05-14 17:22:35 +08:00 via Android
    不同文件系统不是用 `--modify-window`吗
    FindHao
        9
    FindHao  
       2021-05-14 21:21:21 +08:00
    我一般是 acvz
    z 还可以压缩下。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1329 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:45 · PVG 01:45 · LAX 10:45 · JFK 13:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.