Copying Zitadel data to a test environment with mirror

The Zitadel mirror command replicates production data into a secondary database for testing. This page explains how to prepare the target, choose instance or system scope, repeat runs safely and handle personal data.

On this page

Why teams copy Zitadel production data to a test environment with mirror

The mirror command replicates Zitadel data to a secondary environment for testing, and the same data can be mirrored to several databases without those databases influencing each other. That gives a platform team a way to test an upgrade, a login flow or a configuration change against identity data that looks like production, instead of a handful of hand-made test users. The situation usually looks like this: a new Zitadel release is ready to evaluate, a change to an organization's identity provider or action needs checking, or a team wants to confirm that a login flow works for the users, organizations and grants that exist today. Synthetic data rarely reproduces those edge cases, such as long-lived users with several linked identity providers or organizations with unusual role grants.

Mirror is a copy mechanism for testing, not a substitute for the controls around production. It does not replace PostgreSQL backups and restore drills, which remain the recovery path for production data. It does not test your infrastructure, load behavior or capacity, which belong to separate load testing work. A staging copy also does not prove that a Zitadel upgrade is safe for production until you run the upgrade on the copy, watch the startup and projection behavior, and confirm the login and OIDC endpoints work. Confirm with Zitadel's documentation which Zitadel version your mirror tool must match, because the copy is only useful if the test environment runs the version you intend to test.

Before you decide to copy production identity data, settle the question of personal data. A test copy of users, email addresses and linked identity provider accounts is still personal data under most privacy regimes, so the test environment needs the same access controls, logging and retention decisions as production, or the data must be masked before the copy is used. Plan who can read the staging database, how long copies live, and when they are deleted. These decisions shape the rest of the process, and they are easier to make before the first copy runs than after a test environment has been shared with a wider team.

Mirror scope options and when each fits

This table compares the instance and system scopes of the mirror command and the --replace repeat-run behavior, matching each option to the test environment it serves. Read each row as a question: how much production data do you need, and how often will you refresh the copy? Confirm flag names and scope syntax with the command help for your Zitadel version before you script a refresh.

OptionScope or behaviorBest fitCheck before use
Instance scopeMirrors one Zitadel instance, a virtual tenant with fully isolated dataSingle tenant test, such as reproducing one customer's organization setupConfirm the instance identifier flag in your version's help
System scopeMirrors Zitadel system data beyond a single instanceFull environment refresh before a release rehearsal or integration testConfirm exactly what system scope includes and how large the copy will be
Several target databasesCopies to more than one database, and the copies do not influence each otherSeparate staging and load test copies from one production sourcePlan a separate target database and credentials for each copy
First run into a prepared targetCreates the mirrored data in a target set up for itInitial baseline for a new test environmentConfirm the target preparation steps and required state in the docs
Repeat run with --replaceReplaces previously mirrored data in the target on each runRepeated refresh cycles that keep staging close to productionRun against a non-critical target first and confirm what gets overwritten
Repeat run without --replaceBehavior when the target already holds data depends on the versionOnly when you intend to keep an existing copy unchangedConfirm the default behavior in your version before relying on it

Setting up a staging database as a mirror target

This sequence takes a staging PostgreSQL server from empty to a verified copy of production Zitadel data, with a written refresh routine so the copy can be rebuilt on demand. Each step ends with a check the team can repeat.

  1. Confirm the staging PostgreSQL version

    The platform team selects a staging PostgreSQL server running a version Zitadel supports, which is 14 through 18 according to the Zitadel database documentation. Match the staging version to the production version where possible, and confirm the exact Zitadel release that production runs so the mirror tooling matches it. Done means the team has written down both versions and the staging server reports a supported major version when queried.

  2. Provision an isolated staging database

    The platform team or DBA creates an empty database and a dedicated role for the mirror target on a server that is separate from production. The target should not share storage, credentials or network paths with production, so that test activity and mirror writes cannot affect live data. Done means the database exists, is empty, and a connection test from the staging server shows the role can log in with the intended privileges only.

  3. Confirm network access and credentials

    The team opens only the network path needed from the machine that runs the mirror command to both the production source database and the staging target, and stores each set of credentials in the team's secrets store. Review the connection parameters against the mirror command documentation before the first run. Done means a test connection to each database succeeds from the same host, and the team has confirmed that the production credentials used are read-only where the setup allows it.

  4. Choose the mirror scope

    The platform lead decides whether the copy covers a single instance or the whole system, based on what the test environment needs to exercise. Record the choice, the instance or system identifiers involved, and the reason for it, since later refreshes must use the same scope. Done means the scope is written in the environment runbook and reviewed by the security or compliance owner before any data moves.

  5. Run the first mirror

    An engineer runs the mirror command with the chosen scope against the production source and the staging target, following the flags in the Zitadel mirror documentation. Capture the command output and the time the run started and finished in the change record. Done means the command exits without errors, and the log shows which data was replicated and to which target.

  6. Verify the copied data

    The engineer compares object counts and sample records between source and target for the agreed scope, and then logs in to the staging Zitadel instance with a test account to confirm that organizations, projects and users resolve as expected. Note any mismatches and rerun the mirror if needed. Done means the comparison notes show matching counts for the scope and the test login works against the staging environment.

  7. Document the refresh routine

    The platform team writes a refresh procedure that covers who starts a repeat run, when it is allowed, how the --replace option is used so the target is overwritten cleanly, and how the verification from the previous step is repeated. Include the rule that the staging copy inherits personal data controls from the handling policy. Done means the runbook is stored with the environment documentation and a second engineer has completed one refresh by following it.

