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.
Before the first backup
Section titled “Before the first backup”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:
-
Make a key pair, and keep
mockhub-kit.keysafe on your machine:Terminal window openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out mockhub-kit.keyopenssl pkey -in mockhub-kit.key -pubout -out ops.pem -
Copy the public half,
ops.pem, intorecovery-recipients/in the installation directory. Only files ending in.pemcount, and the name before it, hereops, 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 PEMFix or remove that file, then run the backup again.
Take a backup
Section titled “Take a backup”-
Agree the window: MockHub is unavailable for the backup, and anything changed after it is not in it.
-
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.
Result
Section titled “Result”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.encwith.env,tls/and the edge’s certificates and keys. - A
MANIFESTnaming the release, the images, the volumes in restore order, what was left out and the pending work, andSHA256SUMS. 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.
Schedule backups
Section titled “Schedule backups”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.
Restore a set
Section titled “Restore a set”-
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
.envnames, and the image that writes the data, against the release’s manifest - whether this host’s
.envdiffers 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.
Restore on a new host
Section titled “Restore on a new host”-
On the new host, copy in the
dist/files of the same release the set was taken from, and run./mockhub loadwith its bundle. -
Copy the set and a recovery key to the host.
-
Run
./mockhub restoreas above, withoutinstall:.envcomes from the kit. -
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.
Limits
Section titled “Limits”- 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;
--unverifiedrestores one installed--unverified, a build MockHub tests before bundling it. - A restore that fails partway leaves
state/restore-incomplete, andinstallandbackuprefuse 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.