Backup and restore verification
A backup is useful only if it can restore the required data within an acceptable recovery window. Creation, integrity verification and restore validation are separate gates. A successful archive exit status proves neither that all intended files were selected nor that the application can recover from them. Define the required file set, consistency requirements, ownership/permissions, retention and recovery objectives first.
Small restore drill
In a private directory, create a known input, build a GNU tar archive with tar -cf, list with tar -tf, and extract only the archive created in the same exercise into a new empty destination with tar -xf ... -C .... -C changes the archive operation's working directory for following operands. Use cmp for expected file bytes; for a real tree, check required paths, metadata and application consistency as well. A checksum detects unexpected changes relative to a trusted digest but is not proof of recoverability or authenticity. Never extract an untrusted archive using this exercise procedure.
An active database or changing filesystem may require snapshots or application-aware backup tools. Define a recovery point objective (maximum acceptable loss of recent data) and recovery time objective (target time to resume). Keep protected copies separate from the original and periodically rehearse restoration in a disposable environment. Never restore over a real service or production path in this tutorial. Require fresh source and restore directories in each lab. Check the write of the intentionally changed restored file before testing inequality; status 1 is evidence of differing bytes, not a missing file.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Create and list a known archive
mkdir source || exit 1printf 'hello\n' > source/note.txt || exit 1tar -cf backup.tar -C source note.txt || exit 1tar -tf backup.tarExpected stdout:
note.txtThe archive contains the requested relative member.
Restore and compare bytes
mkdir source restore || exit 1printf 'hello\n' > source/note.txt || exit 1tar -cf backup.tar -C source note.txt || exit 1tar -xf backup.tar -C restore || exit 1cmp -s source/note.txt restore/note.txt || exit 1printf 'restore verified\n' Expected stdout:
restore verifiedSuccessful extraction and exact byte equality are both required here.
Reject changed restored data
mkdir source restore || exit 1printf 'hello\n' > source/note.txt || exit 1tar -cf backup.tar -C source note.txt || exit 1tar -xf backup.tar -C restore || exit 1printf 'changed\n' > restore/note.txt || exit 1cmp -s source/note.txt restore/note.txtrc=$?printf 'comparison=%s\n' "$rc"[[ $rc == 1 ]]Expected stdout:
comparison=1cmp status 1 means the files differ; other nonzero values may indicate operational errors.
Common mistakes
Listing archive names alone does not prove content. A local copy on the same disk is not a resilient backup. Check restore status and bytes independently; never overwrite the source during a restore drill.
Practice
Create two synthetic files, archive them, list the expected members, restore into a new directory and compare both files. Modify one restored file and verify comparison fails.
Next: Scheduled automation environments