Backups

How we test restores of our own backups

In this article4 sections

Backups fail quietly. The job runs every night, the log says “ok”, and nobody finds out that the archive is empty, the key is lost or the database dump is half a file until the day it is needed. The only cure is a restore drill. This is ours.

What we back up

Each night an archive is built with consistent database dumps, the site files and the configuration that is painful to recreate. It is encrypted on the server with a public key, so the private key never lives there, and then copied to storage outside the server. A status file records whether the last run worked.

That is the easy part. The drill is what makes it trustworthy.

The drill

We do this on a different machine from the server, so we prove the backup does not depend on anything that would be gone in a disaster.

  1. Download the newest copy from the off-server storage.
  2. Decrypt it with the private key, which is kept offline. If this step fails, the backup is useless, so it is the first thing we test.
  3. Read the manifest that the job wrote inside the archive and check that every expected path and database is listed.
  4. Load each database dump into a throwaway database.
  5. Compare the number of tables, and the rows in a few important tables, with production.
  6. Unpack the files and open the site from them, or at least check that the files that matter are present.
  7. Write down how long the whole thing took and anything that surprised us.
  8. Delete the scratch copy, because a restored backup is also a copy of your data.

A minimal version of step 4, for a MySQL or MariaDB dump, looks like this:

mysql -e "CREATE DATABASE restore_check"
gunzip -c appdb.sql.gz | mysql restore_check
mysql -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='restore_check'"
mysql -e "DROP DATABASE restore_check"

How often

At least every quarter, and once right after you build or change the backup job. Put it in the calendar like any other maintenance, because nobody remembers to do it on their own.

What to watch for

  • The key. Keep the private key in a password manager and in a second place, offline. A backup you cannot decrypt is not a backup.
  • Silence. Make the job write a status file or ping a monitor, and alert when it is missing or old. A job that stops running makes no noise.
  • Things outside the database. Uploads, certificates, environment files and cron jobs are easy to forget and slow to recreate.
  • Same-account storage. Provider snapshots are a good extra layer, but they live in the same account as the server. Keep one encrypted copy somewhere an attacker with your cloud login cannot reach.

The full plan, with retention and a nightly script, is in our 3-2-1 backup guide. If you would rather have someone build it and prove it works, that is what our backups and recovery service does.