Backup & restore
Data is only safe once a restore has been proven: copy it off, keep it, rehearse getting it back.
The CityScript
This is all there is to it. Change it in the editor and the city redraws.
%% B · Backup & restore
%% A backup nobody has restored is a hope. Copy off-site, lock it, and rehearse the restore every month.
%% Prices are made up for the example, to show a cost line: what a service costs, with its vendor, plan and spec.
city 48x32
district prod "Production" 3,3..13,12
district vault "Off-site vault" 18,3..45,12
district drill "Restore drill" 18,14..45,22
building db tower in prod "Primary DB"
floor db.data "Data"
room db.pg database "Postgres" port=5432
room db.wal worker "WAL-G agent"
building bucket warehouse in vault "Backup bucket"
floor bucket.daily "Backups"
room bucket.snap storage "Snapshots, 30 days"
cost 12 "Backup storage" vendor=Backblaze plan=B2 spec="2 TB, 30 days of snapshots"
room bucket.wal storage "WAL archive"
cost 3 "WAL archive" vendor=Backblaze plan=B2
floor bucket.lock "Retention"
room bucket.immutable config "Object lock"
building copy warehouse in vault "Second region"
floor copy.f "Copy"
room copy.bucket storage "Cross-region copy"
cost 12 "Second copy" vendor=Backblaze plan=B2 spec="2 TB, another region"
building restore factory in drill "Restore test"
floor restore.f "Rehearsal"
room restore.pg database "Scratch Postgres" port=5432
room restore.check worker "Integrity check"
pipeline nightly "Nightly backup" db -> [snapshot] -> [encrypt] -> [upload] -> bucket -> [replicate] -> copy
step db "The database is copied at night"
step bucket "The copy is stored in a safe bucket"
step copy "A second copy is kept in another place"
run snapshot "pg_basebackup -D /backup/$DATE -Ft -z"
run encrypt "age -r $BACKUP_RECIPIENT -o base.tar.gz.age /backup/$DATE/base.tar.gz"
run upload "aws s3 cp base.tar.gz.age s3://shop-backups/$DATE/"
pipeline drill-run "Monthly restore drill" bucket -> [fetch] -> [restore] -> [verify] -> restore
step bucket "A stored backup is taken out"
step restore "It is restored into a test database, to prove it works"
run fetch "aws s3 cp s3://shop-backups/latest/ . --recursive"
run restore "age -d -i $BACKUP_KEY base.tar.gz.age | tar -xzf - -C ./restored && pg_ctl -D ./restored start"
run verify "psql -c 'select count(*) from orders'"
link db.wal -> bucket.wal "WAL archive" variant=dashed
link restore.check -> restore.pg "verify restore" variant=dashed