Keycloak backup and disaster recovery

Keycloak backup and disaster recovery means protecting the database, the configuration as code, and the custom providers and themes, then proving you can restore them within agreed objectives. This page explains what to back up, why realm exports fall short, and how to plan and drill the recovery.

On this page

What Keycloak backup and disaster recovery must protect during an identity outage

When Keycloak is down, every application that signs users in through it is down with it, so recovery planning starts with what an identity outage takes away. The answer is the Keycloak database, which holds users, credentials, clients, realm settings, sessions and events. Without a restorable copy of that database, a rebuilt server is an empty identity provider, and every user, client secret and role assignment must be recreated by hand. Recovery has three parts: the database, the server configuration that points Keycloak at it, and the custom providers and themes your team has added. Each has a different owner, a different change rate and a different way to fail, so each needs its own backup path.

The configuration covers the settings that define how the server starts, including database connection details, hostname and TLS setup, cache and cluster options, and the values that come from environment variables or secrets stores. Record where each value is stored and who can change it, because a restored database connected to the wrong hostname or missing a key will still fail to sign anyone in. Custom SPI providers, themes and any Operator custom resources should live in version control and in your artifact registry, so the exact build that ran in production can be redeployed to a fresh cluster in your own infrastructure. Confirm with your team which of these you can rebuild from source and which exist only on a running server.

A realm export does not cover this scope. The Keycloak import and export guide states that the Admin Console partial export is not suitable for backups or data transfer between servers, and that full exports omit events, persisted sessions, workflow state and revoked tokens. Treat exports as a way to move configuration for review or testing, and treat the database backup as the recovery source. Ask your team to write down which data each recovery path restores and which it loses, so that the first time someone must make that call is not during an incident.

Which backup method fits each part of a Keycloak deployment

This table compares the backup method for each part of a Keycloak deployment, what each method captures and when it fits. Read it as a checklist: the database holds the live state that matters most, while exports and configuration-as-code cover structure and can be rebuilt. The main takeaway is that no single export replaces a database backup.

ComponentBackup methodWhat it capturesWhen it fits
Production PostgreSQL databaseScheduled database backups with continuous archiving and point-in-time recoveryUsers, credentials, clients, realms, events and persisted sessions, including the data a realm export omitsAlways required for production; the only method that restores live identity state
Realm exports from the admin consolePartial export from the admin consoleSelected realm settings and some configuration objects, without events, persisted sessions or revoked tokensNot suitable for backups or data transfer between servers; use only for reviewing or copying configuration by hand
Full exports with the server export commandFull realm export run from the Keycloak server command lineRealm configuration and users, but omits events, persisted sessions, workflow state and revoked tokensUseful for migration tests and configuration snapshots; pair it with a database backup, not a replacement for one
Configuration kept as code, including Operator custom resourcesVersion control of Keycloak, KeycloakRealmImport, KeycloakOIDCClient and KeycloakSAMLClient resourcesRealm structure, clients and resource definitions, reviewed and versioned in GitFits teams that rebuild environments from declared state; confirm which settings stay outside the manifests
Custom SPI providers and themesSource control plus artifact storage for built JARs and theme archivesProvider source code, build files, compiled artifacts and theme templatesRequired so a rebuilt server can load the same extensions; keep the exact versions used in production
Standby replicaSynchronous or asynchronous database replication to a standby serverA near-current copy of the database for fast failoverReduces recovery time but does not protect against accidental deletion or corruption, which replicate too

How the database, configuration, providers and standby fit together in recovery

The diagram starts with Keycloak nodes reading and writing the primary PostgreSQL database. Continuous WAL archiving sends a copy to a backup store outside the production network, and that crossing is the trust boundary to review, since access to the archive exposes every user, credential and session record. A standby replica follows the primary, while the configuration repository and the provider and theme artifacts sit beside the database as separate recovery inputs. A restore rebuilds the database from the archive and redeploys Keycloak from those inputs. Check that each input can be restored on its own and that the restore path has actually been tested.

