Skip to content

Back up and restore an installation

Before you begin

You need
  • Shell access to the host, as a user who may use Docker

./mockhub backup takes a cold, complete recovery set: everything needed to bring the installation back, here or on another host, as it was when the backup started. MockHub is unavailable while it runs.

Every set carries the installation’s .env and certificates in a recovery kit, encrypted for one or more recovery keys. Their private halves never live on the host, so a copy of a set alone cannot be opened. Each holder, such as the operator and someone at your organisation, makes a pair on their own machine:

  1. Make a key pair, and keep mockhub-kit.key safe on your machine:

    Terminal window
    openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out mockhub-kit.key
    openssl pkey -in mockhub-kit.key -pubout -out ops.pem
  2. Copy the public half, ops.pem, into recovery-recipients/ in the installation directory. Only files ending in .pem count, and the name before it, here ops, is the holder’s name in each set’s manifest. Use only letters, digits, ., - and _ in the name.

Each holder’s private key opens the kit alone. Before anything stops, backup checks every key in recovery-recipients/: it must be an RSA public key of at least 2048 bits that the kit’s key can be encrypted for. It refuses to run without a recipient, or names each file that fails, such as:

recovery-recipients/legal.pem: it is not an RSA public key in PEM

Fix or remove that file, then run the backup again.

  1. Agree the window: MockHub is unavailable for the backup, and anything changed after it is not in it.

  2. Run:

    Terminal window
    ./mockhub backup

In the window, the scheduler stops, ingress closes behind a maintenance page, the app stops, the queues drain for up to --drain-timeout seconds (300 by default), the workers stop, and then the stateful services stop while their data is copied. Work still queued at the deadline is kept in the set as pending work. Then the stack reopens and is checked, and only then is the set encrypted, given checksums and verified.

.env, tls/ and the edge’s certificates never land unencrypted in BACKUP_DIR. While the set is made they wait in state/backup-stage/, which only the installation’s user can read, and are removed when the backup ends, whether it succeeds, fails or is interrupted.

A directory under BACKUP_DIR (backups/ by default) named by its time, such as backups/20261125T030000Z. It holds:

  • PostgreSQL, the MongoDB activity trail, the data store’s Valkey, and RabbitMQ with its queues.
  • The runtime configuration, and the recovery kit kit.tar.enc with .env, tls/ and the edge’s certificates and keys.
  • A MANIFEST naming the release, the images, the volumes in restore order, what was left out and the pending work, and SHA256SUMS.
  • COMPLETE, written last. A directory without it is not a recovery set.

The newest BACKUP_KEEP complete sets are kept (7 by default). Left out, because they rebuild themselves: the cache, rate-limit counters, the edge’s generated configuration and the GeoIP databases. ./mockhub status warns when the last complete set is older than BACKUP_MAX_AGE_HOURS.

Run ./mockhub backup from the host’s cron or a systemd timer, in the agreed window. A set kept only on the host it protects does not survive losing that host: copy each complete set off it on the agreed schedule.

Only the recovery kit is encrypted. The data archives hold every workspace’s projects, mocks and request logs as they are, so keep BACKUP_DIR on storage only the installation’s operators can read, and copy sets over an encrypted connection to storage that is encrypted.

  1. Run, with the set and a recovery key:

    Terminal window
    ./mockhub restore backups/20261125T030000Z --kit-key ~/mockhub-kit.key

Before anything changes, restore checks:

  • the set’s checksums and archives
  • that this directory holds the release the set was taken from, with its files as that release’s signed manifest records them, built for this host’s architecture
  • the kernel and Docker
  • that the key opens the kit, which it opens into state/restore-stage/, readable only by the installation’s user
  • that the installation’s configuration works with the set’s .env
  • every image that .env names, and the image that writes the data, against the release’s manifest
  • whether this host’s .env differs from the set’s, and free space

If any check fails, restore stops and changes nothing: .env, the data, the containers and whether the installation is open all stay as they were. Then it closes the window, removes the containers, replaces the data and the edge’s certificates, restores .env and tls/ from the kit, runs migrations, rebuilds every project’s mocks on WireMock, checks that stored credentials still decrypt, and reopens, checking the stack before ingress opens.

  1. On the new host, copy in the dist/ files of the same release the set was taken from, and run ./mockhub load with its bundle.

  2. Copy the set and a recovery key to the host.

  3. Run ./mockhub restore as above, without install: .env comes from the kit.

  4. Point the installation’s DNS records at the new host.

On a host whose .env differs from the set’s, restore refuses unless you add --replace-config.

  • A backup is downtime. There is no online backup: the window lasts as long as stopping, copying and checking take on your host. Time a rehearsal to agree the window.
  • You lose what changed since the last set. Back up as often as the data you can afford to lose requires.
  • A set restores only with its own release, loaded. Restore a set taken under an older release by loading that release first. A directory whose release was never loaded is refused; --unverified restores one installed --unverified, a build MockHub tests before bundling it.
  • A restore that fails partway leaves state/restore-incomplete, and install and backup refuse until the restore is run again and completes.
  • Losing every recovery key loses the kit. Without .env, stored credentials and authenticator secrets cannot be decrypted, and nothing recovers them.

Report a problem with this page