Interview Prep/Shell Scripting/Scenarios: backups, log rotation and housekeeping

Backups have "succeeded" every night for a year, but the first real restore failed. How do you make backups trustworthy?

AdvancedScenarioScenarios: backups, log rotation and housekeeping
Answer

Situation read → Nobody tested restores, so "success" only meant "the script exited 0".

What I'd do →

  1. Add an automated restore test on a schedule (weekly), in an isolated environment:
    latest=$(aws s3 ls "s3://$BUCKET/pg/" | sort | tail -n1 | awk '{print $4}')
    aws s3 cp "s3://$BUCKET/pg/$latest" /restore/
    createdb restore_test && gunzip -c "/restore/$latest" | psql -v ON_ERROR_STOP=1 -q restore_test
    psql -tAc 'select count(*) from orders' restore_test   # compare with production metrics
    
  2. Assert on content: row counts within a tolerance, the latest record's timestamp is recent, critical tables exist.
  3. Verify checksums of archives before restoring, and alert if the newest backup is older than 26 hours.
  4. Record restore duration as a metric; that is your real RTO.
  5. Document the restore runbook and rehearse it.

Why → A backup you have not restored is a hypothesis, not a backup.

Interview tip → Use "RTO and RPO" and say restore tests produce the evidence for both.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: backups, log rotation and housekeeping