rsync только определенные типы файлов - PullRequest
0 голосов
/ 29 мая 2018

Я знаю, что по этому поводу велись огромные дискуссии, но я не нашел что-то конкретное.Я пытаюсь скопировать все .key файлы в / home / / directory

Это не работает

/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

1 Ответ

0 голосов
/ 29 мая 2018

Я думаю, что вы ищете вариант -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).
...