Skip to content
Snapshots & recovery

Snapshots & recovery

A snapshot is one archive containing every instance’s data and oddk’s own configuration. It is what a host migration or a disaster recovery restores from.

oddk snapshot make                      # capture everything, now
oddk snapshot setup-cron --utc-hour 3   # every night at 03:00 UTC
oddk snapshot list                      # what exists, and where the copies are

Physical by default

Running instances are captured with pg_basebackup over the replication protocol — fast, no locks, no long transaction. Stopped instances are captured as a cold file copy of the data directory, which is a real, restorable capture.

Physical restores are byte-for-byte, so per-database GUCs, database-level ACLs and ICU collations all survive.

Use --logical for a portable pg_dump-based archive when you need to cross CPU architectures, or when unlogged tables must survive the restore.

Configure offsite copies

Create a bucket in S3 or your S3-compatible storage, with credentials that can list the bucket and upload, download and delete objects under your chosen prefix. Give each deployment its own bucket or prefix so their retention jobs do not share a destination.

Allow s3:AbortMultipartUpload on the archive prefix so failed or canceled uploads can clean up their uploaded parts. Configure a bucket lifecycle rule to abort incomplete multipart uploads left by a daemon crash or loss of connectivity. For SSE-KMS buckets, the upload identity also needs kms:Decrypt and kms:GenerateDataKey on the encryption key.

On the oddk server, export the configuration template to a private file:

(umask 077; oddk offsite get > offsite.json)

Edit offsite.json. The configuration is one JSON object:

{
  "type": "s3",
  "bucket": "my-backup-bucket",
  "endpoint": "",
  "region": "us-east-1",
  "accessKeyId": "YOUR_ACCESS_KEY_ID",
  "secretAccessKey": "YOUR_SECRET_ACCESS_KEY",
  "bucketPath": "db01/",
  "ec2IamRole": false
}

Replace the bucket, region and credentials. Leave endpoint empty for AWS S3; for S3-compatible storage, use its endpoint URL and region. A non-empty bucketPath such as db01/ must end with / and must not begin with /. An empty path means the bucket root.

On an EC2 host using an instance role, set ec2IamRole to true and leave both access-key fields empty. When editing an existing configuration, %SAME-AS-BEFORE% keeps its stored secret.

Apply the file, then test the connection:

oddk offsite apply --file offsite.json
oddk offsite test

The test uploads, downloads and deletes a test file. After it passes, remove the local JSON file if it contains credentials you no longer need on disk.

Scheduled snapshots use this destination automatically. To prove an actual snapshot reaches the bucket, make one and find its ID:

oddk snapshot make --comment "offsite check"
oddk snapshot list

Replace 7 below with that snapshot’s ID:

oddk snapshot upload 7
oddk snapshot list-remote
oddk offsite logs --limit 50

With offsite configured, failed uploads keep their local archive past retention for retry.

Every archive is encrypted before it leaves the host, so someone who can read the bucket but does not have the master key learns nothing from it. See Encrypted at rest.

Back up the master key

The installer stores the key at /var/lib/oddk/data/master.key. If you run the daemon with a custom --data-dir, the key is inside that directory instead.

The key is not inside a snapshot, and every archive is encrypted with a key derived from it. Without it, no archive can be restored or read. Copy it to protected storage separate from this server and from its bucket, such as an encrypted recovery drive. Confirm that drive is mounted at /mnt/oddk-recovery before running these commands on the server:

sudo install -m 600 /var/lib/oddk/data/master.key \
  /mnt/oddk-recovery/db01-master.key
sudo cmp /var/lib/oddk/data/master.key \
  /mnt/oddk-recovery/db01-master.key

cmp exits successfully with no output when the copy matches. Detach the drive and store it securely. A copy left on the same server is not protection against losing that server.

Keep the source key with the recovery records for this deployment, along with its bucket, endpoint, region and a way to obtain storage credentials without the original host. A replacement host needs both an archive and the matching source key.

Retention

Choose local and offsite retention windows when setting the schedule. For example, this captures nightly at 03:00 UTC, keeping local copies for 7 days and offsite copies for 30 days:

oddk snapshot setup-cron --utc-hour 3 \
  --cleanup-local-days 7 --cleanup-remote-days 30

Retention preserves the newest two surviving copies in each location, even past their age limit. The newest complete archive is also protected for that location’s retention window plus 30 days. That extra protection expires; address incomplete captures reported by oddk checklist rather than relying on an old complete archive indefinitely.

Restore one instance

The rest of the deployment stays up.

oddk snapshot restore-instance --instance app --id 7

Restore one database

restore-database creates one database on a running instance and changes nothing else: the other databases, roles, postgres password and configuration stay as they were, and the instance keeps serving. The target name must be free, so use --restore-as to put yesterday’s copy next to today’s:

