rsync 的 --fuzzy 选项如何工作?

And*_*edt 9 rsync

如何rsync --fuzzy工作?我没有得到我期望的结果。

从手册:

这个选项告诉 rsync 它应该为任何丢失的目标文件寻找一个基础文件。当前算法在与目标文件相同的目录中查找具有相同大小和修改时间的文件或名称相似的文件。如果找到,rsync 会使用模糊基础文件来尝试加快传输速度。

如果重复该选项,则还将在通过 --compare-dest、--copy-dest 或 --link-dest 指定的任何匹配的备用目标目录中进行模糊扫描。

请注意,使用 --delete 选项可能会删除任何潜在的模糊匹配文件,因此如果需要防止这种情况发生,请使用 --delete-after 或指定一些文件名排除项。

因此,我希望以下 shell 脚本在第二次 rsync 运行时将文件 destination/a1 重命名为 destination/a2。然而,当我解释输出时,这不是正在发生的事情(Matched data: 0 bytes)。

#! /usr/bin/env bash
set -e

cd $(mktemp -d)
mkdir source destination
cat /dev/urandom | head --bytes=1M > source/a1
rsync --recursive --times $(pwd)/source/ $(pwd)/destination/
tree
mv source/a1 source/a2
rsync \
    --verbose \
    --recursive \
    --times \
    --delete \
    --delete-after \
    --fuzzy \
    --human-readable \
    --itemize-changes \
    --stats \
    $(pwd)/source/ \
    $(pwd)/destination/
tree
rm -r source destination
Run Code Online (Sandbox Code Playgroud)

输出:

??? destination
?   ??? a1
??? source
    ??? a1

2 directories, 2 files
building file list ... done
>f+++++++++ a2
*deleting   a1

Number of files: 2 (reg: 1, dir: 1)
Number of created files: 1 (reg: 1)
Number of deleted files: 1 (reg: 1)
Number of regular files transferred: 1
Total file size: 1.05M bytes
Total transferred file size: 1.05M bytes
Literal data: 1.05M bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 1.05M
Total bytes received: 34

sent 1.05M bytes  received 34 bytes  2.10M bytes/sec
total size is 1.05M  speedup is 1.00
.
??? destination
?   ??? a2
??? source
    ??? a2

2 directories, 2 files
Run Code Online (Sandbox Code Playgroud)

的输出rsync --version

rsync  version 3.1.2  protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes, prealloc

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
Run Code Online (Sandbox Code Playgroud)

如何rsync --fuzzy工作?

为什么我没有得到预期的结果?

roa*_*ima 6

您正在使用rsync在两个本地文件树之间复制文件。--fuzzy在此模式下,将忽略增量算法及其所有相关优化(例如 ) 。

将本地文件复制到远程服务器(或远程到本地;这并不重要)重复测试,您会发现它按预期工作。

例如,在两个地方修改脚本,例如$(pwd)/destination更改为localhost:$(pwd)/destination. 它并不优雅,但已经足够了。

# Set up PKI for localhost
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
ssh localhost id
Run Code Online (Sandbox Code Playgroud)

第二个的脚本结果rsync

building file list ... done
<f+++++++++ a2
*deleting   a1

Number of files: 2 (reg: 1, dir: 1)
Number of created files: 1 (reg: 1)
Number of deleted files: 1 (reg: 1)
Number of regular files transferred: 1
Total file size: 1.05M bytes
Total transferred file size: 1.05M bytes
Literal data: 0 bytes
Matched data: 1.05M bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 4.20K
Total bytes received: 6.18K

sent 4.20K bytes  received 6.18K bytes  20.75K bytes/sec
total size is 1.05M  speedup is 101.09
Run Code Online (Sandbox Code Playgroud)