# Back up and restore Zeabur Identity

> Back up Zeabur Identity data and keys, restore service based on your backup type, and practice recovering identities, passkeys, and access permissions.

Back up the cluster's datastore, Zeabur Identity resources, private keys, and related configuration. Restoring the datastore preserves everyone's identity and passkeys. Rebuilding resources from exports creates new identities. Everyone must register new passkeys and relink their GitHub, Google or other upstream accounts, and applications must migrate their user mappings.

## What to back up

Zeabur Identity identifies each person by the UID of their `User` object. Every token's `sub` claim contains this UID, and every passkey binds to it. Kubernetes assigns UIDs when it creates objects, so the restore method determines whether users keep their original identities.

| Item | Restore the cluster's datastore | Rebuild resources from exports |
| - | - | - |
| User UID | Preserved | Regenerated |
| Existing passkeys | Continue to work | Everyone must register new passkeys |
| Existing passwords and authenticator apps | Continue to work, with Secret `zeabur-identity-password-key` | Everyone sets a new password with a setup link |
| Linked GitHub and Google accounts | Continue to work | Everyone must relink their accounts |
| Applications that track users by `sub` | Recognize the same person | Recognize a new user |
| Sessions | Delete them, then everyone signs in again | Don't restore |

Your primary backup must be a **datastore backup for your Kubernetes distribution**, such as an etcd or SQLite snapshot. A `kubectl get -o json` export provides a fallback, but it can't replace a datastore backup.

Exports can't preserve identities for these reasons:

- The `kubectl` username stays the same, such as `zeabur:alice`, but the `sub` claim changes. Applications that map accounts by `sub` treat Alice as a new user. You need to plan a migration with each application.
- Passkeys store the old UID. Zeabur Identity rejects a passkey when the UID doesn't match. Editing the `Credential` object can't change the data stored in the authenticator.
- Credentials, grants, and invitations point to users through an `ownerReference` that contains a UID. Stale references put these objects at risk of Kubernetes garbage collection.

> Don't run two copies of Zeabur Identity with the same Issuer and signing keys at the same time. Before the cutover, keep the restored copy away from production DNS, upstream sign-in callbacks, and users.

### Backup checklist

Keep the following data together. Record the backup date, Zeabur Identity image and `zeabur-identityctl` version, cluster version, Namespace, Issuer URL, and installation options.

| Backup item | Purpose |
| - | - |
| The cluster's datastore backup, plus the server token, encryption keys, and cluster certificates that your distribution needs to open it | This is the only way to preserve UIDs and passkeys. You can't restore a snapshot that you can't decrypt. |
| `users`, `credentials`, `oauthclients`, and `upstreamproviders` (`*.identity.zeabur.com`) | Preserve users and groups, passkey records, password hashes with their authenticator secrets and recovery codes, linked upstream accounts, registered clients, and sign-in providers. |
| Secret `zeabur-identity-signing-keys` | Preserves all private signing keys, including keys scheduled for activation and retired keys. Other data can't reconstruct these keys. |
| Secret `zeabur-identity-password-key` | Preserves the key that Zeabur Identity mixes into every password hash. It also seals authenticator secrets and signs the cookies that count wrong guesses per browser. Without it, no password, authenticator code or recovery code works, and users must set a new password with a setup link. |
| Secret `zeabur-identity-internal-ca` | Preserves the root CA and private key. cert-manager uses it to issue the certificate that kube-apiserver verifies when it connects to the internal address. Keep this Secret with the authentication files on every control plane machine. cert-manager uses it to reissue `zeabur-identity-internal-tls`. |
| Deployment, Service, ServiceAccount, Role, and RoleBinding `zeabur-identity`, plus ClusterRoleBinding `zeabur-identity-cluster-admins` | Preserve how Zeabur Identity runs and its admin permissions. Also back up any RoleBindings you created for other applications. |
| ConfigMap `zeabur-identity-settings`, if you created it | Preserves the `teams` and `admin-sign-in` settings. Without it, all settings return to their defaults. |
| Secret `zeabur-identity-upstream` | Preserve the sign-in providers' client secrets. Also keep the application registrations at those providers. |
| Public TLS and routing | The quickstart installation uses Secret `zeabur-identity-tls` and Ingress `zeabur-identity`. Sign-in rate limiting also uses Ingress `zeabur-identity-rate-limited`, Middleware `zeabur-identity-rate-limit`, and HelmChartConfig `traefik` in `kube-system`. |
| kube-apiserver configuration on every control plane machine | k3s uses `/etc/rancher/k3s/zeabur-identity/authn.yaml` and the configuration that loads this file. |
| Client secrets in each confidential client application's secret store | Zeabur Identity stores only hashes. |
| GitOps or user provisioning configuration | When these systems resume, they overwrite restored data according to their own configuration. |

