Back up and restore
Cloud SQL backups, point-in-time recovery, the restore drill, configuration export and import, and how long the engine keeps and archives audit events and messages.
On this page
On the GKE path the engine's data lives in Cloud SQL for PostgreSQL. Cloud SQL takes a daily backup and keeps transaction logs so you can restore to a moment in time. A restore is something you practise before you need it. The restore-drill.sh script does that without touching the running engine.
Here is how the drill works.
sequenceDiagram
participant You as Your operator
participant SQL as Cloud SQL
participant Pod as Engine pod
You->>SQL: Clone the live instance (or a point in time)
SQL-->>You: Drill clone, private IP
You->>Pod: prisma migrate status against the clone
Pod-->>You: Reachable, schema matches the release
You->>SQL: Delete the clone
Note over You: Record the elapsed time as your restore RTOWhat Terraform sets up
Two Terraform variables set how long you can go back. Both live in terraform.tfvars.
| Variable | Default | What it sets |
|---|---|---|
sql_backup_count | 14 | Daily backups kept, so also the backup window in days. From 7 to 365. |
sql_pitr_days | 7 | Point-in-time recovery window in days. From 1 to 7. |
The instance has regional high availability, private IP only, TLS required and deletion protection in production. Backups are for disaster recovery, not record keeping: anything older than the window is gone from them.
The deploy also takes an on-demand backup before each upgrade, with the description medhook pre-deploy <version>. See Upgrade and roll back.
List the backups:
SQL=$(cd terraform/gke && terraform output -raw cloudsql_instance)
gcloud sql backups list --instance="$SQL"Restore drill
Run the drill at least once a quarter and after every major upgrade, so the first real restore does not happen during an incident. It is read-only for the running installation: it never restores over, patches or restarts the live instance and never changes the release.
PROJECT_ID="$PROJECT_ID" \
SQL_INSTANCE="$(cd terraform/gke && terraform output -raw cloudsql_instance)" \
CLUSTER="$(cd terraform/gke && terraform output -raw cluster_name)" \
CLUSTER_LOCATION="$(cd terraform/gke && terraform output -raw cluster_location)" \
deploy/restore-drill.shThe script:
- Clones the live instance into
<instance>-drill-<UTC time>. It uses the latest state, or the time you pass inPOINT_IN_TIME, such as2026-11-01T14:30:00Z. This usually takes 10 to 30 minutes. - Runs
prisma migrate statusfrom an engine pod against the clone's private IP, with the engine's own credentials. That proves the restored database is reachable and is at the schema the running release expects. - Prints how long it took, then deletes the clone.
On success it prints Restore drill passed and the elapsed seconds. On failure it prints Restore drill FAILED with the reason and exits non-zero. Set KEEP_CLONE=1 to keep the clone for inspection, and delete it yourself afterwards.
Record the time it prints, with the date, as your measured restore time. Repointing the engine at a restored database adds a redeploy.
Restore from a backup
A restore replaces everything written since the backup. Stop inbound feeds first, and agree the cutover with each healthcare organization.
To restore to a point in time without touching the running instance, clone it. Settings → Backup & restore does this for you: under Point-in-time restore choose Restore…, Choose a time and Ask a second admin. Another admin approves it within 24 hours. When the engine's service account may clone the instance (cloudsql.instances.clone) and point-in-time recovery is on, the approval starts the clone, and Settings names the new instance. Otherwise Settings shows the command to run in Cloud Shell, and why. The engine never gives itself a permission, and it writes the restore to the audit log before it asks Cloud SQL. See Settings.
The clone, run by the engine or by you:
gcloud sql instances clone "$SQL" "${SQL}-restore" --point-in-time="2026-11-01T14:30:00Z"Then point the engine at the clone by setting externalDatabase.host in the medhook-helm-values secret to the clone's private IP, and deploy. Terraform writes that secret from the instance it manages, so the next terraform apply, which every upgrade runs, points the engine back at the original instance. Treat the clone as a stopgap, or restore a backup in place, which keeps the instance Terraform knows:
gcloud sql backups restore BACKUP_ID --restore-instance="$SQL"Deploy the version that matches the restored data. After a restore, run rotate-master-key --check to confirm every value opens with the keys you have.
On Docker Compose there is no managed backup. Back up the postgres volume on your own schedule.
Configuration backup
A database backup restores everything, message history included. To move only the configuration to a fresh engine, or to show an auditor how the engine is set up, export the configuration bundle: one JSON file, which Settings signs and downloads as a .zip.
| In the bundle | Never in the bundle |
|---|---|
| Workspaces | Executions, step outputs and any other message content |
| Workflows, their triggers and every saved version | Workflow sample messages and saved test cases |
| Mapping sets (without sample data), code tables | Workflow globals |
| Workspace variables, shared libraries with every version | The audit log |
| Alert rules | Users, workspace members and API clients |
| Adapter profiles, with each secret replaced by a placeholder | VPN tunnels |
| SSO identity providers saved in Settings, with their group-to-role maps | OIDC client secrets and incumbent engine passwords |
| Incumbent engine connections and parallel-run settings | Parallel-run messages, capture tokens and correlation keys |
| The Google sign-in client ID and allowed domains, for the record | Secret values of any kind |
The bundle also leaves out the IP allowlist and log export settings. Set them again on the new engine.
Each secret becomes a named placeholder such as $secret:adapterProfile/<id>/credentials, and the bundle lists every one. That covers adapter profile fields the adapter marks secret, credentials in a URL, whole incoming-webhook URLs (Slack, Teams, Discord), alert rule notification targets, workspace variable secrets, trigger secrets, and credential headers in workflow steps (Authorization, Cookie, X-API-Key, and any header with token, secret or key in its name). Ids are kept, so steps still point at their adapter profiles after an import.
To export, sign in as an admin and open Settings → Backup & restore → Config bundles → Export a bundle (Export), or call GET /api/settings/config-bundle. Settings downloads a signed .zip: the bundle's JSON file and an Ed25519 signature over it, made with the engine's signing key. The API returns the JSON file, or the .zip with ?format=zip. Importing a .zip checks the signature first and refuses a bundle changed after export. Each export is audited as engine_config.exported.
To import:
- Open Settings → Backup & restore → Config bundles → Import a bundle (Import) and pick the file. The engine shows a dry run first: each record is created, updated, left unchanged, or in conflict, plus every secret you will need to re-enter and any warnings.
- A conflict means another record already has that name, its workspace is missing, or a workflow or trigger fails the checks a save runs. Fix it and try again. With any conflict, nothing is imported.
- Select Import N changes. Everything is written in one transaction.
- Re-enter each secret in the list. Until you do, a secret holds a random value that nobody knows, so a connection fails and a webhook signature never verifies. A record that already existed keeps its own secrets.
- Deploy each workflow you need running. Imported workflows land disabled and undeployed, and go through the normal deploy checks. A workflow whose content already matches the engine's is left as it is, including whether it runs.
The import never takes a secret from the file. A stored secret is kept only when the rest of its adapter profile or workflow step is unchanged. If the file changes any other setting (a host, a port, a URL, a user name, the adapter profile a step uses), every secret of that profile or step comes in unset and is listed for re-entry, so a credential never follows a changed destination. A shared library version gets its checksum and export names from its own source, not from the file. The engine accepts only the columns an export writes: a file with any other field is refused before anything is read or written. A secret value written into the file by hand is ignored, and the dry run warns about it.
The API is POST /api/settings/config-bundle/import with { "bundle": …, "dryRun": true }, then without dryRun. A request body over 50 MB is refused. Imports are audited as engine_config.imported (or engine_config.import_refused on a conflict), with the ids of the SSO providers written, of those that grant admin, and of those the import turned off. Google sign-in and the ENGINE_OIDC_* and ENGINE_SAML_* providers come from the environment and are never imported: the dry run says whether this engine's Google sign-in settings match the bundle.
SSO providers and parallel runs
Identity providers saved in Settings → Single sign-on → Other identity providers (OIDC and SAML 2.0) are in the bundle with their non-secret settings: issuer or IdP entity ID and URLs, client ID, the IdP certificate (it is public), the group-to-role map, the default role, the allowed email domains and the MFA and email trust settings. The OIDC client secret is a placeholder. The engine accepts only these settings: a file with any other field in a provider, such as a client secret or a private key, is refused.
An imported provider is held for review:
- It lands disabled, whether it is new or changed, so it signs no one in until an admin turns it on. A provider that already matches the engine's is left as it is, including whether it is on.
- The dry run lists every provider it writes: who the IdP is (the OIDC issuer, or the SAML entity ID, sign-in URL and the SHA-256 fingerprint of each signing certificate), the groups it maps to admin, its default role, whether it trusts unverified emails, the IdP's MFA, or any email domain, which fields differ from this engine's copy, and how many accounts on this engine (and how many admins) are already linked to its id. You get a warning when it grants admin, when admins are linked to it, when its issuer, entity ID or certificate changes while accounts are linked (the new IdP would decide who signs in as them), and when it turns on trust in the IdP's MFA.
- A provider that was on and changes is turned off by the import, and the dry run says so for each one. Read its role map in Settings → Single sign-on → Other identity providers before you turn it on. The import itself never creates a user or changes anyone's role.
- Its OIDC client secret comes in as an unknown value, so sign-in through it fails until you enter the real one. The dry run lists it for re-entry, Settings shows it as not set, and the provider can't be saved until you enter it. A changed provider never keeps the old secret.
- Saving a provider through
PUT /api/settings/ssowithoutenabledleaves it as it is, so an imported provider stays off until someone turns it on. Settings marks it Imported: review before enabling until it is first turned on. Turning any provider on or off is audited withenabled: {from, to}, and turning one on also writessettings.sso_provider_enabled, which says whether it came from an import. - It passes the same checks as a save in Settings: https endpoints, known role names and a certificate that loads. A reserved id (
google,oidc,saml) or a different protocol for an existing id is a conflict.
An import never turns off the last way an admin can sign in. Password sign-in (the break-glass sign-in) counts only for an admin who can finish it: one with an authenticator, or any password admin when the engine can email the sign-in code. If turning off the changed providers would leave no active admin who can do that, has a Google link while Google sign-in is configured, or is linked to a provider that stays on, those providers are conflicts and nothing is imported. Give an admin a password and an authenticator first, or leave the provider out of the file.
An import never moves a record to another workspace. If a record in the file has the id of one on this engine in a different workspace (a workflow, a parallel run with its messages, an incumbent connection, or any other record), it is a conflict. A record can't point into another workspace either: a mapping set or alert rule naming another workspace's workflow, or a workflow step naming another workspace's adapter profile, is a conflict. So is a trigger id that another workflow already has, on this engine or elsewhere in the file.
Migration bridge settings come too. An incumbent connection keeps its name, kind, API URL and auth mode; its user name and password come in unset, so re-enter both. A parallel run keeps its workflow, connection, incumbent channel and ignored fields. It lands closed with no capture token: issue a new token and reopen the run. A new run gets a fresh correlation key from this engine. Its messages stay behind, because they are message content.
Retention
The engine also deletes its own history on a schedule. These periods are your compliance decision.
| What | Setting | Default | What happens at the end |
|---|---|---|---|
| Audit log | AUDIT_LOG_RETENTION_DAYS | 2190 (six years) | Expired events are written to the audit archive first, then deleted. With no archive, nothing is deleted. |
| Executions and steps | EXECUTION_RETENTION_DAYS | 2190 | Settled executions older than this are deleted every 6 hours. 0 keeps them. The minimum is 7 days. |
- Messages of a workflow with Encrypt stored messages on are stored encrypted. Restoring them is only useful with the message key that sealed them. See Stored message encryption.
- Running and pending executions are never deleted. Each purge writes an
execution.purgedaudit event with counts and dates only. - A workflow can have its own retention, 7 to 3650 days, set by an admin in the workflow's Settings tab (under Data) or with
PUT /api/workflows/{id}/retention. It applies even whenEXECUTION_RETENTION_DAYS=0, and its purges' audit events carry theworkflowId. Each change is audited asworkflow.retention_changed. - A workflow can also keep its failed executions longer than the rest, like Mirth's "keep failed messages when pruning": an admin sets Keep failed executions for (7 to 3650 days) in the same place, or sends
keepFailedDaystoPUT /api/workflows/{id}/retention. Failed and partial runs are then deleted after that many days, and completed, filtered and cancelled runs after the workflow's period. Failed runs are never deleted sooner than the rest, and when the period is "keep forever" they are kept too. The Retention field shows both, for example30 days, then bodies deleted · failed runs 365 days. These purges' audit events addkeepFailedDaysand thestatusesthey deleted, and a change is audited asworkflow.retention_changedwith the old and new values of both settings. - A workflow can store less per message and drop message content before its runs are deleted: see Message storage for storage modes and content retention.
- Step outputs are stored once and capped at
EXECUTION_NODE_RESULT_MAX_BYTES(10 MiB) each, so large repeated messages do not multiply the database size. - The same sweep deletes ordering-lane records that have had no message for a day, even with
EXECUTION_RETENTION_DAYS=0. A lane held after a failure is released once retention has deleted the failed message, the same as discarding it. - Deleting a workflow does not delete its message history. The executions stay searchable under the workflow's name until retention removes them.
- With
EXECUTION_ARCHIVE_DIRset, expired executions are archived before they are deleted. See Execution archive. - On GKE, Terraform creates an audit archive bucket. Each archive file is NDJSON with every column, including the hash chain, plus a
.sha256file. The engine can add and read objects but not delete them, andaudit_archive_retention_days(default 2190) keeps every object. audit_archive_lock = truelocks the bucket's retention policy. This cannot be undone: nobody can shorten the retention or delete the bucket until every object ages out. Lock it only after your compliance owner confirms the period.- An
audit.retentionDaysbelow 2190 in Helm is refused unless you also setaudit.allowShortRetention: true.
Execution archive
By default, retention deletes expired executions for good. To keep them, set EXECUTION_ARCHIVE_DIR to a directory: a volume on Docker Compose, or a mounted bucket on GKE. Each retention batch is then written there before it is deleted.
- Each batch is one
executions-<time>-<id>.ndjson.gzfile: gzip NDJSON, one line per execution with its step results. - Message content is encrypted with the stored-message key, as in the database. Content that is already encrypted in the database is copied as it is and never decrypted. Without a message key of at least 32 characters, nothing is archived and nothing is deleted.
- If
EXECUTION_ARCHIVE_DIRis set but the directory is missing or read-only, or there is no message key, retention does not delete anything. Each retention run checks again and logs the problem, and/api/healthshowschecks.executionArchive.statusasmisconfigured(the engine reports degraded). Once the directory is mounted or the key is set, the next run archives and purges as usual. - The engine reads the file back and checks its size and SHA-256 before it writes
executions-<time>-<id>.manifest.json. Only then does it delete the batch. If the archive can't be written, nothing is deleted. - If the engine stops between the archive and the delete, the next run archives those executions again under a new name. You may see a duplicate, never a gap.
- Each batch writes an
execution.archivedaudit event with the archive name, size and checksum. Theexecution.purgedevent names the archive too. - The engine never deletes or overwrites an archive file. Keep them as long as your compliance owner says.
To read one back, an admin calls GET /api/execution-archive?executionId=<id> to find the archive that holds it, then GET /api/execution-archive/<archive>?executionId=<id>. The engine checks the file against its manifest and decrypts the content with its message keys, current or previous. Every read is audited as execution.archive_read.
Checklist
-
sql_backup_countandsql_pitr_daysmatch your recovery needs. - You have run the restore drill and recorded the time.
- The drill is in your calendar every quarter and after every major upgrade.
- The master key is in escrow, including older keys that older backups need.
- Retention periods are agreed with your compliance owner.
- You know whether expired executions must be archived, and
EXECUTION_ARCHIVE_DIRis set if so. - A recent configuration bundle is stored with your other recovery material.