Skip to content
Get started
Bastionary › Knowledge base › Operations and self-hosting

Backing up and restoring identity data: the DR drill most teams skip

By Bastionary · Operations and self-hosting

Everyone backs up the users table. Far fewer teams have ever restored it and watched what happens: users exist again, but their sessions are gone so everyone is logged out, their MFA enrollments point at devices the new records do not know about, their API keys hash to nothing, and their SSO links are severed. A backup that restores identities without the state wrapped around them does not restore access; it restores a spreadsheet of people who can no longer get in. The disaster-recovery drill most teams skip is the one that matters most.

Identity is more than the users table

The first misconception to kill is that "back up the users" means a dump of one table. A functioning identity system is a graph of interdependent state, and a restore is only successful if the graph is internally consistent at a single point in time. The pieces that must travel together include credentials, MFA enrollments, active sessions and refresh tokens, API keys, SSO and social identity links, roles and permissions, and the audit log. Restore them from mismatched points in time and you get subtle, dangerous inconsistencies.

-- The identity graph is not one table. A consistent restore needs
-- all of these captured at the SAME logical point in time.
-- users            : the people
-- credentials      : password hashes, keyed to users
-- mfa_enrollments  : TOTP secrets, WebAuthn credentials, recovery codes
-- sessions         : live sessions + refresh tokens (short-lived; may be ok to drop)
-- api_keys         : hashed secrets, scopes, per tenant
-- federated_ids    : SSO/OIDC/social subject -> user mappings
-- roles_grants     : who can do what
-- audit_log        : append-only history (must survive restore intact)

-- Snapshot consistently, not table-by-table over 20 minutes:
SELECT pg_export_snapshot();  -- pin one snapshot, dump every table against it
Take every identity table from a single consistent snapshot, not as independent dumps spread across a backup window. If the users table is captured at 02:00 and federated_ids at 02:12, a user created in between exists with no SSO link, or an SSO link points at a user who is not there. Point-in-time consistency across the whole graph is the requirement, and most ad-hoc backup scripts quietly violate it.

Decide deliberately what you do not restore

Not everything should come back. Live sessions and short-lived access tokens are arguably better dropped: forcing a re-login after a disaster is acceptable and often safer, since you do not know whether those sessions were part of the incident. But that is a decision to make on purpose, with the product consequences understood, not an accident of a backup that happened to miss the session store. Document which categories are restored, which are intentionally reset, and what the user experience is for each.

Encryption and key custody will betray a naive restore

Identity data is encrypted, and here is the trap: if your MFA secrets, recovery codes, or API-key material are encrypted with a key held in a KMS, then restoring the database into a new environment with a new key means every encrypted field is now undecryptable garbage. The backup of the data is useless without the matching key, and the key is often the thing people forget to include in the DR plan.

Your identity backup is incomplete without a tested path to the encryption keys that make it readable. Back up and version the key material (or the KMS access) alongside the data, store it with separation of duties so one compromised credential cannot grab both, and verify during the drill that the restored database actually decrypts. A perfectly preserved ciphertext you cannot decrypt is data loss wearing a costume.

The restore drill is the only real test

A backup you have never restored is a hypothesis, not a safeguard. The drill is non-negotiable: on a schedule, restore the full identity graph into an isolated environment, decrypt it with the backed-up keys, and then prove that identity actually works, that a user can log in, present MFA, validate an API key, and complete an SSO flow against the restored state. Checking that rows exist is not the test; checking that a human can authenticate is.

// A restore is "successful" only if authentication works end to end.
// Rows existing is necessary, not sufficient.
async function verifyRestore(env: RestoredEnv) {
  assert(await env.login("drill-user@example.com", TEST_PASSWORD));   // credential ok
  assert(await env.verifyTotp("drill-user@example.com", totpNow()));  // MFA secret decrypts
  assert(await env.validateApiKey(TEST_API_KEY));                     // key hash intact
  assert(await env.ssoCallback(TEST_SAML_ASSERTION));                 // federation mapping intact
  assert((await env.auditTail(10)).length === 10);                    // audit chain survived
  // Record RTO: wall-clock from backup to first successful login.
}

Know your RTO and RPO for identity specifically

Auth deserves its own recovery objectives, usually stricter than the rest of the product, because when auth is unrecovered nothing else is usable regardless of its own state. Measure the real recovery time during the drill (how long from "disaster declared" to "a user logged in") and the recovery point (how much recent identity change you would lose). New enrollments and key rotations in the gap are the data most likely to vanish, and the most frustrating to lose, because the affected users were the ones who just set up their security.

Testing an identity restore means owning the backup process, the keys, and an environment you can safely rebuild into, which is exactly the control a self-hosted auth system gives you and a black-box login provider does not: when the provider is your backup strategy, "restore" is a support ticket and a shrug. Running identity yourself, as teams do with Bastionary, is what makes a real DR drill for your users' access possible in the first place.

Run it yourself

Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.

Get started