I am using tar
to backup a linux server to tape. I am using the -j
option to compress the file with bzip2
, however I can't see a way to adjust the block size options for bzip2 from tar. The default block size is 900,000 bytes which gives the best compression but is the slowest. I am not that bothered about the compression ratio, so am looking to make bzip2 run faster with a smaller block size.
Or pipe the output of
tar
tobzip2
.Though you should note from the bzip2 man page:
bzip2
block sizesbzip2
has some block size options. From the manual pagebzip2(1)
:As you want faster compression with less regards to compression ratio, using
bzip2
, you seem to want the-1
(or--fast
) option.Setting
bzip2
block size when usingtar
You can set
bzip2
block size when usingtar
in a couple of ways.The UNlX way
My favorite way, the UNlX way, is one where you use every tool independently, and combine them through pipes.
You can read that as "create .tar with
tar
-> bzip it withbzip2
-> write it to[ARCHIVE].tar.bz2
".Environment variable
It is also possible to set
bzip2
options through the environment variableBZIP2
. From the manual pagebzip2(1)
:So to use that with
tar
, you could for example do:Faster alternatives
bzip2
uses a slow compression algorithm. If you are concerned about speed, you could investigate alternative algorithms, such as those used bygzip
orlzop
. Here is a nice article comparing compression tools: https://aliver.wordpress.com/2010/06/22/huge-unix-file-compresser-shootout-with-tons-of-datagraphs/Send the
tar
output tostdout
and then pipe it throughbzip2
separately:Its even easier: