Karyo
Documentation/ Operations

Upgrade, backup and recovery

Karyo 2.1.1rendered at build time
On this page

How an installation moves to a new release, how Karyo and the selected identity provider are backed up and restored, and what no restore can undo.

Derived from services/karyo-app/src/main/resources/application.yaml, scripts/deploy-server.sh, infrastructure/docker/docker-compose.prod.yml, infrastructure/docker/init-db.sh, infrastructure/docker/nginx/nginx.conf and scripts/migrate_keycloak_realm.py.

The schema moves forward when the application boots

services/karyo-app/src/main/resources/application.yaml, quarkus.flyway configures one Flyway migrator over seventeen module location sets, with migrate-at-start: true, out-of-order: true, schemas: karyo and create-schemas: true (ADR 0005).

out-of-order is there because per-module migrations interleave numerically - a layout V308 can ship after orders V4xx are already applied to a long-lived database - while each module's own version range stays internally ordered (application.yaml, quarkus.flyway.out-of-order). The location list matches the migration directories on the classpath exactly, seventeen for seventeen. Four of them hold the engines' tables, created for every installation and empty until a capability acts on them (see data and persistence).

The delivery consequence is that there is no migration step. Upgrading is replacing the image and starting it, and the migration runs inside the application container during boot. If it fails, the container never becomes healthy, and Stage 7 of the deploy script times out after 150 seconds and prints the last twenty lines of its log (scripts/deploy-server.sh, wait_for_health, Stage 8: Verify stack). Watch startup through the first Flyway and Quarkus errors, not only the final health result.

There is no way back from a migration

Flyway's open-source edition has no undo, and nothing here substitutes for one. The limits:

  • Image-only rollback needs the retained, matching application and nginx images plus a compatible configuration, and it is safe only after proving that the old application accepts the current schema and identity state. A previous tag is not that proof. Keep every release's images rather than overwriting a mutable tag and hoping it still means the old one.
  • A schema change is not undone by starting an older image: Flyway forward migrations have no automatic down migrations. Prefer a reviewed forward repair. Restoring a database instead needs a full recovery plan, writers stopped, a verified matching backup, and a decision to accept the loss of everything written since the backup.
  • An identity principal cutover follows the fix-forward or coordinated-restore boundary in the identity upgrade runbook. A managed-Keycloak realm change uses the realm rollback procedure. Restoring provider state without the matching Karyo database, or old secrets without current bindings, can revive or misattribute access.
  • Physical and external work cannot be restored at all. Restoring software cannot put shipped cartons back on the dock, unpick a physical pallet or recall an acknowledgement another system has already received. Warehouse and integration owners must reconcile physical counts, reservations, queued requests and duplicate external messages before reopening. A database restore is never an undo button for warehouse movements.

A Flyway checksum mismatch has one correct answer: restore the applied migration file's exact released bytes, including comments; put the correction in a new forward migration; and never repair, re-baseline or renumber retained data to conceal it.

Upgrading an installation

  1. Compare the installed and the target release: application and nginx images, architecture, extensions, configuration, realm state and Flyway history. Identify added migrations and incompatible API or configuration changes. Recompile and test every extension against the target release, not just against the release it was written for.
  2. Rehearse on isolated storage restored from a representative backup (see Restoring), with identity, network and outbound effects isolated too. Test schema migration and restart, then the agreed warehouse and negative cases. Success on an empty database proves nothing about retained data.
  3. Prepare the window. Obtain a go or no-go, communicate the outage, stop new warehouse work, and drain and reconcile queued operations and integrations. Capture the last known counts and external acknowledgements. Take a matching pre-upgrade backup (see Backing up) and keep the old images.
  4. Change identity through its selected procedure. A principal-boundary upgrade uses the reviewed manifest runbook. In managed mode, --import-realm skips an existing realm, so provider-client changes use changing an existing Keycloak realm. For an external provider, coordinate its own reviewed backup and change procedure; do not infer or recreate bindings from usernames or email.
  5. Install the target. A source update needs a full rebuild; --quick compiles nothing. An image built elsewhere is started without rebuilding: load it, export both image references (KARYO_APP_IMAGE, KARYO_NGINX_IMAGE) and run ./scripts/deploy-server.sh --quick. A host without a JDK and Node starts released images with --image-only instead (deploying). Keep the existing credentials unless a reviewed rotation is part of the change. Never use --reset-db for an upgrade.
  6. Watch the first boot. Read the first Flyway and Quarkus errors, not only the final health. nginx follows a recreated application or Keycloak container on its own and does not have to be recreated alongside it (see runtime and configuration). Finish verification (see verifying an installation) before warehouse work and external effects resume.

