Backups
Back up the two volumes a self-hosted twins server needs, and restore them on each install.
Back up the two volumes a self-hosted twins server needs, and restore them on each install.
Keep
records (Postgres) and worlds (SQLite files)
Runs on
Docker Compose · Helm chart · AWS · Google Cloud · Azure
Can lose
About a second of worlds with replication. Up to a day without it.
Watch out
A file-by-file copy (cp, rsync, AWS Backup of EFS) is not safe while the server runs
What to keep
Two volumes hold everything:
records
Postgres: people, keys and the record of what each did.
worlds
Every world's data, as SQLite files.
Back up both. The cache holds nothing that outlives a restart.
Backups by install
Snapshot the host's disk. Or stop the server, copy the worlds volume, and take a pg_dump of the database:
docker compose -f deploy/docker-compose.selfhost.yml stop worldsStart it again with docker compose -f deploy/docker-compose.selfhost.yml up -d worlds once the copy is done.
worlds.replication streams every world to an S3 bucket as it is written. A server on an empty volume restores them before it serves. See Replicate worlds to S3.
Or snapshot the volume with the cluster's CSI driver.
Back up the database too: the bundled Postgres's volume, or your managed database's own backups.
The module backs up both on its own:
Worlds' copies in S3 (
replication, on by default). The server runs Litestream, which follows each database's write-ahead log and sends what each transaction changed, with a snapshot of each database a day. A restore to a time puts every database back as it stood then. The bucket keeps what Litestream replaces or deletes a week longer (versioning), as Litestream's S3 guide advises.AWS Backup of the EFS file system (
backup), daily, kept 35 days. It reaches further back than the copies, for a loss noticed late.RDS automated backups: any point in the last
db_backup_retention_days(35 by default).
Backup for GKE, nightly, when Cloud SQL's daily backup starts: twins' namespace with the worlds' disk. Kept
backup_retain_days(14 by default).Cloud SQL:
postgres_backup_countdaily backups with a week of point-in-time recovery.
Azure Backup for AKS, nightly at 22:00 UTC: twins' namespace with the worlds' disk and its volume. Kept
backup_retain_days(30 by default).Azure Database for PostgreSQL:
backup_retention_days(30) of point-in-time backups.
Both default to 30, so every night of one has the other beside it. Keep them equal.
Safe and unsafe copies
A snapshot of a whole block volume: a disk snapshot, Backup for GKE's or Azure Backup's of the disk, a CSI VolumeSnapshot, an EBS, Persistent Disk or Azure Disk snapshot
Yes
It is taken at one instant. SQLite restores it as it would after a power cut.
A copy made file by file: cp, rsync, AWS Backup of EFS
No
Files copied at different moments may not agree.
Litestream copies (worlds.replication, AWS replication)
Yes
A copy is always one the database itself could have been at.
AWS says of EFS backups: "inconsistencies ... can occur if you make modifications to your file system while the backup is occurring" (EFS: backing up).
Take a file-by-file copy with the server stopped. Where the newest EFS backup will not open, restore an older one, or replicate the worlds as they are written.
How much can be lost, and how long a restore takes
What a failure can lose (recovery point) and how long putting things back takes (recovery time), by install. The times are typical. Measure yours with a restore drill.
Replicating (worlds.replication, AWS replication)
About a second: Litestream sends every second
The provider's log backup (RDS: five minutes)
Minutes: a server on an empty disk restores each world as it is first opened
The provider's point-in-time restore
AWS without replication
Up to a day: AWS Backup of EFS, daily
Five minutes (RDS)
Minutes to an hour: restore the recovery point, then the restore task
RDS point-in-time restore
GKE, AKS without replication
Up to a day: the nightly disk backup
Cloud SQL's or Azure's own
Restore the backup of the namespace and its disk
The provider's point-in-time restore
Compose, or the chart's own Postgres
Since your last snapshot of the volume
Since your last pg_dump
Copy the volume back
pg_restore
Before every upgrade that migrates, the server also dumps the records. Going back from an upgrade loses nothing written before it. See Upgrades.
Restoring
Always stop the twins server first, so nothing writes while things are put back. Restore the records and the worlds to the same time.
Stop the server:
docker compose -f deploy/docker-compose.selfhost.yml stop worlds.Copy the
worldsvolume back from your snapshot.Restore the database with
pg_restore:Start the server:
docker compose -f deploy/docker-compose.selfhost.yml up -d worlds.
With worlds.replication, a server on an empty volume restores every world from its copies before it serves. Watch twins_replication_restores_total rise while it works.
From a volume snapshot, restore the snapshot with your CSI driver. Restore the database from its own backup.
Put back to a time T (UTC, RFC 3339). The restore output gives the commands for the worlds.
Stop the server:
Restore the database to T, as a new instance under the old one's name, the old one kept aside (point-in-time recovery):
Point Terraform at the new instance, without applying yet (an apply now would start the server):
Restore the worlds to T with the restore task. It refuses to start while the server holds its lock. It puts every database back into a place of its own, checks each with
PRAGMA integrity_check, and only then moves them in. It keeps what the root held under/twins-restore/before-<run>on EFS.From the copies: run it as the
restoreoutput shows, withRESTORE_TIMESTAMP=<T>. A database that did not exist at T, or whose copies do not reach back to T, stops the restore.RESTORE_ALLOW_MISSING=trueleaves those out. WithoutRESTORE_TIMESTAMP, it restores the copies' latest.From AWS Backup: restore the file system's recovery point from before T to the same file system (restoring EFS). Then run the restore task with
RESTORE_FROM=backup.
RESTORE_CHECK_ONLY=truestops after the check, the root untouched.Start the server:
terraform apply. When only the worlds were put back,aws ecs update-service ... --desired-count 1./readyanswers 200 once the server holds its lock.Clean up once the install is checked: delete
<name>-before-restore(turn its deletion protection off first) and the root's old contents. AWS Backup'saws-backup-restore_<time>directory is billed as storage until removed.
Postgres and the worlds' disk go back together, to one moment: a nightly Backup for GKE backup, and Cloud SQL recovered to the time it was taken. Point-in-time recovery reaches back 7 days. With P the project, R the region, N the module's name and T the backup's time:
Pick the backup and note its
completeTimeasT:Stop the twins server:
kubectl -n twins scale statefulset/twins-worlds --replicas=0.Recover Cloud SQL to
T, as a new instance:Restore the worlds' disk with the restore plan, leaving the cluster's Secrets as they are. Write
filter.yaml:Then:
Wait for
gcloud beta container backup-restore restores describe restore-1 --project P --location R --restore-plan N-twins-restoreto saySUCCEEDED.Hand the clone to the module. Take the old instance out of the state:
Import the clone in its place:
Set
postgres_instance_name = "N-pg-restored"on the module, then runterraform apply.Start the twins server:
kubectl -n twins scale statefulset/twins-worlds --replicas=1, then checkkubectl -n twins rollout status statefulset/twins-worlds.Once it is right, remove the import blocks and delete the old instance:
gcloud sql instances patch N-pg --no-deletion-protection --project P, thengcloud sql instances delete N-pg --project P.
A restore puts both stores back to the same moment T, the time of the disk's restore point. Microsoft's guides: Postgres point-in-time restore, restore AKS from Azure Backup.
Pick the restore point: Azure portal, Resiliency, the backup instance
<name>-twins, its restore points. T is its time, in UTC.Stop the twins server:
kubectl -n twins scale statefulset/twins-worlds --replicas=0.Restore Postgres to T, as a new server in the same subnet and private DNS zone:
Move Terraform onto the new server:
Set
postgres_server_name = "<new-server>"on the module, then runterraform apply -target=module.azure. The old server stays, locked, until you check the new one.Remove the worlds' claim and volume, keeping the disk until the restore is checked:
Restore from Azure Backup for AKS: Resiliency, Recover, the backup instance, the restore point from step 1, the original cluster, namespace
twins, persistent volumes included, conflicts left on Skip (the default).Run
terraform apply, thenkubectl -n twins scale statefulset/twins-worlds --replicas=1. Check it serves, then delete the retained old disk from the node resource group.
Common problems
One world will not open after a restore
See TwinsRestoreRefused in Monitoring.
The newest EFS backup will not open
Restore an older one, or replicate the worlds as they are written.
Next
Monitoring: alerts for the copies, the lease and the volume.
Upgrades: the dump the server takes before it migrates.
Last updated: 27 October 2026
Was this helpful?