Running repeat mirrors with --replace without losing test work

A repeat run with --replace overwrites the data the mirror previously wrote to the target database, so the first question to settle is what that overwrite covers. Before the first refresh, confirm in the Zitadel docs: mirror command exactly which scope the replacement touches in the version you run, whether it is limited to the instance or system scope you selected or reaches other data in the target schema. Test the behavior on a throwaway database first, and record what disappeared. Treat the staging database as disposable for mirrored data only. Any tester-created users, test clients, scratch grants or manual fixes made directly in staging after the last mirror will not survive a replacement, so assume they are lost unless you have confirmed otherwise.

A refresh is appropriate when the staging copy no longer reflects the production state the team is testing against, for example after a schema-affecting release, a configuration change that must be exercised with real data, or a bug that cannot be reproduced on stale data. It is not a good trigger for routine convenience. Agree a refresh schedule with the people who use staging, and announce each replacement in the channel they already read, with the planned time, the scope being replaced, and the request to export or note any test work they want to keep. Give testers a clear window to finish or capture their work before the job starts, and confirm afterward that the refresh completed before they resume.

Keep staging-only configuration out of the mirrored data so a refresh never erases it. Test-only identity providers, staging redirect URIs, sandbox signing settings, debug switches and any action scripts that exist only for testing belong in versioned infrastructure code, such as Helm values, Terraform or deployment manifests kept in your own repository, and should be reapplied after each run rather than edited by hand in the console. Document which objects are mirrored and which are owned by staging, and review that list whenever production configuration changes. Also remember that mirrored data includes personal data copied from production, so any test accounts you add afterward should use synthetic identities that are clearly marked as test records.

How production data flows into isolated test databases

The mirror command reads from the production Zitadel database and writes into one or more staging databases, so the two never share a connection. Production sits on its own side of the trust boundary, and the copy is only written into a target that has been prepared in the test network. Check that the source is read-only for the job, that each staging target is a separate database, and that the test network cannot reach production.

Production data is copied by the mirror command into separate staging databases.

Protecting production and personal data in test copies

A mirrored Zitadel database holds the same user records, login history and organization data as production, so the test environment inherits production's privacy exposure. The cards below cover the risks that come with that copy and the controls to decide on before the first mirror run.

Personal data in staging

A mirror copies user profiles, email addresses, phone numbers and login metadata along with everything else in the source database. Staging usually has looser logging, shared debugging habits and wider engineer access than production, so the copy is often less protected than the original. Decide with the compliance owner whether personal data is needed in test at all, and if it is, which fields must be masked, pseudonymized or excluded before or after the copy.

Mirror command docs

Weaker access controls on test

Test environments often accept logins from broader networks, run older patch levels and share administrator accounts. A copied Zitadel instance can expose a working login page, OIDC clients and admin consoles that were built for production. Restrict network paths to the staging instance, use separate administrator identities, and confirm which test users and clients may sign in.

Credentials used by the mirror job

The mirror job needs read access to the source database and write access to the target, which makes its database credentials a high-value secret. Give the job a dedicated account with the least privilege that works, store its credentials in your secrets manager rather than in shell history or job files, and rotate them after each run. Confirm the exact permissions your PostgreSQL version and Zitadel release require.

Masterkey handling in the test instance

The masterkey encrypts sensitive values stored in Zitadel, so a test instance that holds production data also needs the production masterkey to read it. Copying that key into staging spreads the most sensitive secret to a weaker environment. Decide whether the test instance uses its own masterkey, which would leave encrypted values unreadable, or the production key under stricter custody, and record that choice in your data handling procedure.

Deleting copies on schedule

Each mirror run leaves a full copy of production data behind until someone removes it. Copies that persist for months are easy to forget and hard to account for in a data subject request. Set a retention period with the compliance owner, assign an owner for deletion, and check that the database, backups, snapshots and exports of the test copy are all removed on the same schedule.

Confirming the mirror scope

Mirror runs can target a whole system or a single instance, so the scope decision also determines how much personal data leaves production. Limit the copy to the instance and data the test needs, document that scope in the run record, and confirm with the compliance owner that the scope matches the purpose of the test before any repeat run with the replace option.

Questions teams ask before copying Zitadel data to staging

What does a Zitadel mirror project cost?

Cost depends on the scope of the work, not on a fixed fee for running the command. DeployOpen works to a fixed scope agreed in writing before work starts, and the quote follows from that scope. The main drivers are the number of target databases, whether you mirror selected instances or the whole system, how much personal data handling the test copies need, and how much of the staging environment already exists. Repeat refreshes add recurring effort because each run needs checking. Ask any provider to split the quote into one-time setup, verification, and recurring refresh, and to state who performs each repeat run and who signs off on the results.

