【问题标题】:rsync only certain types of filesrsync 仅某些类型的文件
【发布时间】:2018-05-29 18:01:37
【问题描述】:

我知道对此进行了广泛的讨论,但我还没有找到这么具体的东西。 我试图复制 /home// 目录中的所有 .key 文件

这不起作用

/usr/bin/rsync -auPA --include="*/*.key" --exclude="*" /home/* /tmp/test

这可行,但它会复制不需要的空目录,例如 /home/uname/Documents

/usr/bin/rsync -auPA --include="*/" --include="*.key" --exclude="*" /home /tmp/test

基本上我需要 rsync 做的是只复制带有 .key 扩展名的文件,并且只创建包含 .key 文件的必要文件夹

【问题讨论】:

标签: linux bash shell rsync


【解决方案1】:

我认为您正在寻找-m 选项。从手册页:

-m, --prune-empty-dirs
          This option tells the receiving rsync to get rid of empty directories from the file-list, including  nested  directories  that
          have  no  non-directory children.  This is useful for avoiding the creation of a bunch of useless directories when the sending
          rsync is recursively scanning a hierarchy of files using include/exclude/filter rules.

          Note that the use of transfer rules, such as the --min-size option, does not affect what goes into the  file  list,  and  thus
          does not leave directories empty, even if none of the files in a directory match the transfer rule.

          Because the file-list is actually being pruned, this option also affects what directories get deleted when a delete is active.
          However, keep in mind that excluded files and directories can prevent existing items from being deleted due to an exclude both
          hiding source files and protecting destination files.  See the perishable filter-rule option for how to avoid this.

          You can prevent the pruning of certain empty directories from the file-list by using a global "protect" filter.  For instance,
          this option would ensure that the directory "emptydir" was kept in the file-list:

          --filter ’protect emptydir/’


          Here’s an example that copies all .pdf files in a hierarchy, only creating the necessary destination directories to  hold  the
          .pdf  files,  and  ensures  that any superfluous files and directories in the destination are removed (note the hide filter of
          non-directories being used instead of an exclude):

          rsync -avm --del --include=’*.pdf’ -f ’hide,! */’ src/ dest


          If you didn’t want to remove superfluous destination files, the more time-honored options  of  "--include='*/'  --exclude='*'"
          would work fine in place of the hide-filter (if that is more natural to you).

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 2019-10-31
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多