2.1.0 contract compatibility

The comparison against v2.0.0 covers all 21 existing -api modules. Only auth-api and layout-api change existing declarations; the new ai-api module adds contracts. The other 19 modules have no source changes.

RuntimePropertyLookup.storedDescription defaults to null when an implementation does not expose notes. The layout DTOs retain the 2.0.0 positional order and accept the old constructor arguments. New optional overrides and temperature limits default to null; enclosed defaults to false. FloorSizesResponse.rackDepthMetres defaults to null for old constructor calls, because they contain no rack depth and an installation can override the catalogue value. FloorPlanAisleResponse.walkingAisleMetres defaults to null for old constructor calls, because they contain no rack-face count from which to calculate a width. The server still supplies the actual values. These defaults do not replace stored or resolved values in server responses or rename JSON fields.

The eleven extended layout DTOs also retain their old JVM constructors, constructor default-argument bridges, copy methods and copy default-argument bridges. Existing destructuring keeps its field order. The new lookup method has a JVM default implementation. The source and JVM compatibility tests live in services/karyo-app/src/test/kotlin/com/karyo/app/Api210CompatibilityTest.kt and Api210BinaryCompatibilityTest.kt. This repair does not change the requirement to rebuild and test extensions for each release, or establish a general binary-loading guarantee (extension contract).

Backing up

Nothing in the repository takes a backup on its own (see Nothing takes a backup on its own); this is the procedure an operator runs. Adapt retention, encryption, off-host transport and permissions to the installation's own agreement. A dump on the same failed disk is not recovery. Every complete backup includes the karyo database, environment and secrets, exact application and nginx images, and external integration checkpoints. Managed mode also requires the matching keycloak database; external mode requires a provider-state backup or recovery checkpoint produced by that provider's procedure. Principal bindings in Karyo and provider subjects must be recoverable to the same point.

This is a maintenance outage: the ingress, the application's schedulers and every identity writer stop, and PostgreSQL stays up. Run it from the deployment's own checkout, against an already identified project, with any other database writer stopped first. With Podman, use podman-compose in place of docker compose in the array.

The command below is the managed-Keycloak variant. In external mode stop nginx and karyo-app, dump karyo, and capture the provider checkpoint separately instead of treating the unused Keycloak database as identity evidence.

set -euo pipefail
: "${COMPOSE_PROJECT_NAME:?select the existing project to back up}"
: "${BACKUP_DIR:?choose a new, protected backup directory}"
COMPOSE=(docker compose -p "$COMPOSE_PROJECT_NAME" -f infrastructure/docker/docker-compose.prod.yml)
umask 077
mkdir -m 700 "$BACKUP_DIR"   # must not already exist
"${COMPOSE[@]}" stop nginx karyo-app keycloak
"${COMPOSE[@]}" exec -T postgresql sh -c \
  'pg_dump -U "$POSTGRES_USER" -Fc karyo' > "$BACKUP_DIR/karyo.dump"
"${COMPOSE[@]}" exec -T postgresql sh -c \
  'pg_dump -U "$POSTGRES_USER" -Fc keycloak' > "$BACKUP_DIR/keycloak.dump"
sha256sum "$BACKUP_DIR/"*.dump > "$BACKUP_DIR/SHA256SUMS"
test -s "$BACKUP_DIR/karyo.dump" && test -s "$BACKUP_DIR/keycloak.dump"

