Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Sidenote: Lately I've all but given up on bzip2. I use lzma (from the lzma, lzma-utils, or lzma-sdk package, name depends on your distribution.) It usually compresses the same or better than bzip2 given the same CPU time - and when it comes to decompression it simply blows bzip2 away. –  Mihai Limbăşan May 2 '09 at 19:53

3 Answers 3

up vote 3 down vote accepted
export BZIP=--fast
tar cjf foo.tar.bz2 foo

Or pipe the output of tar to bzip2.

Though you should note from the bzip2 man page:

    -1 (or --fast) to -9 (or --best)
              Set  the  block size to 100 k, 200 k ..  900 k when compressing.
              Has no effect when decompressing.  See MEMORY MANAGEMENT  below.
              The --fast and --best aliases are primarily for GNU gzip compat-
              ibility.  In particular, --fast  doesn't  make  things  signifi-
              cantly faster.  And --best merely selects the default behaviour.
share|improve this answer

Send the tar output to stdout and then pipe it through bzip2 separately:

% tar cvf - _file_ | bzip2 _opts_ > output.tar.bz2
share|improve this answer

Its even easier:

% tar -cvf dir.tar path/to/dir/ && bzip2 -9 dir.tar
share|improve this answer
1  
Using a temporary file means you need enough hard disk space, plus bandwidth for tar to write and bzip2 to read it. This may seem trivial for small amounts of data, but when the directory in question has several hundred gigabytes, it may become a real problem. –  Ansgar Esztermann Jan 10 '13 at 10:51

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.