Skip to content

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.

  • The name of the D1 database, or the URL of the Postgres database. D1 shows where the name goes.
  • The secret of the API at the time of the backup. Keep it beside the backup, in a secret store. Secrets tells what it opens.
  1. On D1, note that Time Travel is always on. It goes back 30 days on Workers Paid, and 7 days on Workers Free.
  2. Read the bookmark of a time before the fault. The command prints it.
Terminal window
pnpm --filter my-app exec wrangler d1 time-travel info my-app --timestamp="2026-10-14T09:00:00+00:00"
  1. Restore the database to that bookmark.
Terminal window
pnpm --filter my-app exec wrangler d1 time-travel restore my-app --bookmark="$BOOKMARK"
  1. For a copy outside Cloudflare, export the database to a SQL file.
Terminal window
pnpm --filter my-app exec wrangler d1 export my-app --remote --output=./my-app.sql
  1. On Postgres, dump the database in the custom format, and restore it with pg_restore.
Terminal window
pg_dump -Fc -f my-app.dump "$DATABASE_URL"
pg_restore -d "$RESTORE_URL" my-app.dump
  1. After a restore, delete every session row, because a restore brings back sessions that ended.
Terminal window
pnpm --filter my-app exec wrangler d1 execute my-app --remote --command "DELETE FROM ta_session"
psql "$DATABASE_URL" -c "DELETE FROM ta_session"
  1. With the compatibility package, delete the rows of the table session instead.
  2. Run auth.api.sweepExpired() once.

The table prefix ta_ keeps the old product name tempo-auth for compatibility. Schema and migrations states the rule.

  • A D1 restore overwrites the database in place.
  • A D1 export blocks the other requests to the database while it runs.
  • pg_dump makes 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 secret of its time.
  • Every second factor fails after a restore: the API runs with another secret than the backup. Use the secret of the backup’s time.
  • Every route answers 500 after a restore: the backup is from an older schema version. Apply the migrations again.
  • invalid_token for a link: the restore removed the row of a link that was sent after the backup.