Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to exclude some directories from backup. But not all with specific name - only those lying under specified root directory. With rsync I would use exclude mask like this:

/path/excludeRoot/**/directoryToExclude

which means that all directories with name directoryToExclude lying below /path/excludeRoot will be excluded.

On the other hand: each directory with name directoryToExclude but lying elsewhere will be included

Is it possible to do it with tar?

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.