Upgrades and backups
Upgrading
Karta is pre-release: there are no tagged releases or upgrade notes yet,
and only master receives fixes. Read CHANGELOG.md before you upgrade.
- Build the new image.
- Run the migrations with the new image and the production environment:
/app/bin/migrate. - Replace the running containers.
What makes a restart safe:
- SMTP clients that are in the middle of a message when a node stops
get
421 4.3.2 Service shutting downand retry later; an acknowledged message is always stored. - Delivery jobs are in Postgres. A job interrupted by a stop is rescued by Oban after 60 minutes and run again; a recipient whose SMTP transaction finished but whose outcome was not yet written may receive the message twice (at most once more).
- The sweep (every 15 minutes) queues delivery again for any recipient that is still waiting but has no job.
To roll back a migration from a release:
/app/bin/karta eval 'Karta.Release.rollback(Karta.Repo, 20261112000000)'
(Karta.Release.rollback/2 migrates down to the given version.)
Backups
A complete backup has three parts that only work together:
| Part | Contents | Notes |
|---|---|---|
| Postgres | everything except message bodies | use your usual dumps or replication |
| The bucket | encrypted message bodies | object storage versioning or replication |
| The vault key(s) | KARTA_VAULT_KEY and any retired keys | without them the bucket and the DKIM keys are unreadable |
- Bodies in the bucket are useless without the vault key that encrypted them; database rows without their bodies can still be listed but not delivered or read.
- Restore the database and the bucket from the same moment where you can. A queued message whose body is missing fails to deliver with "the stored message could not be read" (a temporary failure, retried until the 5-day retry period ends); an object without a row is never removed by Karta.
- Restore the database before you start Karta, and run
/app/bin/migrateif the backup is from an older version.
Step by step
Take the three parts at about the same time. With pg_dump and any S3 tool
(rclone, aws s3, mc); names and addresses are examples:
# 1. The database (custom format restores selectively and in parallel)
pg_dump --format=custom --file=karta-$(date -u +%F).dump "$DIRECT_DATABASE_URL"
# 2. The bucket of message bodies (objects named messages/<id>)
rclone sync karta-s3:karta /backups/karta-bucket --checksum
# 3. The vault keys: KARTA_VAULT_KEY and every retired key, from wherever
# they are kept (the service's environment, a secrets manager). Store them
# apart from the other two: whoever holds all three can read the mail.
Every day is enough for the database if you can live with losing the mail
accepted since; shorter if you cannot (continuous archiving). A pooled
connection (KARTA_DATABASE_POOLER) is for Karta; dump through a direct one.
To restore, on an empty database and an empty bucket:
createdb karta
pg_restore --no-owner --dbname=karta karta-2026-11-13.dump
rclone sync /backups/karta-bucket karta-s3:karta
# Start the release with the same KARTA_VAULT_KEY (and retired keys), then:
docker run --rm --env-file karta.env karta /app/bin/migrate # only if the dump is older
docker run -d --env-file karta.env -p 4000:4000 karta
Check the restore before you rely on it: sign in, open a recent message and its HTML (the bucket and the vault key work together), and send a message through the API to an address you own. Do this once on a spare machine now, not for the first time in an emergency. Messages queued at the time of the backup are delivered again after the restore (a message delivered between the backup and the failure is delivered twice); keep that in mind when restoring a server that has sent mail since.
Moving to a new database or bucket
Karta has no export or import tooling yet. Copy the database with Postgres
tools and the bucket with S3 tools (object names are messages/<id>), keep
the same vault keys, and change DATABASE_URL and KARTA_S3_*.