Exclude `Grant` objects (sessions), `Invitation` objects, and Secret `zeabur-identity-setup` from every restore. Old backups bring back sessions you've revoked and invitation links that should no longer work. You can export these objects for your records, but delete them after restoring.

You don't need to back up sign-in flows in progress. Zeabur Identity keeps this state in memory. Users can start signing in again.

Restoring old data also brings back access you removed after the backup, such as disabled users, deleted passkeys, old client secrets, and revoked admin permissions. Review who has access after every restore.

### Confidential client secrets

An `OAuthClient` stores only the hash of its client secret. `zeabur-identityctl client create` displays the secret once. Zeabur Identity can't provide it again.

After a restore, the application must hold a secret that matches the hash for the client to work. If you rotated the secret after the backup, the restored hash corresponds to the old secret. Give the application the matching secret, or follow [Register clients](https://oss.zeabur.com/docs/identity/users/clients) to generate a new secret and update both sides.

The command doesn't preserve options you omit, so provide all options again when you regenerate a secret.

## Create a backup

Keep this resource export with the datastore backup. You need `kubectl`, `jq`, `tar`, [`age`](https://github.com/FiloSottile/age), Bash, and an admin kubeconfig.

Stop Zeabur Identity during the export so users, credentials, and keys all come from the same point in time. This causes a short planned outage.

### Prepare for downtime and create a backup directory

Before you start:

- Notify users.
- Pause GitOps, user provisioning, and any other systems that write to these objects.
- Work in a private directory on an encrypted disk. Don't enable `set -x`, print Secrets, or commit files to version control. Base64 doesn't provide encryption.

### Stop Zeabur Identity and export resources

The following script records the original replica count, stops Zeabur Identity, and exports resources and mounted Secrets.

```sh
umask 077
NS=zeabur-identity
BACKUP=$(mktemp -d "$HOME/zeabur-identity-backup.XXXXXXXX")

# Remember how many replicas Zeabur Identity had, then stop it.
kubectl -n "$NS" get deploy zeabur-identity -o json > "$BACKUP/deployment.json"
jq -r '.spec.replicas // 1' "$BACKUP/deployment.json" > "$BACKUP/replicas.txt"
kubectl -n "$NS" scale deploy/zeabur-identity --replicas=0
kubectl -n "$NS" wait --for=delete pod \
  -l app.kubernetes.io/name=zeabur-identity --timeout=180s

for resource in users credentials oauthclients upstreamproviders grants invitations; do
  kubectl -n "$NS" get "$resource.identity.zeabur.com" -o json \
    > "$BACKUP/$resource.json"
done
kubectl -n "$NS" get secret zeabur-identity-signing-keys zeabur-identity-internal-ca \
  zeabur-identity-password-key -o json \
  > "$BACKUP/identity-secrets.json"
kubectl -n "$NS" get secret zeabur-identity-upstream -o json --ignore-not-found \
  > "$BACKUP/upstream-secret.json"
kubectl -n "$NS" get svc zeabur-identity -o json > "$BACKUP/service.json"
kubectl -n "$NS" get serviceaccount/zeabur-identity role/zeabur-identity rolebinding/zeabur-identity -o json \
  > "$BACKUP/namespaced-rbac.json"
kubectl get clusterrolebinding zeabur-identity-cluster-admins -o json \
  > "$BACKUP/admin-bindings.json"
kubectl -n "$NS" get configmap zeabur-identity-settings -o json --ignore-not-found \
  > "$BACKUP/settings.json"
kubectl get crd users.identity.zeabur.com credentials.identity.zeabur.com \
  oauthclients.identity.zeabur.com grants.identity.zeabur.com \
  invitations.identity.zeabur.com upstreamproviders.identity.zeabur.com -o json > "$BACKUP/crds.json"

# Save every Secret mounted into Zeabur Identity, whatever it's called.
jq -r '.spec.template.spec.volumes[]? | .secret.secretName // empty' \
  "$BACKUP/deployment.json" | while IFS= read -r secret; do
    kubectl -n "$NS" get secret "$secret" -o json \
      > "$BACKUP/mounted-secret-$secret.json"
  done
```

If any command fails, restart Zeabur Identity before troubleshooting so the backup operation doesn't extend the outage.

```sh
kubectl -n "$NS" scale deploy/zeabur-identity --replicas="$(cat "$BACKUP/replicas.txt")"
```

Fix the cause, then start over. An incomplete directory isn't a backup.

### Export public TLS and routing

If you use the configuration from [Install and sign in on k3s](https://oss.zeabur.com/docs/identity/get-started/quickstart), export these resources:

```sh
kubectl -n "$NS" get secret zeabur-identity-tls -o json > "$BACKUP/public-tls.json"
kubectl -n "$NS" get ingress zeabur-identity -o json > "$BACKUP/ingress.json"
```

If you also enabled the quickstart's sign-in rate limiting, save its configuration:

```sh
kubectl -n "$NS" get ingress zeabur-identity-rate-limited -o json > "$BACKUP/rate-limited-ingress.json"
kubectl -n "$NS" get middleware.traefik.io zeabur-identity-rate-limit -o json > "$BACKUP/rate-limit.json"
kubectl -n kube-system get helmchartconfig traefik -o json > "$BACKUP/traefik-config.json"
```

### Create a datastore snapshot and encrypt the export

To capture a datastore snapshot from the same point in time, create it while Zeabur Identity is still stopped.

Then restart Zeabur Identity and encrypt the export:

```sh
kubectl -n "$NS" scale deploy/zeabur-identity \
  --replicas="$(cat "$BACKUP/replicas.txt")"

# age asks for a passphrase. Store it somewhere you can reach when the cluster is gone.
cd ~
ARCHIVE="$(basename "$BACKUP").tar.gz.age"
tar -C "$BACKUP" -czf "$BACKUP.tar.gz" .
age -p -o "$ARCHIVE" "$BACKUP.tar.gz"
rm "$BACKUP.tar.gz"
shasum -a 256 "$ARCHIVE" > "$ARCHIVE.sha256"
```

`tar` runs separately so you can see errors when it can't read a file. If it reports an error, don't keep that archive.

### Move the backup out of the cluster

Copy the archive and `.sha256` file outside the cluster, restrict read access to a small group, and keep an offline copy. Store the passphrase separately from the archive.

After you confirm that the copies are stored safely, delete the unencrypted directory, then resume GitOps and user provisioning.

## Open a backup

Before using either restore method, verify the archive and decrypt it into a new private directory on an encrypted disk. Start in the directory that contains the archive and `.sha256` file:

```sh
umask 077
ARCHIVE=zeabur-identity-backup.XXXXXXXX.tar.gz.age   # your archive's file name
shasum -a 256 -c "$ARCHIVE.sha256"
RESTORE=$(mktemp -d "$HOME/zeabur-identity-restore.XXXXXXXX")
age -d "$ARCHIVE" | tar -xz -C "$RESTORE"
cd "$RESTORE"
```

This directory contains Zeabur Identity's private signing keys. Delete it after you finish the restore.

## Restore and preserve everyone's identity

Use this method when you have a datastore backup. Users keep their original identities and passkeys.

### Isolate the restore environment before startup

A snapshot restores Zeabur Identity to its state at backup time. If the service was running when you took the backup, it starts with the cluster and brings back old sessions.

Before starting the restored cluster, make sure no one can reach the Issuer's public address. Use a separate network, or block the address at the firewall or load balancer. Upstream sign-in callbacks must also be unable to reach the restore environment.

Use an admin kubeconfig. Don't depend on signing in through Zeabur Identity.

### Restore the datastore

Follow your Kubernetes distribution's procedure to restore the datastore, including any tokens or keys needed for decryption.

Use the same Zeabur Identity version as the backup.

### Stop Zeabur Identity and compare UIDs

As soon as the API responds, stop Zeabur Identity and keep it stopped:

```sh
kubectl -n zeabur-identity scale deploy/zeabur-identity --replicas=0
```

Snapshots taken with the backup procedure above already have a replica count of 0.

Compare the restored user UIDs with the `users.json` export. If they differ, the restore procedure recreated the objects. Switch to the "Restore by rebuilding resources" procedure below.

### Review access permissions

Reapply permission changes made after the backup, including disabling users and revoking admin permissions, passkeys, or client secrets. Finish this before opening sign-in access.

If you can't confirm whether someone should still have access, keep their account disabled until the person responsible decides. This applies even when their passkey still works.

### Delete sessions and one-time links

Keep Zeabur Identity stopped while you delete sessions, invitations, and setup links:

```sh
NS=zeabur-identity
kubectl -n "$NS" delete grants.identity.zeabur.com --all
kubectl -n "$NS" delete invitations.identity.zeabur.com --all
kubectl -n "$NS" delete secret zeabur-identity-setup --ignore-not-found
```

This signs everyone out. Issued tokens contain the information needed for independent verification, so they remain valid until they expire. Unless you've changed the lifetimes, the defaults are 10 minutes for regular accounts and 5 minutes for admin accounts.

### Restore the remaining configuration

Restore configuration Secrets, application client secrets, public TLS, routing, and the kube-apiserver authentication files.

Run `zeabur-identityctl kube-config` with the original Issuer. It directs cert-manager to use the restored CA to issue an internal certificate for the `zeabur-identity` Service address.

If the output differs from the authentication files, follow the "Lost signing keys or internal certificates" section below.

### Start the service and verify access

Use the same image and Issuer, restore Zeabur Identity to its usual replica count, then resume GitOps.

Have an admin sign in again and verify regular and admin access. Test a passkey from before the backup and a confidential client. Open sign-in access to everyone else only after all checks pass.

## Restore by rebuilding resources

Use this method only when you don't have a datastore backup. After the restore:

- Users receive new UIDs, and the `sub` values that applications receive also change.
- Everyone must register new passkeys or set a new password.
- Everyone must sign in again.

Restore into an empty Namespace or cluster. Don't delete a working production Namespace to make room.

### Install the base resources and keep the service stopped

Use the same Zeabur Identity version as the backup to install the CRDs, Namespace, RBAC, and Service. Keep the Deployment's replica count at 0, and isolate the Issuer so users can't connect.

Don't apply `crds.json`, `deployment.json`, or `service.json` directly. These files contain fields set by the old cluster, such as Service IPs, that the new cluster might not accept.

Don't start Zeabur Identity yet, or it will create new signing keys.

### Review and create users and clients

Review `users.json`, `oauthclients.json` and `upstreamproviders.json`. Remove users, clients and providers that shouldn't return. Edit working copies and leave the original archive unchanged.

The following script removes metadata from the old cluster and creates every user in a disabled state to prevent accidental access:

```sh
NS=zeabur-identity   # the namespace you are restoring into
for resource in users oauthclients upstreamproviders; do
  jq --arg ns "$NS" '
    {apiVersion:"v1", kind:"List", items:[.items[] |
      {apiVersion, kind,
       metadata: ({name:.metadata.name, namespace:$ns,
                   labels:(.metadata.labels // {}),
                   annotations:((.metadata.annotations // {}) |
                     del(."kubectl.kubernetes.io/last-applied-configuration"))}),
       spec:(if .kind == "User" then .spec + {disabled:true} else .spec end)}]}
  ' "$resource.json" > "$resource.restore.json"
  kubectl create -f "$resource.restore.json"
done
```

If `create` fails, stop and investigate. Don't switch to a forced apply or delete existing objects that block the operation.

### Restore keys, the CA, and Secrets

Before starting Zeabur Identity, restore the signing keys, internal CA, public TLS, and configuration Secrets:

```sh
for file in identity-secrets.json upstream-secret.json mounted-secret-*.json public-tls.json; do
  [ -s "$file" ] || continue
  jq --arg ns "$NS" '
    {apiVersion:"v1", kind:"List", items:[(if .kind == "List" then .items[] else . end) |
      {apiVersion, kind, type, data,
       metadata:{name:.metadata.name, namespace:$ns,
         labels:(.metadata.labels // {}),
         annotations:((.metadata.annotations // {}) |
           del(."kubectl.kubernetes.io/last-applied-configuration"))}}]}
  ' "$file" > "${file%.json}.restore.json"
  kubectl apply --server-side -f "${file%.json}.restore.json"
done
```

If you exported `settings.json`, restore the `teams` and `admin-sign-in` settings as well:

```sh
[ -s settings.json ] && jq --arg ns "$NS" \
  '{apiVersion, kind, data, metadata:{name:.metadata.name, namespace:$ns}}' settings.json \
  | kubectl apply -f -
```

`identity-secrets.json` contains a list. Each of the other files contains a single Secret. This filter handles both formats.

This step uses `apply` because installing Zeabur Identity already created empty signing key and password key Secrets. If the apply reports a conflict, identify the field owner before deciding whether to add `--force-conflicts`.

### Exclude old credentials, sessions, and links

Don't create any objects from `credentials.json`, `grants.json`, or `invitations.json`.

Old passkeys and passwords can't work with new UIDs. Old sessions refer to accounts by username, so an old refresh token can obtain tokens for whoever currently uses that name.

Users can relink their upstream accounts when they register again.

### Recover one admin account

Follow the internal certificate procedure below to make the internal certificate match the kube-apiserver configuration. Restore routing, and start Zeabur Identity while regular users remain isolated.

Choose an existing admin from the restored users. Verify their identity, then enable the account and generate a setup link:

```sh
ZEABUR_IDENTITY_ISSUER=https://identity.example.test   # the original issuer
RECOVERY_USER=alice                         # the admin you are bringing back
kubectl -n "$NS" get users.identity.zeabur.com "$RECOVERY_USER" -o yaml
kubectl -n "$NS" patch users.identity.zeabur.com "$RECOVERY_USER" \
  --type=merge -p '{"spec":{"disabled":false}}'
zeabur-identityctl setup-link --namespace "$NS" --issuer "$ZEABUR_IDENTITY_ISSUER" \
  --username "$RECOVERY_USER" --reset
```

Before continuing, confirm that `get` shows the account you expect. If the name doesn't exist, `setup-link` creates a new admin account.

Anyone with the setup link can take over that account. Deliver it in person or send it through a channel you trust.

### Restore access for other users and applications

Enable approved users one at a time and send invitations, such as `zeabur-identityctl invite --username alice`. Don't reenable an account only because it appears in the backup.

Have each application that uses Zeabur Identity for sign-in migrate its account mappings to the new `sub` values and sign everyone out of those applications.

When you're done, resume GitOps and user provisioning.

## Lost signing keys or internal certificates

### Signing keys

Public JWKS, client secret hashes, and passkeys can't reconstruct private signing keys. If the keys are lost and you have no backup, Zeabur Identity must start with new keys. This resets the signing keys; it doesn't restore the old ones.

- Tokens signed with the old keys become invalid. Some applications continue to accept them until they refresh their key cache or the tokens expire.
- Delete all grants and invitations so everyone must sign in again.
- Users and passkeys remain unaffected.

If Secret `zeabur-identity-signing-keys` is empty, Zeabur Identity creates new keys at startup. If the Secret no longer exists, Zeabur Identity can't create it on its own. Check all backups. Then, as a cluster admin, recreate the empty Secret the same way you installed Zeabur Identity.

If you suspect someone stole the keys, restoring old keys doesn't remove the risk. Treat the keys as compromised and use new ones.

### Password key

Nothing else can rebuild the key in Secret `zeabur-identity-password-key`. If it is lost and you have no backup, Zeabur Identity starts with a new key:

- Every password, authenticator code and recovery code stops working, and each browser's count of wrong guesses starts again.
- Passkeys, linked accounts and sessions keep working.
- For each user who signed in with a password, delete the password's `Credential` and send a new setup link. A user who also has a passkey or a linked account needs `--reset`, which deletes those too.

If the Secret is empty, Zeabur Identity fills it at startup. If the Secret no longer exists, Zeabur Identity can't create it. Check all backups. Then, as a cluster admin, recreate the empty Secret the same way you installed Zeabur Identity.

### Internal certificates

cert-manager issues `zeabur-identity-internal-tls`. kube-apiserver verifies this certificate when it fetches Zeabur Identity's keys from the internal address.

cert-manager signs the certificate with the root CA in `zeabur-identity-internal-ca`, and kube-apiserver trusts only this CA. Check both with `kubectl -n zeabur-identity get certificate`.

| Condition | Action |
| - | - |
| The service certificate is missing or expired | cert-manager automatically reissues it. No configuration changes are needed on the control plane machines. |
| The root CA is missing, its private key is compromised, or the CA is nearing its 10-year expiration | Replace the root CA. Sign-in fails from step 2 below until kube-apiserver applies the new configuration. |

To replace the root CA:

### Delete the CA Secret

cert-manager issues a new root CA with a new key:

```sh
kubectl -n zeabur-identity delete secret zeabur-identity-internal-ca
kubectl -n zeabur-identity wait certificate/zeabur-identity-internal-ca --for=condition=Ready --timeout=2m
```

### Delete the service certificate Secret

cert-manager issues the service certificate with the new CA:

```sh
kubectl -n zeabur-identity delete secret zeabur-identity-internal-tls
kubectl -n zeabur-identity wait certificate/zeabur-identity-internal-tls --for=condition=Ready --timeout=2m
```

### Update the configuration on every control plane machine

Run `zeabur-identityctl kube-config` for your Kubernetes distribution with the original Issuer.

Follow [Install and sign in on k3s](https://oss.zeabur.com/docs/identity/get-started/quickstart) or [Install on an existing cluster](https://oss.zeabur.com/docs/identity/get-started/existing-cluster) to install the generated configuration on every control plane machine.

On a cluster set up with Zeatend, put the configuration in `apiServer.authenticationConfig` in `/etc/zeatend/config.yaml` and run `sudo zeatend apply` on each server instead.

> Anyone who can read Secrets in the `zeabur-identity` Namespace can also read the CA private key and issue certificates for the internal address. If they can also respond to requests at the Service's ClusterIP, they can supply their own signing keys to kube-apiserver.
>
> Grant Secret read access in this Namespace only to cluster admins. Zeabur Identity's own ServiceAccount can access only these named Secrets: it can read and update `zeabur-identity-signing-keys` and `zeabur-identity-password-key`, read and delete `zeabur-identity-setup`, and read `zeabur-identity-internal-tls` and `zeabur-identity-upstream`.

Don't work around a missing certificate by trusting plain HTTP or skipping certificate checks. If the public certificate is missing, obtain a new certificate for the same hostname.

## Back up and restore a single-server k3s installation

This procedure applies to a single k3s server that uses the default SQLite datastore, with a restore to the same machine.

If you use embedded etcd, an external database, a different Kubernetes version, or a new machine for the restore, follow the [k3s backup and restore guide](https://docs.k3s.io/datastore/backup-restore) or [etcd snapshot documentation](https://docs.k3s.io/cli/etcd-snapshot) instead.

### Create a backup

Stop k3s while copying data to keep the database files consistent. First, follow the backup procedure above to pause other writers and stop Zeabur Identity.

```sh
SNAPSHOT=/var/backups/zeabur-identity-k3s/$(date -u +%Y%m%dT%H%M%SZ)
sudo install -d -m 0700 "$SNAPSHOT"
sudo systemctl stop k3s
sudo tar -C /var/lib/rancher/k3s/server -czf "$SNAPSHOT/db-and-token.tar.gz" db token
sudo chmod 0600 "$SNAPSHOT/db-and-token.tar.gz"
sudo systemctl start k3s
```

Decrypting the database requires the `token` file, so keep the database and token together. Also save `/etc/rancher/k3s`.

Then encrypt the archive and copy it to another machine. Don't keep the only backup on the machine you need to recover.

### Restore a backup

A restore returns the entire cluster to its state at backup time, including workloads beyond Zeabur Identity. Coordinate with everyone who runs workloads in the cluster first.

Keep the failed state for later investigation instead of deleting it:

```sh
RECOVERY_ARCHIVE=/path/to/db-and-token.tar.gz   # the decrypted archive
FAILED_STATE=/var/backups/zeabur-identity-k3s/failed-$(date -u +%Y%m%dT%H%M%SZ)
sudo install -d -m 0700 "$FAILED_STATE"
sudo systemctl stop k3s
sudo mv /var/lib/rancher/k3s/server/db "$FAILED_STATE/db"
sudo cp -a /var/lib/rancher/k3s/server/token "$FAILED_STATE/token"
sudo tar -C /var/lib/rancher/k3s/server -xzf "$RECOVERY_ARCHIVE"
sudo systemctl start k3s
sudo k3s kubectl get --raw=/readyz
```

Don't mix databases and tokens from different backups. If you changed the authentication files after the backup, put the matching versions back before starting k3s.

If you followed the procedure above and took the snapshot while Zeabur Identity was stopped, the service stays stopped after the restore. If the service was running in the snapshot, it starts with k3s. In that case, block the Issuer's public address before starting k3s, then scale Zeabur Identity to 0 replicas as soon as `/readyz` responds.

Before increasing the replica count, complete steps 3 through 5 in "Restore and preserve everyone's identity": stop the service and compare UIDs, review access permissions, and delete sessions and one-time links.

A datastore restore brings back sessions you've revoked. Delete the grants to stop those sessions.

## Practice recovery in advance

Practice the restore procedure in a disposable cluster with test accounts only. For example, use a virtual machine that you can reset to a snapshot between drills.

Start each scenario with a clean installation and a newly registered passkey. At the end of each drill, sign in again and check regular and admin access.

| Scenario | Action | Expected result |
| - | - | - |
| Zeabur Identity outage | Scale Zeabur Identity to 0 replicas, use an admin kubeconfig, then restore the replica count. | The admin kubeconfig works throughout. Passkey sign-in works again after the service returns. |
| Ingress outage | Stop the Ingress controller, use an admin kubeconfig, then start the controller. | Zeabur Identity's public URL is unreachable during the outage. The admin kubeconfig remains unaffected. Everything works again after the controller returns. |
| kube-apiserver can't start | Install a broken authentication file, then restore the configuration on the machine. | The admin kubeconfig works after you restore the configuration. While the Zeabur Identity authentication configuration is removed, kube-apiserver rejects Zeabur Identity tokens. |
| Datastore restore | Back up, delete a user, then restore. | The UID stays the same, and the old passkey still works. Sessions revoked after the backup return until you delete the grants. Issued tokens remain valid until they expire. |
| Rebuild from exports | Delete a user, then rebuild from an export. | The user receives a new UID. The old passkey doesn't work even if you fix the `Credential`. The user can register again. |
| Lost signing keys | Delete the signing key Secret, then recreate it as an empty Secret. | Old tokens and sessions are rejected. Users and passkeys still work. |
| Lost password key | Delete the password key Secret, then recreate it as an empty Secret. | Passwords and authenticator codes are rejected. Passkeys and sessions still work. A new setup link sets a new password. |
| Lost internal certificate | Delete `zeabur-identity-internal-tls`. | cert-manager reissues the certificate with the same CA. Sign-in continues to work, and the authentication files stay unchanged. |
| Internal CA replacement | Follow the internal certificate procedure above. | You get a new CA. Sign-in works again after kube-apiserver applies the new configuration. |
| Failed upgrade | Deploy an image that doesn't exist, then roll back to the old version. | Users, passkeys, and sessions stay unchanged. |

A disposable cluster can't verify the following items. Test them in your own environment too:

- The authenticators and browsers you actually use.
- Public certificates and Ingress.
- Where you store encrypted backups and passphrases, and whether you can retrieve them after the cluster is gone.
- Applications that use Zeabur Identity for sign-in.
- A control plane and datastore spread across multiple machines.
- The exact upgrade you're about to perform.
