deleting files in rsync ( rsync 中的delete)

访问量: 2329

最近要使用rsync 来同步接近大小1G,总共50W个的文件。由于需要保证服务器上一直有对应的文件存在, 杰杰  问我rsync 的上传/删除文件的 具体顺序是怎样的。 我当时不清楚,所以赶紧学习了下: ( in my job, I need to rsync 500, 000 files to a server , totally in 1 GB file size. and I used the --delete option, so it's very important for me to know how rsync delete files) 

总结: 应该使用 --delete --delete-after 选项。(两个同时存在)

$ man rsync : 

The --delete option may be combined with one of the --delete-WHEN options
without conflict, as well as --delete-excluded. However, if none of the
--delete-WHEN options are specified, rsync will choose the --delete-during
algorithm when talking to rsync 3.0.0 or newer, and the --delete-before algo‐
rithm when talking to an older rsync. See also --delete-delay and
--delete-after.       ( 也就是说, --delete 选项可以跟 --delete-WHEN 一起使用,如果不指定 --delete-WHEN的话,就会默认使用 --delete-during 算法)

--delete-before
Request that the file-deletions on the receiving side be done before the
transfer starts. See --delete (which is implied) for more details on
file-deletion.  ( 在 接收方收到文件之前,先删掉 多余的文件。 适合 接收方磁盘空间不够的情况)

--delete-during, --del
Request that the file-deletions on the receiving side be done incrementally as
the transfer happens. The per-directory delete scan is done right before each
directory is checked for updates, so it behaves like a more efficient
--delete-before, including doing the deletions prior to any per-directory fil‐
ter files being updated.  ( 应该是 在每一个子目录被上传之前,先删掉目标目录中的文件。应该是一种 --delete-before. )

--delete-delay (太长没看懂。。。需要先动手试一下,估计是先上传,再执行删除。。。)
Request that the file-deletions on the receiving side be computed during the
transfer (like --delete-during), and then removed after the transfer com‐
pletes. This is useful when combined with --delay-updates and/or --fuzzy, and
is more efficient than using --delete-after (but can behave differently, since
--delete-after computes the deletions in a separate pass after all updates are
done). If the number of removed files overflows an internal buffer, a tempo‐
rary file will be created on the receiving side to hold the names (it is
removed while open, so you shouldn’t see it during the transfer). If the cre‐
ation of the temporary file fails, rsync will try to fall back to using
--delete-after (which it cannot do if --recursive is doing an incremental
scan). See --delete (which is implied) for more details on file-deletion.  

--delete-after (先上传, 再删除文件)
Request that the file-deletions on the receiving side be done after the trans‐
fer has completed. This is useful if you are sending new per-directory merge
files as a part of the transfer and you want their exclusions to take effect
for the delete phase of the current transfer. It also forces rsync to use the
old, non-incremental recursion algorithm that requires rsync to scan all the
files in the transfer into memory at once (see --recursive). See --delete
(which is implied) for more details on file-deletion.

订阅/RSS Feed

Subscribe

分类/category