WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script restore-verify-tar

Verify a Tar Backup

Check an archive's checksum, list its contents, and compare a sample safely.

category Backup and Recovery shell Bash 4+ updated 2026-09-19
restoretarverifybackup
Safety notes
  • Extracts to a temporary directory only; it never writes over the original data.
  • A passing checksum proves the file is intact, not that it contains the right data.
commands involved: rm

Dependencies: tar, sha256sum, mktemp

Usage

  • Pass the .tar.gz and its optional .sha256 file.
  • The script lists the archive and extracts it into a temp directory for a spot check.

Script

#!/usr/bin/env bash
set -euo pipefail

archive="${1:-}"
[[ -f "$archive" ]] || { echo "usage: $0 ARCHIVE [CHECKSUM_FILE]" >&2; exit 1; }

if [[ -n ${2:-} ]]; then
  sha256sum -c "$2"
fi

echo "== archive contents (first 20 entries) =="
tar -tzf "$archive" | sed -n '1,20p'

tmp="$(mktemp -d)"
trap 'rm -rf -- "$tmp"' EXIT
tar -xzf "$archive" -C "$tmp"
echo "extracted to: $tmp (removed on exit)"
echo "files: $(find "$tmp" -type f | wc -l)"
du -sh "$tmp"

Example

./restore-verify-tar /mnt/backups/projects-20260924-120000.tar.gz /mnt/backups/projects-20260924-120000.tar.gz.sha256

Notes

  • Run this before you need the backup, not during an incident.
  • Extraction uses the current user’s permissions; a root-owned archive may fail to unpack cleanly.

Related scripts

Rsync Snapshot Backup

Mirror a directory to a backup target with dry-run, delete protection, and a log.

Backup and Recovery

Safe SQLite Backup

Use SQLite's online backup API to copy a live database consistently.

Backup and Recovery