Chapter 12: Backup & Restore
Learning Objectives
By the end of this chapter, you will be able to:
- Explain why PostgreSQL, and why an operator (CloudNativePG) to run it on Kubernetes
- Tell a base backup from the WAL archive, and what each one gives a restore
- Restore a database to a point in time before a bad change - into a new cluster, never over the old one
- Prove a restore with data and the application’s own credentials, not with
Ready, and measure how long it took - Name the signals that say a backup has stopped working, before you need it
Recall Check
Before continuing, quickly recall:
developis default-deny. What does a new pod need before it can open any connection? (Chapter 06)- The resource quota of
developis nearly full. What happens to a new pod that does not fit? (Chapter 08) - When should an alert fire - and when must it stay silent? (Chapter 11)
If you can’t answer these, revisit the corresponding chapter before proceeding.
Context
Chapter 11 made sure someone hears when users fail. This chapter is about the one failure no rollback undoes: data that is gone. A release can be rolled back to the previous image; a DELETE cannot be rolled back to the previous rows. Only a restore brings them back - and a restore is a procedure you either practised before the incident, or learn during it.
So the chapter holds one bar: a backup that was never restored is a hope, not a backup. A green backup job proves that files were written somewhere. It does not prove that they can become a database again, to the moment you need, in a time the business can live with, reachable by the application.
Work through each lesson section; the chapter video, once it is published, gives the concept overview.
Why PostgreSQL, and Why CloudNativePG
Not every reader runs PostgreSQL, and fewer run it on Kubernetes. The platform’s choice, and why:
PostgreSQL, the database:
- Proven and open. Decades in production, a large community, no licence fees and no vendor that can change the terms. The same database runs on a laptop and on every cloud - which matters for a platform that runs on all of them.
- Correct by design. Transactions (ACID), constraints and a strict type system: a transaction that fails rolls back everything it changed. Related changes are atomic only when they run in one transaction - separate statements commit one by one.
- The write-ahead log (WAL). Every change is written to the WAL before it is applied. That one design gives replication and point-in-time recovery: replay the log up to the second you choose.
- Broad enough to stay. Relational data, JSON, full-text search and many extensions in one engine - one database to operate instead of three.
CloudNativePG, the operator:
- A database as a declared object. A
Clusterin Git says how many instances, which version, where backups go; the operator makes it so and keeps it so - the same GitOps loop as every app (Chapter 03). - Operations as code, not as scripts. Failover, replicas, rolling upgrades, the WAL archive, scheduled backups and restore are built in - not shell scripts someone has to remember.
- Kubernetes-native, no external dependency. It needs no managed database service and no sidecar from a vendor; it works on kind and on the cloud cluster alike (provider agnosticism). Credentials are Secrets, metrics are Prometheus metrics.
- Open source (a CNCF project) - the same trade-off as PostgreSQL itself.
What it costs. You operate the database yourself: storage, upgrades, backups and restores are your team’s job, not a provider’s. A managed service (Cloud SQL, RDS) takes that work - and ties you to that cloud. Other operators exist (Zalando’s, Crunchy’s); CloudNativePG was chosen for its declarative model and its built-in backup and restore. With fewer people than the work needs, a managed database is the honest answer.