tar - как исключить так: "/ путь / excludeRoot / ** / directoryToExclude"

476
ardabro

Я хотел бы исключить некоторые каталоги из резервной копии. Но не все с конкретным именем - только те, которые лежат под указанным корневым каталогом. С rsync я бы использовал исключающую маску следующим образом:

/path/excludeRoot/**/directoryToExclude 

Это означает, что все каталоги с именем, directoryToExcludeлежащим ниже, /path/excludeRootбудут исключены.

С другой стороны: каждый каталог с именем, directoryToExcludeно лежащий в другом месте будет включен

Можно ли сделать это с помощью tar?

2

1 ответ на вопрос

1
Wejn

That is, unfortunately not straightforwardly possible as the --exclude family of options is not powerful enough.

One approach would be to obtain the list of objects using external program (say find) and then use -T switch to tell tar which files/objects should be included.

Quoting from the man page:

-T, --files-from FILE get names to extract or create from FILE 

If the filenames contain special symbols (and/or spaces) I would add --null to the tar command line; to generate the list I would also use -print0 with find -- to separate the files/dirs with NUL (\000) character.

Похожие вопросы