能否从已上传80%的不完整tar.gz文件中提取数据?
Hey HarveyP, sorry to hear about your hard drive failure—total bummer when critical files go missing like that. Let’s break down your situation and walk through what you can do to recover as much data as possible from that incomplete tar.gz.
The short answer: Yes, often you can recover at least some data, depending on where the file cut off. Tar.gz files are a combination of a tar archive (which bundles files) and gzip compression (which shrinks the bundle). Gzip is a streaming compressor, meaning it can decompress up to the point of corruption, and tar can then extract any intact files from that partial decompressed stream.
Step 1: Try Direct Extraction with Tar
Start with the simplest approach—just try extracting the file with tar, telling it to ignore read failures:
tar -xzf incomplete_backup.tar.gz --ignore-failed-read
If that throws errors, split the decompression and extraction steps to get more control:
# Decompress as much as possible to a partial tar file gzip -dc incomplete_backup.tar.gz > partial_backup.tar # Now extract from the partial tar tar -xf partial_backup.tar
Tar will skip over any corrupted or incomplete files in the archive and extract everything it can successfully read.
Step 2: Use Specialized Recovery Tools
If the basic method doesn’t pull out as much as you hoped, try these tools:
tar_recover: Many Linux/Unix systems include this utility specifically for damaged tar archives. It scans the file and attempts to salvage individual files even if parts of the archive are missing. Run it like this:tar_recover partial_backup.tar ./recovered_files/- Manual truncation (if you know the intact size): If you have a rough idea of how much of the file was successfully uploaded (e.g., full backup was 10GB and you have 8GB), use
ddto truncate the file to that size before decompressing to avoid some corruption errors:dd if=incomplete_backup.tar.gz of=truncated_backup.gz bs=1G count=8 gzip -dc truncated_backup.gz > truncated_backup.tar tar -xf truncated_backup.tar
Key Things to Keep in Mind
- Work on copies, not the original: Always make a duplicate of your incomplete tar.gz before trying any operations—you don’t want to accidentally damage the only copy you have.
- Recovery depends on where the cut happened: If the missing 20% is at the end of the file, you’ll likely recover almost all your data (only the last few files in the archive might be corrupted or missing). If the cut is in the middle, you’ll lose files stored in that section, but everything before the cut should still be recoverable.
- If it was split into multiple parts: If you were uploading split tar.gz volumes (e.g.,
backup.part1.tar.gz,backup.part2.tar.gz), first combine all the parts you have:
Then follow the extraction steps above on the combined file.cat backup.part*.tar.gz > combined_backup.tar.gz
内容的提问来源于stack exchange,提问作者HarveyP