How long does mirror setup take?

The duration depends on the agreed scope, but the work follows a predictable sequence: confirming the target PostgreSQL version, choosing instance or system scope, a first run, verification against production, and documenting the refresh routine. The first run is usually the least predictable step because it exposes gaps in the target, such as missing extensions, storage sizing, network paths, or access accounts. Your team can keep the timeline shorter by deciding early which instances must be copied, providing a staging database on a PostgreSQL version within the range Zitadel supports (14 through 18), and naming the people who approve data handling rules. Ask for a plan that lists each stage with its exit criteria.

What does a mirror project need from our team?

The project needs several inputs from your side before the technical work can finish:

  • Access: read access to the source data path and write access to the staging database.
  • Scope decisions: which instances and organizations are in scope, and whether system-level configuration is copied.
  • Data rules: a named approver for personal data handling and retention in test copies.
  • Environment: a staging PostgreSQL instance your team can operate, with network paths and a secrets process.
  • Review: a named owner who checks verification results and accepts the copy.

Delays usually come from the approval and access items, not from the copy itself, so confirm these owners before the scope is signed.

Can our in-house team run a Zitadel mirror on its own?

Yes, a team can run a mirror in-house if it already operates Zitadel and PostgreSQL in production and has the authority to approve data handling. The skill gap is usually in verification and repeatability rather than in running the command. An internal team needs to confirm the target database matches what the mirror expects, check that the copy behaves as production for the flows under test, and write a refresh routine that another engineer can repeat. Teams with a single operator, no staging database, or no documented data handling rules often get more value from a fixed-scope engagement. Read the mirror documentation first, then decide whether a pilot run in a non-production environment will show you where the effort sits.

How should personal data be handled in test copies?

Treat a mirrored copy as production personal data until a deliberate step changes that. Options include excluding users who are not needed for testing, replacing names, email addresses, and phone numbers with generated values, limiting who can log in to the copy, and setting a retention period that deletes the copy on schedule. Your compliance team should confirm whether the copy falls under the same processing terms as production and whether test users need consent records. Also check how encrypted fields and secrets are handled, because a copy without the matching key may not work, while a copy that carries the key widens who can read sensitive values. Record each decision so auditors can trace it.

When is a mirror the wrong tool for test data?

A mirror is the wrong tool when the test does not need production data. Examples (illustrative): a team building a new login flow may only need a few synthetic users, and a load test needs controlled volumes that a copy will not give. Use a fresh install or a migration rehearsal when you are testing an import from another identity system, and follow the migration guides for that source. A mirror is also the wrong choice when the staging environment cannot be isolated from production, or when the test must hold no personal data at all. In those cases, synthetic data and a separate setup are safer. Restore drills test backups, which is a different question from whether staging matches production.

What could go wrong after a mirror reaches staging?

The most serious risk is staging acting on production systems. Check that staging cannot send email, SMS, or webhooks to real users, that its redirect URIs and client secrets differ from production, and that its identity provider federation does not point at production partners. Other risks include version mismatch between the source and target, drift after the copy ages, and a repeat run with --replace overwriting data a tester has changed. Confirm how --replace behaves in the mirror command reference before scheduling refreshes. Mitigate by disabling outbound messaging, separating domains and credentials, labeling each environment clearly, and writing a checklist that runs before every refresh.

How DeployOpen scopes and delivers a Zitadel mirror setup

DeployOpen approaches a Zitadel mirror setup as a fixed-scope piece of work inside your own infrastructure, starting with the production data you need, the test environment you will use and the personal data rules that apply to copies. The work is planned in writing, built against your target databases, verified with your team and documented so the copy process can be repeated.

How we scope

  • Confirm which Zitadel instances or system-scope data the test environment needs, and which should stay out of the copy
  • Record the PostgreSQL versions and target databases in writing, checking them against supported versions before work starts
  • Agree who approves personal data in test copies, and what masking or exclusion rules apply
  • Set out in the written scope how repeat runs with replacement will be used and who triggers them

How we build

  • Prepare the staging database and its permissions so the mirror target is isolated from production
  • Configure and run the mirror command against each agreed target, one scope at a time, with logged output
  • Test that separate mirror targets do not influence each other, and that a repeat run with replacement behaves as documented
  • Record each command, configuration key and file name used so the steps can be reproduced by your team

How we hand over

  • Provide a verification checklist comparing row counts and sample records between production and the test copy
  • Deliver a runbook covering target preparation, repeat runs, rollback of a bad copy and cleanup of test data
  • Document the personal data handling decisions, including who can access test copies and how long they are kept
  • Walk your platform and compliance teams through the runbook and confirm the handover in writing

How we support

  • Offer ongoing support and upgrade work as a retainer if your Zitadel version or test process changes
  • Review the runbook again when you upgrade Zitadel, since mirror behavior should be confirmed against the release notes
  • Retest the copy process after changes to database versions, network paths or personal data rules
  • Confirm support terms, response expectations and any recurring fees with DeployOpen in the written quote

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.