oddk snapshot restore-database --instance app \
  --database sales --id 7 --restore-as sales_copy

--from-instance reads another instance’s copy, for example last night’s production database onto staging. The target must run a PostgreSQL major at least as new as the copy in the snapshot:

oddk snapshot restore-database --instance staging \
  --from-instance prod --database sales --id 7

Objects come back owned by postgres, without object privileges.

A physical snapshot has no per-database dumps, so oddk first starts the instance’s copy as a temporary cluster, dumps the one database out of it, and then removes the cluster and its volume. That cluster has no network access and runs no background workers, so subscriptions, foreign servers and scheduled jobs in the copy cannot reach real systems or change it before it is dumped. It needs free disk for the whole instance while it runs, and unlogged tables come back empty.

Rebuild a whole host

On an empty replacement host, install oddk with Docker running. Use the same CPU architecture for a physical snapshot. The new host can be smaller than the old one: an instance recorded with more CPU or RAM than this host has is restored at what the host provides, memory-based settings follow, and preflight lists each instance it sized down. A parameter group that sets memory explicitly, such as a fixed shared_buffers, must fit the smaller size; preflight checks it before anything changes.

Retrieve your archive from the bucket and your separately saved source key. Place them at the paths below, readable by the oddk user; that user also needs permission to traverse their parent directories. Keep the key private.

Stop the newly installed service, then apply. This runs locally against the data directory, so recovery works even when the daemon cannot start:

sudo systemctl stop oddk
sudo -u oddk oddk snapshot apply \
      --file /mnt/restore/snapshot-db01-20261017.tar.zst.age \
      --master-key /mnt/restore/master.key
sudo systemctl start oddk
Use the source host’s key, not the key created by the fresh installation. Apply checks it before anything else; a wrong key is refused, and the error names the key the archive needs. Do not delete the new host’s key by hand; apply replaces it and preserves the previous one.

Apply pauses every restored schedule, because the archive carries the source host’s offsite settings — an unpaused restore would upload into that bucket and run retention against it. Resume deliberately, once this host owns its bucket:

oddk snapshot setup-cron --resume

On a rehearsal host, keep schedules paused or configure a separate offsite destination before resuming. If the snapshot also contains per-instance backup schedules, resume each deliberately with oddk backup setup-cron --instance NAME --resume.

Check the result and test notification delivery:

oddk list
oddk checklist
oddk notify test

Every archive is verified

Archives are fsynced, read back, and structurally asserted before being catalogued — and verified again on download, before anything is allowed to depend on them. A corrupt archive is refused rather than silently restored.

The catalogue also records each archive’s SHA-256, the value sha256sum prints; oddk snapshot list --json shows it as sha256. Downloading a catalogued archive, or restoring one by --id, checks the copy against it, so an archive that is intact but not the one this host wrote — an object replaced in the bucket, say — is refused. Archives fetched with --s3-uri have no catalogue entry and are not checked this way.

Check stored copies

A copy can go bad while nobody is looking at it: bit rot on the backup disk, an object changed in the bucket. snapshot verify finds that before a restore depends on the archive:

oddk snapshot verify 7              # one snapshot
oddk snapshot verify --all          # every catalogued snapshot
oddk snapshot verify --all --deep   # also download every S3 copy

Local copies are read in full and compared with the recorded SHA-256. S3 copies are checked for existence and size; --deep downloads them and verifies them the same way, without writing them to disk. Any copy that is missing, damaged, replaced or could not be checked makes the command exit non-zero, so it can run from cron; --json reports each copy. It does not wait for a running snapshot.

Encrypted at rest

Every archive oddk writes ends in .tar.zst.age: it is encrypted with age, using a post-quantum hybrid key (ML-KEM-768 + X25519) derived from the master key. There is nothing to turn on and no second key to manage. Restores on the same host use its key; apply and restores of another deployment’s archive take that deployment’s key with --master-key.

Someone who can read the backup directory or the bucket, but does not have the master key, learns nothing about the contents: not your data, not the role password hashes, not even the instance names. Every 64 KiB of an archive is authenticated, so a changed or truncated file is refused before anything is extracted.

Read an archive without oddk running

snapshot decrypt writes the plain .tar.zst next to the archive. It verifies the archive first, writes the file with mode 0600, never overwrites, and needs no daemon:

oddk snapshot decrypt --master-key master.key \
  --file snapshot-db01-20261017030000.tar.zst.age

To decrypt with the stock age command instead, on a machine without oddk, print the age secret derived from the key. It is as sensitive as the master key, so run this with umask 077 and delete both files when you are done:

(umask 077
 oddk snapshot decrypt --master-key master.key \
   --print-age-identity > identity.txt
 age -d -i identity.txt -o snapshot.tar.zst \
   snapshot-db01-20261017030000.tar.zst.age)