Recovery inputs for Keycloak and where the trust boundary sits.

Why a realm export is not a Keycloak backup

A realm export is not a Keycloak backup. The Keycloak import and export guide describes the Admin Console partial export as not suitable for backups or for moving data between servers, and a full export omits events, persisted sessions, workflow state and revoked tokens. A recovery plan that depends on exports alone would bring back realm configuration but lose the user activity and token state that an identity outage actually disrupts. The database is the system of record for that state, so the database backup is the component that restores users' sessions and history.

A realm export still has real uses. It gives you a portable snapshot of realm configuration (clients, roles, identity providers, authentication flows and similar settings) that you can keep in version control, review with your security team, or load into a scratch environment to test an upgrade or a migration. Those snapshots are most useful when they are taken on a schedule and compared over time, because they show what changed between two points. Confirm with your own configuration which items your export covers, and check the export file for secrets before storing it outside a controlled location.

When you plan a restore, treat the export and the database backup as separate inputs. Restore the database to a recovery point, then use the export only where you need configuration that was changed after that point or that must be rebuilt on a new cluster. Test this sequence in a drill, because the export and the database can come from different times and the team needs to know which settings win. Confirm with your database team how the database is backed up and restored, since the recovery steps depend on that setup.

Database backup and restore blueprints for PostgreSQL

Continuous archiving combines a periodic base backup with a continuous stream of write-ahead log (WAL) segments sent to archive storage. It protects against logical damage such as an accidental realm deletion, a bad bulk update to users, or a failed migration, because you can restore the base backup and replay WAL up to a chosen moment just before the damage. Keycloak's database holds users, clients, credentials and sessions, so this is usually the blueprint that answers the question of how far back you can recover.

  • Archive storage: Store WAL and base backups in object storage or another location separate from the primary database host, with retention set by your recovery requirements.
  • Restore environment: Keep a spare PostgreSQL server of the same major version available for restore drills, sized to hold the restored data.
  • Recovery target: Document the stop point (time, transaction or named restore point) that your runbook uses to avoid replaying past the damage.
  • Credentials and encryption: Control who can read the archive, since it contains the full identity database, and encrypt it at rest.
  • Limits: This blueprint does not provide a warm standby, so restores take time proportional to the data volume and replay length. PostgreSQL does not detect primary failure or switch traffic on its own.

Check the archive retention window, the time a full restore takes in your environment, and whether a restored Keycloak instance starts cleanly against it.

Setting recovery point and recovery time objectives for an identity service

Recovery point and recovery time objectives for Keycloak are set by a handful of connected decisions: what data loss users can absorb, how the database is replicated and archived, where a restore lands, and who approves it. Settle these with the business owners of each dependent application, then confirm the resulting targets in restore drills rather than on paper.

Tolerable loss of sessions and user changes

Decide how much recent activity can disappear after a restore: active sessions, newly registered users, password changes, MFA enrollments and role grants. Sessions are usually cheaper to lose than credential changes, so the answer may differ by data type. Ask each business owner which losses force users to re-authenticate and which create a security gap, such as a revoked user who regains access. Record the answer per category before choosing any archive frequency.

WAL archive frequency

Continuous archiving and point-in-time recovery of the PostgreSQL database set the recovery point. Base backups plus archived write-ahead log segments let you restore to a chosen moment, but only as far as the most recent archived segment. Check how often segments are shipped, where they are stored, and whether the archive is separate from the primary's failure domain. Test that a restore reaches the intended point in time.

PostgreSQL archiving docs

Synchronous or asynchronous standby

Synchronous replication means a commit waits for the standby, which narrows data loss on failover but adds write latency and can stall logins when the standby is unreachable. Asynchronous replication keeps logins responsive but can lose the most recent committed changes during failover. Keycloak's supported high availability designs require a synchronously replicated database, so confirm with your database team how that requirement is met and what happens when the standby is lost.

In-place restore or a new cluster