Expected in managed mode: every command exits zero, leaving two non-empty custom-format dumps and their checksums. External mode must instead produce the Karyo dump and its separately verified provider checkpoint. That is not proof of restore. If any part fails, keep writers stopped until a decision is made; never label an uncoordinated set a valid backup. scripts/.env.prod and the rendered service files hold secrets: keep their recoverable state in the protected channel the dumps go to, never in a repository or a ticket.

Restart the stack afterwards with the same exported project and image selection, using ./scripts/deploy-server.sh --quick, and verify it.

Restoring

Restore into a separately allocated PostgreSQL instance, never into the source project. The commands below are for managed mode: prepare empty karyo and keycloak databases and the required role, as infrastructure/docker/init-db.sh does for a new installation (init-db.sh, CREATE DATABASE keycloak, CREATE SCHEMA karyo). Record the source and restore container IDs and storage and check that they differ. The restoring PostgreSQL tooling must support the dump's server version; preserve owners and privileges rather than masking a missing role with flags.

# RESTORE_PG_CONTAINER is the verified, isolated PostgreSQL container, never a guessed default.
: "${RESTORE_PG_CONTAINER:?select the isolated restore container with empty databases}"
sha256sum -c "$BACKUP_DIR/SHA256SUMS"
docker exec -i "$RESTORE_PG_CONTAINER" sh -c \
  'pg_restore --exit-on-error -U "$POSTGRES_USER" -d karyo' < "$BACKUP_DIR/karyo.dump"
docker exec -i "$RESTORE_PG_CONTAINER" sh -c \
  'pg_restore --exit-on-error -U "$POSTGRES_USER" -d keycloak' < "$BACKUP_DIR/keycloak.dump"

Expected: both managed-mode restores exit zero with no ignored errors. In external mode restore only karyo here and restore or isolate provider state through its own procedure. Then confirm the schemas and Flyway history, warehouse quantities, principal/binding records and provider subjects against the same checkpoint, and boot the matching release in isolation. Keep restored identities unreachable from outside and block real outbound effects. A different origin needs deliberate provider callback maintenance; never rewrite production callbacks to make a rehearsal pass.

Do not run pg_restore over a live, non-empty database with this procedure. Replacing an installation's data in place is a recovery decision with data loss attached, taken with every writer stopped and a verified matching backup in hand.

Nothing takes a backup on its own

There is no scheduled dump, no sidecar, no backup volume and no retention job anywhere in the Compose files, the deploy script or the workflow. That is deliberate: where backups go, how long they are kept and how they are encrypted are decisions for the installation, and the repository provisions no storage for them. Its cost is that nothing happens unless an operator makes it happen.

The single named volume karyo-pgdata holds every warehouse record, Karyo principal and binding; in managed mode it also holds Keycloak's database (docker-compose.prod.yml, services.postgresql.volumes, volumes.karyo-pgdata), and --reset-db destroys it with two warning lines and no confirmation prompt (deploy-server.sh, Stage 6: Start infrastructure (RESET_DB branch)).

The one place a backup is mechanically required is the realm change, where scripts/migrate_keycloak_realm.py refuses its irreversible account deletion without an explicit --verified-backup flag attesting that a restore check succeeded (migrate_keycloak_realm.py, migrate, main (--verified-backup and --isolated-maintenance checks)). That is the only backup gate in the system, and it gates one procedure.

The managed identity realm is changed inside an isolated window

This section applies to managed-Keycloak mode. Keycloak is the component with a numbered realm maintenance procedure, and nothing else in the system is protected as carefully. Its first step is a restorable backup of the Keycloak database that is proved to restore, by restoring it into a throwaway database, before anything else happens; a run that fails partway is recoverable only from a backup already known to be good. Its rollback restores that dump with every public route stopped, and has to generate new client secrets for the restored realm before anything starts. Both are in deploying.

Flyway history, not a tag, describes the installed schema

A Git tag says which source a release was cut from. What an installation's database actually holds is its Flyway history:

docker compose -f infrastructure/docker/docker-compose.prod.yml exec -T postgresql sh -c \
  'psql -U "$POSTGRES_USER" -d karyo -c "SELECT installed_rank, version, description, success
     FROM karyo.flyway_schema_history ORDER BY installed_rank"'

Compare it with the target release's migration directories before an upgrade, and record it with every backup.