I've been using tar with its "--use-compress-prog=pbzip2" function to archive my files then compress them with pbzip2 to get an "*.tar.bz" archive.

Afterwards I checked the resulting file with pbzip2's "-t" switch, and it passed the test. However, to great surprise, I got "file incomplete" or other integrity errors when trying to extract the archive!

Is it because there might be something wrong with the tar file, but not when it was compressed by pbzip2? If so, is there a way to check the tar file itself? If not, what other problem might this be? Also, are there ways to recover data from tar files with errors?

I am afraid I might have already lost some important data through this process...

The point is, I would like to know a method to test the integrity of my archives after they are created.

  • 2
    Try uncompressing with normal bunzip2 instead of pbzip2. Also there are alternative programs for tar such as 'star' or Winrar – golimar Apr 19 '12 at 14:45
  • 3
    Please post the commands you are running. Did you pass --use-compress-prog=pbzip2 when doing the extraction? – Mikel Apr 19 '12 at 14:50
  • Hello. I just like to know a way to test the integrity of a tar archive after it has been created and compress via bzip2. – hpy Apr 19 '12 at 23:44

First test bzip2 compression, It should output OK.

bzip2 -tv FILE.tar.bz2

Next uncompress the tarball, to get just the tar.

bunzip2 FILE.tar.bz2

Finally verify the tar file,

tar -tvfW FILE.tar

Truthfully the best indicator of a problem, is a failed extraction. Hopefully you can narrow down the cause. I should also mention..., I have had the occasional archive fail verification, yet still correctly extract.

  • 2
    Very glad I was able to point you towards your path! – J. M. Becker Apr 20 '12 at 19:22
  • sadly bzip2 -tv takes about as long as decompression, I wish there was a way to test possibly truncated files faster – user30750 Jan 21 '13 at 15:07
  • 1
    Instead of extracting the .tar.bz2 file, you can also use tar's -j switch in addition to tvfW, which (in sufficiently recent version) can directly read bzip2 files – Tobias Kienzler Oct 30 '13 at 9:25
  • @TobiasKienzler, you're absolutely correct about using tar options together, it's faster, and it was also my first thought.... But considering the OP was being somewhat 'unconventional' with his compression options, I thought it may be best to additionally verify the bzip2 compression. As combining the options would specifically verify the tar, decompressing the bzip2, hence pre-assuming its compression was already valid. – J. M. Becker Nov 4 '13 at 23:57
  • @TobiasKienzler, but yea if it's just the tar itself in question, the extra step is unnecessary. So I +1'd your comment, as it's normally the prefered action. – J. M. Becker Nov 5 '13 at 0:00

In addition to the solutions above, you always can use pipes with tar:

pbzip2 -dc FILE.tar.bz2 | tar -tvfW -
  • 1
    why the downvote? Please explain... – sekmo Apr 20 '16 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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