Decide whether recovery overwrites the existing database and Keycloak cluster or builds a new cluster from backup and then switches traffic to it. A new cluster keeps the damaged system available for forensics and allows a rehearsed cutover, but needs DNS, certificates, and the reverse proxy to follow. An in-place restore is faster to start but destroys evidence. Write down which path applies to each failure type, such as data corruption, accidental deletion or a compromised admin.

Who can authorize a restore

A restore of an identity service rolls back security state, so it needs a named approver outside the team performing it. Define who may declare the incident, who approves a point-in-time choice that discards recent changes, and who verifies that revoked accounts stay revoked after recovery. Keep the approval path reachable during an outage, including out-of-hours contacts and break-glass access to backup storage. Confirm these roles with your incident response owners before the first drill.

Dependent applications during the outage

Every application that delegates sign-in to Keycloak needs a stated behavior during an identity outage: fail closed, serve cached sessions for a limited period, or switch to a documented fallback. The answer sets how much time the business can tolerate, which in turn sets the recovery time objective. Inventory the applications, their session lifetimes and their emergency access paths, then test the fallback in the same drill that exercises the restore.

How to build and test a Keycloak restore runbook

This sequence turns a backup plan into a restore runbook that a team has actually exercised, so that after an identity outage the people on call can rebuild Keycloak to a known point in time and prove that sign-in works.

  1. Inventory every stateful component

    The platform owner lists everything Keycloak needs to come back: the production database, the configuration applied through the Admin Console or the Operator, custom providers packaged as JARs, themes, TLS certificates and keys, the secrets that connect Keycloak to the database and to any LDAP or identity provider, and the reverse proxy settings. Each item gets an owner, a storage location and a note on whether it is backed up. The step is done when the list is reviewed by someone outside the team who runs Keycloak, and every item maps to a backup source or a documented way to recreate it. Partial realm exports do not count as backups, because the Keycloak import and export guide says full exports omit events, persisted sessions, workflow state and revoked tokens.

  2. Enable and verify continuous archiving

    The database team enables continuous archiving on the PostgreSQL primary so that a base backup and a stream of archived write-ahead log segments can be used for point-in-time recovery. They confirm the archive command succeeds, that archives land in a location separate from the database host, and that the retention period matches the recovery point the business has agreed. The check is a logged successful archive of a recent segment, plus a test that the archive location is readable from a different host. If the database is not PostgreSQL or uses a managed service, the team confirms in writing with the provider which recovery options exist and how they are tested.

  3. Store configuration and provider artifacts under version control

    The platform team keeps Keycloak configuration as code where possible, including realm and client definitions, Operator custom resources, deployment manifests, container image references, custom SPI provider source or built artifacts, and theme files. Each artifact is tagged with the Keycloak version it was built for, and build outputs are stored in an artifact repository with checksums. The step is complete when a clean checkout and build reproduces the exact provider and theme files running in production. Secrets stay in a dedicated secrets store, and the repository holds only references to them.

  4. Record the target Keycloak and schema versions

    The runbook names the Keycloak release, the container image digest, the database major version, and the database schema version the restore must match. Keycloak migrates its schema at startup by default, so a backup taken before an upgrade may need the older Keycloak version to start, and a newer image may have already migrated the schema. The team records which migration mode each environment uses and where the upgrade notes for each version are kept. The check is a written record that a responder can read during an incident, reviewed after each Keycloak upgrade. Current supported PostgreSQL versions are listed in the PostgreSQL versioning policy, and the team confirms that the target version is still supported.

  5. Restore the database to a point in time in isolation

    The database administrator restores the base backup into an isolated environment that has no route to production clients or to live identity providers, then replays archived write-ahead logs up to the chosen target time. This isolation prevents restored sessions, scheduled jobs or outbound notifications from reaching real users. The check is a database that starts cleanly, passes integrity queries, and reports the expected latest transaction time for the chosen target. The restore time is measured and recorded, since it is the basis for the recovery time objective.

  6. Start Keycloak against the restored database

    The platform engineer starts the recorded Keycloak version in the isolated environment with the same providers, themes, and configuration artifacts from version control, pointed at the restored database. Outbound email and identity provider connections are disabled or redirected to test endpoints. The check is that Keycloak starts without schema errors, reports the expected version in its logs, and loads the custom providers and themes without warnings. If the schema does not match, the team uses the version and migration notes recorded in the earlier step rather than changing the database by hand.

  7. Verify realms, clients, test login and admin access

    The identity team checks that each realm, client, identity provider and role mapping exists and matches the configuration in version control. They run a test login through a non-production client for each protocol in use, covering OpenID Connect and SAML where applicable, including a test account with multi-factor enrollment. They confirm administrator access through the admin console and the Administration REST API on their dedicated hostname. The step is done when a written checklist with timestamps and results is signed off, and any gaps become tracked corrections to the runbook. Repeating this step on a schedule is what turns the runbook into a disaster recovery drill.

