Backups
For: an operator who must restore the data of an API with authtempo after a fault.
What it does: this guide makes a backup on each database, restores it, and secures what the restore brings back.
Before you start
Section titled “Before you start”- The name of the D1 database, or the URL of the Postgres database. D1 shows where the name goes.
- The
secretof the API at the time of the backup. Keep it beside the backup, in a secret store. Secrets tells what it opens.
- On D1, note that Time Travel is always on. It goes back 30 days on Workers Paid, and 7 days on Workers Free.
- Read the bookmark of a time before the fault. The command prints it.
pnpm --filter my-app exec wrangler d1 time-travel info my-app --timestamp="2026-10-14T09:00:00+00:00"- Restore the database to that bookmark.
pnpm --filter my-app exec wrangler d1 time-travel restore my-app --bookmark="$BOOKMARK"- For a copy outside Cloudflare, export the database to a SQL file.
pnpm --filter my-app exec wrangler d1 export my-app --remote --output=./my-app.sql- On Postgres, dump the database in the custom format, and restore it with
pg_restore.
pg_dump -Fc -f my-app.dump "$DATABASE_URL"pg_restore -d "$RESTORE_URL" my-app.dump- After a restore, delete every session row, because a restore brings back sessions that ended.
pnpm --filter my-app exec wrangler d1 execute my-app --remote --command "DELETE FROM ta_session"psql "$DATABASE_URL" -c "DELETE FROM ta_session"- With the compatibility package, delete the rows of the table
sessioninstead. - Run
auth.api.sweepExpired()once.
The table prefix ta_ keeps the old product name tempo-auth for compatibility. Schema and migrations states the rule.
How it behaves
Section titled “How it behaves”- A D1 restore overwrites the database in place.
- A D1 export blocks the other requests to the database while it runs.
pg_dumpmakes a consistent backup while the database is in use, and blocks no reader and no writer. It dumps one database, and no role.- A restore brings back each row of its time. That includes sessions that a sign-out deleted, and API tokens that a person revoked.
- A link or a code that a person spent after the backup time is live again until its expiry.
- A restored row that holds a sealed value opens only under the
secretof its time.
If it fails
Section titled “If it fails”- Every second factor fails after a restore: the API runs with another
secretthan the backup. Use thesecretof the backup’s time. - Every route answers 500 after a restore: the backup is from an older schema version. Apply the migrations again.
invalid_tokenfor a link: the restore removed the row of a link that was sent after the backup.