TarTips
Fix A Broken Tar File
Find the filename at first broken spot:
$ tar tvf broken.tar
Estimate position of broken spot:
$ tar tvf broken.tar | sed 's/ */ /g' | cut -d' ' -f3 | awk '{x+=$1;} END {print x;}'In subdirectory, split file into workable chunks:
$ split -b 20m ../broken.tar
Use hex editor to search for broken spot:
$ ghex2 xaa (find broken file path starting at 0x73B800 [offset1]) (find next good file path starting at 0x7AE800 [offset2])Help with hex-to-dec conversion:
$ bc ibase=16 73B800 (answer is 7583744) 7AE800 (answer is 8054784)
Get total file length:
$ ls -l xaa (size is 20971520)
Take away good head part (offset1):
$ head --bytes=7583744 < xaa > xaa1
Take away good tail part (length - offset2):
$ tail --bytes=12916736 < xaa > xaa2
Recombine head and tail, leaving out broken file:
$ cat xaa1 xaa2 > xaa
Remove working files:
$ rm xaa1 xaa2
Recombine all the parts:
$ cat `ls -1` > ../fixed.tar
