我有这些目录SRC
,,DST
:COMPARE
/opt/SRC
file1 file2 file3
/opt/DST
file1 file2
/opt/COMPARE
空的
我希望:
$ ls /opt/COMPARE
file3
但是当我跑步时:
rsync -avz --compare-dest=/opt/COMPARE /opt/SRC/ /opt/DST
该/opt/COMPARE
目录还是空的,为什么?
答案1
我认为您的应用方式--compare-dest
不正确。
从man rsync
--compare-dest=DIR This option instructs rsync to use DIR on the destination machine as an additional hierarchy to compare destination files against doing transfers (if the files are missing in the destination directory). If a file is found in DIR that is identical to the sender’s file, the file will NOT be transferred to the destination direc‐ tory. This is useful for creating a sparse backup of just files that have changed from an earlier backup. This option is typically used to copy into an empty (or newly created) directory. Beginning in version 2.6.4, multiple --compare-dest directories may be provided, which will cause rsync to search the list in the order specified for an exact match. If a match is found that differs only in attributes, a local copy is made and the attributes updated. If a match is not found, a basis file from one of the DIRs will be selected to try to speed up the transfer. If DIR is a relative path, it is relative to the destination directory. See also --copy-dest and --link-dest. NOTE: beginning with version 3.1.0, rsync will remove a file from a non-empty des‐ tination hierarchy if an exact match is found in one of the compare-dest hierar‐ chies (making the end result more closely match a fresh copy).
如果我没看错的话,--compare-dest
过去常常停止发送某些文件。这将允许您创建一个新的复制目标目录,其中仅包含自上次复制以来已更改的文件。如果您愿意的话,这可以说是一种增量复制。
答案2
- rsync 会将 /opt/SRC 中的文件与 /opt/COMPARE 中的文件进行比较。如果文件存在于 /opt/SRC 中而不存在 /opt/COMPARE 中,或者两者中存在不同版本,则会将其复制到 /opt/DST。
- rsync 不仅在决定文件是否“相同”时检查内容。为了使其正常工作,您有时应该使用诸如“--no-times”(这个对我有用)或“--no-perms”、“--no-owner”、“--no-group”、“--checksum”等标志。
- 使用“--dry-run”来测试行为是一个好主意,而无需实际复制。