Backup and restore

What to back up (the PostgreSQL database and, apart from it, the secret key), how to restore, what happens after restoring an older point in time, and moving servers.

On this page

Status. Written from the design and the code. Not yet run: a full backup and restore of a populated installation following this page. Structam ships no backup tool of its own; it relies on PostgreSQL's.

Structam keeps everything in PostgreSQL. A backup is two things, kept apart:

WhatWhereWhy it matters
The databasePostgreSQLhosts, inventory, change events, configuration versions, users, settings, audit log
STRUCTAM_SECRET_KEY/etc/structam/secrets/secret_key, the compose .env, or the Kubernetes Secretseals every stored credential, every configuration file content and the server identity key

Keep the secret key outside the database backups, in a password manager or a vault. A database backup without the key reveals no sealed value; the key without the backup is useless.

Caution. A database restored without its key loses every integration credential (re-enter them), every configuration file content (gone), TOTP seeds (users enrol again) and the server identity key, which agents pin: every agent then refuses the server and must be re-enrolled. Structam never generates a new identity key over an existing one; it stops at start with a message naming STRUCTAM_SECRET_KEY.

Also keep the node settings (/etc/structam/structam.env, your compose .env, or the ConfigMap) so a rebuilt node gets the same settings, and any STRUCTAM_SERVER_KEY_FILE you use.

Backing up

Any PostgreSQL method works. Choose by how much you can lose:

  • Logical dumps (pg_dump), daily: simple, portable across PostgreSQL versions and CPU architectures, and restore to the time of the dump.
    pg_dump -Fc -d "$DATABASE_URL" -f structam-$(date +%F).dump                               # a server install
    docker compose exec -T db pg_dump -U structam -Fc structam > structam-$(date +%F).dump    # compose
  • Base backups with WAL archiving (pg_basebackup with archive_command, pgBackRest, Barman, or your operator's or provider's backups): restore to any point in time. Use this for production.

A standby is not a backup: it replicates a mistaken deletion at once. Test a restore at least once, into a scratch PostgreSQL, before you need it.

Restoring

  1. Stop every Structam node (or scale the Deployments to 0).
  2. Restore into PostgreSQL 16 or newer:
    createdb -O structam structam
    pg_restore -d structam --no-owner --role=structam structam-2026-12-01.dump
  3. Set the same STRUCTAM_SECRET_KEY as when the backup was taken. During a key rotation, that is the key the backup's values were sealed with; STRUCTAM_SECRET_KEY_PREVIOUS may hold the other.
  4. Check compatibility with the binary you will run, and run the doctor, then start one node:
    structam migrate -check
    structam doctor

    The doctor opens the restored sealed values with STRUCTAM_SECRET_KEY. FAIL secret key ... is sealed with key id <id> means the key is not the one the backup was sealed with: set the right one before starting any node.

  5. Start the other nodes.

After restoring an older point in time

  • Agents reconnect on their own; the server's identity key is the same, so they trust it. The server tells each agent which sequence number it expects; messages the agent still queues are sent again, and anything it already discarded is recorded as an agent.gap change event. Resync on an agent forces a full report.
  • Audit and change chains are consistent within the backup. Events after the backup's time are gone, but SIEM sinks that received them still hold them. The restored id sequences hand out those ids again, and forwarded event ids are derived from them, so a SIEM that de-duplicates on the event id may drop the new events. Before starting the nodes, raise the sequences above the highest ids your sinks received, for example SELECT setval('audit_log_id_seq', <highest audit id> + 1000), and the same for change_event_id_seq.
  • Sessions and tokens are as they were at the backup: tokens revoked later work again until you revoke them again.
  • Licence: the activation is in the database; the next heartbeat brings it up to date.

Moving to another server

Restore as above on the new database, with the same secret key and settings, and point the public URL's DNS (or the load balancer) at the new nodes. Agents connect to the public URL and pin the server key, so they follow without changes.

Questions the docs do not answer?

Ask the people who build Structam. Installation media and licences come from KazLabs.

Talk to us