Module 6 · Reliability and infrastructureLesson 67 of 886 minBeginner

Backups

Replicas protect you from machines failing. Backups protect you from people, bugs and attackers, by letting you go back in time.

Try it

Watch the replica copy a disastrous delete, then compare a nightly backup with point-in-time restore. Finally see the untested backup.

Things that destroy data:

  • hardware failure,
  • bugs that write bad data,
  • mistakes: a DELETE without a WHERE,
  • attackers and ransomware,
  • a cloud account being closed or compromised.

Replication only helps with the first one. For the rest, you need backups.

Kinds of backup

  • Full backup: a complete copy, often nightly. Simple, but restoring loses everything since.
  • Incremental / differential: only what changed since the last backup. Smaller and faster to take.
  • Continuous (log) backup: ship the database's write-ahead log to storage as it's written. Combined with a base backup, you get point-in-time recovery (PITR): restore to any moment, like one minute before the mistake.
  • Snapshots: fast copies of whole disks or volumes, great for quick restores.

Managed databases (RDS, Cloud SQL) offer PITR with a few clicks. Turn it on.

The 3-2-1 rule

  • 3 copies of your data,
  • on 2 different types of storage,
  • with 1 copy off-site (another region, ideally another account).

Add immutability (backups that can't be deleted for N days) to protect against ransomware and compromised credentials.

Test your restores

Backups fail silently: a job that stopped months ago, a missing encryption key, a corrupted file. Restore regularly into a test environment and check the data. Measure how long it takes; that's part of your RTO.

Retention

Keep daily backups for a few weeks, weekly for a few months, monthly for longer, depending on legal and business needs. And remember privacy laws: deleted user data may need to disappear from backups too, eventually.

Quick check

Someone runs a command that deletes a table. You have two live replicas but no backups. What can you recover?