What a Keycloak DR drill must prove before you rely on it

A disaster recovery drill is the only evidence that a Keycloak restore works, so treat an untested backup as unproven. The drill should start from the archive alone, following the written runbook without help from the engineer who set up the original system. If the restore depends on someone's memory of a command or a hidden file path, the runbook is incomplete and the drill has found a gap. Record each step, who ran it, and where it deviated from the documented procedure.

A successful database restore does not prove the identity service works. After the restore, confirm that the custom providers and themes packaged in your deployment load at startup, that the login pages render with the expected branding, and that the server reports no missing SPI classes in its logs. Then have a test user complete a full sign-in through a representative client, including token issuance and a refresh, and confirm that the application accepts the token. Also check the admin recovery path: a named administrator should be able to sign in, and the break-glass account and its credentials should be usable under your documented access process.

Keycloak migrates its database schema automatically at startup by default, so a drill that restores a database from an older or newer release can change the schema the moment the node starts. Decide in advance whether your restore environment will use automatic or manual migration, and rehearse that choice. Measure the elapsed time from the decision to declare an outage to the point where a test login succeeds, then compare it with your recovery time and recovery point objectives. Keep the drill record, including the timings, the versions tested, the deviations and the retest results, as evidence for your auditors and your risk owners.

Security risks in Keycloak backups and restores

A Keycloak backup holds the same secrets as the live server, so a recovery copy is a security asset in its own right. The cards below cover the controls that keep backups, restore hosts and recovery steps from becoming the weakest point of your identity estate.

Backups hold credentials and keys

A full database backup contains password hashes, client secrets, token signing keys and session-related data. Anyone who can read the archive can attempt offline password cracking or forge tokens for the realms it contains. Encrypt backups at rest, restrict read access to a named group, and confirm that configuration files holding secrets are stored in the same protected location. Check that backup copies sent off-site carry the same controls as the primary store.

Keycloak export guide

Restored hosts must stay isolated

A restored Keycloak that starts with production hostnames can issue tokens, send email and call live identity provider callbacks before anyone has checked it. Restore into an isolated network with test hostnames, disabled outbound email and no access to production client redirect targets. Verify realms, clients and administrator accounts first, then switch DNS and upstream callbacks in a controlled step.

PostgreSQL authentication on restore hosts

Restore hosts need the same client authentication rules as production. PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM, so a restore host with an older pg_hba.conf template can weaken the connection path or fail to connect. Confirm which methods your pg_hba.conf allows, use SCRAM for Keycloak database roles, and restrict restore access to the database network segment.

PostgreSQL auth methods

Backup credentials and retention need owners

Backup jobs use database, storage and encryption credentials that often outlive the people who created them. Assign a named owner for each credential, rotate them on a schedule, and remove access when staff change roles. Write down how long each backup tier is kept and who approves deletion, because retention that is too long keeps old credentials and revoked users alive in archives, while retention that is too short removes your recovery options.

Log and approve every restore

A restore replaces live identity data, so it is a change that needs a record. Log who requested the restore, which backup and point in time were used, who approved it and what was verified afterward. Keep these entries outside the Keycloak instance being restored so that an attacker who compromised the identity server cannot erase them. Agree the approval path before an incident, since emergency restores are the moment this step is most often skipped.

