Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
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
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
    
I think I get it now, thank you! –  hpy Apr 20 '12 at 16:49
2  
Very glad I was able to point you towards your path! –  TechZilla 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 –  qarma 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. –  TechZilla Nov 4 '13 at 23:57
show 2 more comments

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.