Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article5 min readViews2

How to verify a tar.gz archive before extraction

How to verify tar.gz before extraction: gzip and tar commands, exit codes, and five real-world examples. Why a file list and even exit code 0 do not guarantee a backup is usable.

Comments 0

Drives in protective cases for storing backups
In this article

An archive has the expected size and opens in a file manager. This is a useful sign, but you should verify it more thoroughly before restoration. A tar.gz file has at least two levels: the gzip compressed stream and the tar archive structure inside. Verifying each level solves different tasks.

First, check gzip

This instruction is designed for GNU gzip and GNU tar in Linux. The file backup.tar.gz is an example of a fully written archive name. Before verification, ensure that the backup or copy process is complete.

gzip -t -- backup.tar.gz

The command verifies the integrity of the compressed stream without extracting the contents to a directory. Usually, a successful check does not print a detailed report; for a script, the exit code is what matters. An error must be preserved in the result, not lost due to the next command.

A large archive will be read in its entirety. Consider disk load and do not run multiple checks simultaneously on a volume that is already experiencing issues.

See what is inside

For the list of objects in tar:

tar -tzf backup.tar.gz

This is a preview, not an extraction. Verify the expected directories, names, and presence of required components. For a detailed list with metadata, use the -tvzf variant.

If the list is too large, first clarify the backup composition based on its description. Skipping output through a program that terminates after the first few lines can interrupt archive reading before the end. Such viewing must not be presented as a full verification of the entire contents.

What the test on a small stand showed

On October 2, 2026, we tested the commands in an isolated Linux environment with GNU tar 1.35 and GNU gzip 1.12. The sample archive good.tar.gz contained site/index.html and db.sql; the SQL file was a text sample, not a copy of a working database. Other variants were created from the same test data. No live customer websites or backups were used, and no file extraction was performed.

File variant

gzip -t

tar: exit code and file list

Next step

good.tar.gz: two sample files

0

0; site/index.html, db.sql

Verify the contents, then separately check the restoration.

truncated.tar.gz: last 8 bytes removed

1

2; both names appeared in time

Obtain a full copy; printed names do not cancel the error.

not-tar.gz: compressed text 2688 bytes long

0

2; no list available

Clarify the format: a raw gzip stream does not necessarily contain a tar archive.

files-only.tar.gz: only the site file

0

0; site/index.html

If the schema requires a database, locate its consistent copy.

short-text.gz: compressed text of 41 bytes

0

0; the list is empty

Do not treat zero exit codes as confirmation of the presence of expected components.

For a correct sample archive, the list looked like this:

site/index.html

db.sql

The truncated gzip file reported:

gzip: truncated.tar.gz: unexpected end of file

When reading the same file, tar first printed both names, then exited with code 2 and the following messages:

gzip: stdin: unexpected end of file

tar: Child returned status 1

tar: Error is not recoverable: exiting now

The short text in gzip provided a particularly useful counterexample: in this version, GNU tar completed without error and listed nothing. Therefore, the preliminary check criterion is successful commands plus the expected composition. Even these conditions do not yet confirm recovery suitability.

How to preserve the result, not lose the error code

In a standard interactive Bash session, save the exit code immediately after the command being checked. In the example below, the file list and errors are written to separate files in the current directory; choose unused names to avoid overwriting previous reports.

gzip -t -- backup.tar.gz 2>gzip-check-errors.txt

gzip_rc=$?

tar --list --gzip --force-local --file=backup.tar.gz >archive-files.txt 2>tar-check-errors.txt

tar_rc=$?

printf 'gzip=%s tar=%s\n' "$gzip_rc" "$tar_rc"

In this GNU tar version, the --force-local parameter treats a colon in the filename as part of the local path. A non-zero result or an unexpected file list requires parsing before extraction. If the check is included in a script with set -e, use explicit error handling via if: a simple script may terminate before the variable is assigned.

The purpose of the compressed stream check and the meaning of the result codes are described in the GNU gzip manual.

Inspecting objects without extraction is described in the GNU tar manual. These checks should be retained alongside the archive size, creation time, and expected contents.

Verify the meaning of the contents

Assume the archive is intact but contains only website files without a database. This may suffice for a static project, but not for an online store. You need to know which components are included in the accepted backup scheme and how they are synchronized in time.

Look for unexpected absolute paths, parent directory transitions, and symbolic links. Do not extract an untrusted archive with elevated privileges into the working directory. Checking the file list does not make its contents safe to execute.

What these commands do not prove

Success of gzip verification and tar reading does not guarantee database business integrity, configuration suitability, or the ability to run the application. Even a complete list of expected files does not confirm that the backup was created in a consistent state.

Separate verification of restoration in an isolated environment is required. There, application startup and control data are evaluated without sending real emails or contacting live payment services. This instruction does not perform restoration.

How to record the result

Record the archive name, its creation time, size, gzip verification result, and tar structure reading result. If a trusted checksum exists, add its comparison as a separate item. Do not label an archive as a verified restoration if you have only read the file list.

On error, save the original file and the message, then check the source and transfer process. Do not unpack a corrupted archive over a live site hoping that "core files are intact." The purpose of preliminary control is to identify the issue before restoration begins modifying live data.

Discussion 0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.