Realm key material as a restore dependency

Realm signing keys and any external keystores or HSM references are needed to keep existing tokens and metadata consistent after a restore. If the database is restored without the matching key material, clients may fail validation or trust the wrong keys. Inventory where each realm's keys live, back them up under the same controls as the database, and test that a restored realm publishes the expected keys before relying on it.

Keycloak export guide

Questions buyers ask about Keycloak disaster recovery

What drives the cost and effort of a Keycloak disaster recovery plan?

The main drivers are how many Keycloak nodes and databases you run, how many realms, clients, identity providers and custom providers or themes must be recovered, how strict your recovery point and recovery time objectives are, and whether your database is self-managed or a managed service with its own backup features. Each driver adds design work, testing and runbook detail. Costs split into one-time work (architecture, backup tooling, runbooks, the first drill) and recurring work (scheduled drills, backup monitoring, restore testing after upgrades). Ask any provider to itemize these components in a written scope so you can see what is included and who pays for each part.

Can our team build a Keycloak DR plan without outside help?

Yes, if you have engineers who already run Keycloak and your database in production and who can practice a restore in a non-production environment. The hard parts are less the tooling than the discipline: keeping database, configuration, provider JARs and themes versioned together, documenting the order of restore steps, and running drills often enough that the runbook stays accurate. A partner can help with architecture reviews, a first drill and an independent check of the result, while your team keeps ownership of the runbook and the recurring drill schedule.

What do we need to provide for a disaster recovery engagement?

Expect to provide access to the Keycloak database and its backup system, including the ability to take and restore a copy outside production, and read access to the infrastructure that hosts Keycloak, the load balancer and DNS. You will also need owners for the database, the network and the identity directories Keycloak federates with, plus approval for a maintenance window for drills. Drills usually touch login availability, so agree in advance on the window, the rollback plan and who can declare a test failed. Confirm these needs with your own change process before scoping starts.

How long does a first Keycloak restore drill take?

The duration depends on the environment rather than on a fixed rule: database size, backup storage location and speed, the number of Keycloak nodes to rebuild, how many external systems must be reconnected, and whether the team has rehearsed the steps before. A first drill usually takes longer than later ones because it uncovers undocumented dependencies, such as a missing provider JAR or a secret that lived only on one server. Ask your provider to state the assumptions behind any duration and to list the environment facts they used.

Is a realm export enough to back up Keycloak?

No. The Keycloak import and export guide says the Admin Console partial export is not suitable for backups or data transfer between servers, and a full export omits events, persisted sessions, workflow state and revoked tokens. A usable backup starts with a consistent copy of the database, which holds users, credentials and most configuration. Keep configuration as code, custom provider JARs and themes in version control or artifact storage so you can rebuild the server. Test a restore end to end, because an export that imports cleanly still may not restore a working login service.

How do Keycloak upgrades affect our ability to restore?

A restore must return the database to the Keycloak version and schema that matches the server binaries you deploy. If you backed up under one version and upgraded, the restored database may need the older image, or the newer server will run schema migration on restore. Keycloak migrates schemas automatically at startup by default, and it also supports manual migration, which the upgrading guide suggests for large deployments. Store each backup with its Keycloak version, record the migration mode, and include a restore test in every upgrade plan.

What does DeployOpen do and what does our team keep?

DeployOpen plans, implements, hardens, backs up, documents and supports self-hosted open-source platforms inside your own infrastructure, and it runs security testing and prepares evidence for compliance assessments. For Keycloak disaster recovery, that can cover the backup design, runbooks, configuration, the first drill and retainer support for later drills. Your team keeps the infrastructure, the accounts and data, the operational decisions and the recovery objectives you approve. DeployOpen does not issue audit reports or certifications, so independent auditors still assess whether your controls meet a framework.

Limits to confirm for your Keycloak and PostgreSQL environment

