Backup Verification
Test and validate backup integrity.
Quick Verification
# Check backup exists
ls -la /backup/latest*
# Check backup size (not zero)
du -sh /backup/*
# Check backup timestamp
stat /backup/latest.tar.gzFile Backup Verification
Verify Archive Integrity
# Test tar archive
tar -tzf backup.tar.gz > /dev/null && echo "OK" || echo "FAILED"
# List contents
tar -tzf backup.tar.gz | head -20
# Verify with checksum
md5sum backup.tar.gz
sha256sum backup.tar.gz
# Compare with stored checksum
sha256sum -c backup.sha256Test Restore
# Extract to test directory
mkdir -p /tmp/restore-test
tar -xzf backup.tar.gz -C /tmp/restore-test
# Compare with original
diff -r /original/path /tmp/restore-test/path
# Cleanup
rm -rf /tmp/restore-testDatabase Backup Verification
PostgreSQL
# Verify dump file
pg_restore --list backup.dump
# Test restore to temp database
createdb test_restore
pg_restore -d test_restore backup.dump
# Verify data
psql test_restore -c "SELECT count(*) FROM important_table;"
# Cleanup
dropdb test_restoreMySQL
# Verify dump syntax
head -100 backup.sql
tail -10 backup.sql # Should end properly
# Test restore
mysql -e "CREATE DATABASE test_restore;"
mysql test_restore < backup.sql
# Verify
mysql test_restore -e "SELECT count(*) FROM important_table;"
# Cleanup
mysql -e "DROP DATABASE test_restore;"Automated Verification Script
#!/bin/bash
BACKUP_DIR="/backup"
DATE=$(date +%Y-%m-%d)
LOG="/var/log/backup-verify.log"
echo "=== Backup Verification $DATE ===" | tee -a $LOG
# Check recent backup exists
LATEST=$(ls -t $BACKUP_DIR/*.tar.gz 2>/dev/null | head -1)
if [ -z "$LATEST" ]; then
echo "FAIL: No backup found" | tee -a $LOG
exit 1
fi
# Check backup age (less than 24 hours)
AGE=$(($(date +%s) - $(stat -c %Y "$LATEST")))
if [ $AGE -gt 86400 ]; then
echo "WARN: Backup is more than 24 hours old" | tee -a $LOG
fi
# Check backup size
SIZE=$(stat -c %s "$LATEST")
if [ $SIZE -lt 1000 ]; then
echo "FAIL: Backup too small" | tee -a $LOG
exit 1
fi
# Test archive integrity
if tar -tzf "$LATEST" > /dev/null 2>&1; then
echo "OK: Archive integrity verified" | tee -a $LOG
else
echo "FAIL: Archive corrupted" | tee -a $LOG
exit 1
fi
echo "OK: Backup verification passed" | tee -a $LOGCloud Backup Verification
AWS S3
# List recent backups
aws s3 ls s3://bucket/backups/ --recursive | tail -10
# Check object exists
aws s3api head-object --bucket bucket --key backups/latest.tar.gz
# Download and verify
aws s3 cp s3://bucket/backups/latest.tar.gz /tmp/
tar -tzf /tmp/latest.tar.gz > /dev/null && echo "OK"Restic
# Check repository
restic check
# List snapshots
restic snapshots
# Verify snapshot
restic check --read-data
# Test restore
restic restore latest --target /tmp/restore-testVerification Checklist
| Check | Command | Expected |
|---|---|---|
| Backup exists | ls -la |
Recent file |
| Size reasonable | du -sh |
> expected size |
| Not corrupted | tar -tzf |
Exit code 0 |
| Can restore | Test restore | Data matches |
| Offsite copy | Check remote | Matches local |
Verification Schedule
# Add to crontab
# Daily quick check
0 8 * * * /usr/local/bin/backup-verify.sh
# Weekly full restore test
0 2 * * 0 /usr/local/bin/backup-restore-test.sh - backup
- verification
- testing
- disaster recovery
- integrity