I'm trying to create a very large backup of an entire hard disk, using tar. However, there are many files such as CR2 (Canon RAW 2), JPG and a few other files which are already compressed.I have seen excluding these types of files from the tar archive itself, using the --exclude option, but that is not what I would like to do. Instead, I would like to include these already-compressed files, but skip compression on them, similar to that of rsync's --skip-compress.Is this possible, and if yes, how can it be done?
tar while avoiding compression of certain file types
tar;compression
tar itself does not have this feature, you could only filter it so you have two independent tar files, one holding the compressed files, another for the uncompressed files. This can be achieved using tar's exclude option you mentioned, or by building file lists using find.If you are open to alternatives, there is dar (disk archive) which can decide whether to compress or not for each file individually (-Z, --exclude-compression <mask> option). It can also restore individual files in the archive without uncompressing the whole lot (until the file is found) like tar.Most people just ignore this problem altogether and compress all files regardless. With a fast compression algorithm it does not make much of a difference. Strong compression takes order of magnitude more CPU time with negligible size reduction (ymmv, depends a lot on the data). If it's an archive that will be downloaded lots of times, strong compression might be worth it, otherwise it may not be.