Feb 15, 2012

Linux – Splitting a backup into two steps


I create a tarball using tar zcf arhive.tar.gz dir/ and this works ok. Now I wanted to split this into two simple archives, one only for images, the other — for everything else.

It seems that there’s not a trivial and clean way to do this. For tar I can only exclude files, which is unreasonable to exclude every extension except gif, jpg, and png.

To include I have to use find with either –exec or | xargs. This kinda works, but breaks if the filenames have spaces or special characters (apostrophes, quotation marks). So now I have to pipe all the filenames into, say, awk and escape them manually?

What am I missing? Why is this so complicated?

I just wanted tar zcf archive-images.tar.gz dir/ --match-only=*.png

Asked by Mikhail


use find ... -print0 | xargs -0 tar... these two options exist in order to deal with filenames with spaces.

Answered by stew

Related posts:

  1. Linux: How do I archive select file extensions in an unknown tree
  2. How to exclude files from TAR archive using regular expressions?
  3. exclude directory with tar command
  4. Recursively archive small files in document tree on linux?
  5. Differential backup with TAR relative to specific weekday

Leave a comment