Skip to content

Backups & restore

The PDS keeps everything in one SQLite database, so backing it up is your disaster-recovery plan. Custos uses Litestream to stream that database to object storage continuously and restore it on boot.

When the Litestream environment variables are set, the container runs the PDS under Litestream: it streams the SQLite write-ahead log to your bucket as writes happen (not a nightly snapshot — a continuous replica), and on boot it restores from that replica if the local database is missing. So a current restore point always exists.

The replica is defined in litestream.yml (committed in the repo) with force-path-style: false — virtual-hosted-style addressing, which Railway/Tigris-style buckets require.

Set these on the environment you want backed up (production; staging and local leave them unset and run the PDS directly):

VariableRole
LITESTREAM_S3_BUCKETThe bucket the replica is written to. Setting this is what switches Litestream on.
LITESTREAM_S3_ENDPOINTObject-storage endpoint (e.g. your Tigris/S3-compatible host).
LITESTREAM_ACCESS_KEY_IDAccess key for the bucket.
LITESTREAM_SECRET_ACCESS_KEYSecret key for the bucket.

To restore the database from the replica:

Terminal window
litestream restore <path-to-db>

Litestream pulls the latest state (or a point in time) from the bucket. On a fresh container the PDS does this automatically on boot when the local database is absent.

Schema migrations are forward-only — there is no down-path. Redeploying an earlier vX.Y.Z tag is safe only when the schema change was backward-compatible. If it wasn’t, roll back by restoring the database from the Litestream replica to a point before the promote, rather than by redeploying old code against a newer schema.