A recovery plan is only as good as the limits it rests on. The cards below list the versions, database features, operator behavior, retention rules and multi-site steps that change what a backup can restore and how long recovery takes. Confirm each one with the vendor or in your own environment before you write the runbook.

Exact Keycloak version and migration mode

Record the precise Keycloak build in every environment, including the Red Hat build if you use it. Confirm whether the schema migrates automatically at startup or whether your team applies the SQL by hand, since that determines what a restored backup needs before the server starts. A backup taken on one version may not restore cleanly onto another without the migration path the upgrade guide describes. Check the upgrade notes for the version you run.

Current Keycloak release
26.8.1
Keycloak upgrade guide

PostgreSQL version and end-of-support date

Confirm the PostgreSQL major version behind Keycloak and its end-of-support date from the versioning policy. A recovery design that restores onto an unsupported major version carries security and compatibility risk. Plan the major upgrade as part of the recovery schedule, and confirm which Keycloak database versions your release supports before you choose one.

PostgreSQL 14 end of support
November 12, 2026
PostgreSQL versioning policy

Managed database backup features

If the database is Aurora PostgreSQL, Azure SQL or another managed service, confirm what its backup features actually provide: automated backup retention period, point-in-time restore window, cross-region copies, snapshot sharing and encryption key ownership. Ask whether restores create a new instance with a new endpoint, and what your Keycloak configuration must change when that happens. Do not assume the provider's defaults match your recovery objectives.

Operator ownership of database and cluster

Confirm whether the Keycloak Operator manages only the Keycloak custom resources or also the database and cluster around them. If a separate database operator or managed service owns the data, backup schedules and restores sit outside the Keycloak runbook. Check how the Operator's manual approval setting interacts with restores after an unexpected upgrade, and document who can trigger a restore and in what order the components return.

Keycloak Operator docs

Retention and encryption requirements

Ask your compliance and legal teams how long identity data backups must be kept, where copies may be stored, and which encryption standards and key custodians apply. Backups contain user records, credentials hashes and client secrets, so their retention window and access controls are a security decision as well as a storage one. Confirm the answers in writing, because they set how far back a restore can reach and who may read the copies.

Recovery steps for multi-site designs

If you run a multi-cluster or multi-site Keycloak, confirm how each site recovers, which site holds the write primary, and whether the synchronously replicated database or a failover tool promotes the standby. PostgreSQL does not detect primary failure or notify standbys by itself, so the promotion method is a separate decision you must confirm. Test whether a restored site can rejoin without splitting the cluster state.

PostgreSQL failover docs

How DeployOpen scopes, builds and tests Keycloak recovery

DeployOpen plans, implements, backs up, documents and supports self-hosted open-source platforms inside your own infrastructure, and Keycloak recovery follows the same method. We start from the failure scenarios your login depends on, then build and test recovery in your environment so your teams can run it after handover.

How we scope

  • Inventory of the Keycloak database, configuration, custom providers, themes and secrets that a restore must bring back.
  • Recovery point and recovery time objectives agreed with your business and security owners before design starts.
  • Written fixed-scope agreement listing deliverables, environments, drill count and timelines before any work begins.

How we build

  • Database backup and restore blueprint for your chosen PostgreSQL or other supported database, including retention and encryption.
  • Configuration and provider backup pipeline stored separately from the database, with restore steps written for your platform team.
  • Timed restore drills into an isolated environment, with results recorded against the agreed recovery objectives.

How we hand over

  • Runbook covering failover decisions, restore order, DNS or load balancer switches and verification of logins after recovery.
  • Documented evidence for security and compliance reviewers, such as backup schedules, access controls and drill records.
  • Walkthrough with your operators so they can run a restore and a drill without DeployOpen present.

How we support

  • Ongoing support and periodic recovery drills are available as a retainer, scoped separately from the initial engagement.
  • Review of recovery plans when Keycloak, the database or your hosting platform is upgraded or changed.
  • Retesting after any fix so that recovery findings are closed with evidence rather than assumed resolved.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.