Skip to Content
mlab docs

Backup and restore

What a tprm.mlab.sh instance stores and where, the exact backup and restore commands, how to test a restore and what to save before an upgrade.

Run all commands from the directory that holds docker-compose.yml and .env.

What to back up

ItemWhereHoldsHow
MySQLmysql_data volume, database mlabtprmAll business data, users, SSO settings and client secrets, API keys, the signed license and the instance id.Logical dump (daily), plus volume snapshot
ClickHouseclickhouse_data volume, database mlabtprmActivity log (platform_activity, kept 365 days).Volume snapshot, or table export
DocumentsYour S3 bucket (or the silo_data volume)Contracts, annexes, amendments.Bucket replication / versioning, or volume snapshot
uploads volume/app_mlab_sh/uploadsProfile pictures.Volume snapshot
.env and docker-compose.ymlProject directoryLICENSE_KEY, database passwords, S3 keys, every setting.Copy to your secrets store
logs volume/app_mlab_sh/logRequest logs.Optional, per your retention policy

Backups hold secrets. The MySQL dump contains the SSO client secrets, the mlab.sh API key, password hashes and session identifiers, as well as all your compliance data. Encrypt it and restrict who can read it, as you do for .env.

The license itself needs no backup: the key is in .env, the signed license is in MySQL and is renewed from mlab.sh at the next hourly check.

MySQL: logical dump

Safe while the platform runs:

docker compose exec -T mysql sh -c \
  'mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --single-transaction --routines --triggers mlabtprm' \
  | gzip > mlabtprm-$(date +%F).sql.gz

Check the dump is complete: the last line must read -- Dump completed.

gunzip -c mlabtprm-$(date +%F).sql.gz | tail -1

ClickHouse: activity log

The activity log is one table. Export it while the platform runs:

docker compose exec -T clickhouse sh -c \
  'clickhouse-client --user "$CLICKHOUSE_USER" --password "$CLICKHOUSE_PASSWORD" \
   --query "SELECT * FROM mlabtprm.platform_activity FORMAT Native"' \
  | gzip > activity-$(date +%F).native.gz

BACKUP DATABASE works too once a backups disk is configured in ClickHouse.

Volume snapshots

A consistent copy of every volume needs the stack stopped. Volume names carry the compose project prefix (docker volume ls); tprm-mlab below is the quick start directory.

PROJECT=tprm-mlab
mkdir -p backup
docker compose stop
for v in mysql_data clickhouse_data uploads; do   # add silo_data if you run Silo
  docker run --rm -v "${PROJECT}_${v}":/v:ro -v "$PWD/backup":/b debian:bookworm-slim \
    tar czf "/b/${v}-$(date +%F).tgz" -C /v .
done
docker compose start

A filesystem or storage snapshot of /var/lib/docker/volumes (LVM, ZFS, a VM snapshot) taken while the stack is stopped is equivalent.

Documents on S3

The platform never lists the bucket: each document is a database record pointing at an object <S3_PREFIX>/<organisation>/contract/<contract>/<document>. A backup of the bucket and a backup of MySQL are only consistent with each other at the same point in time.

  • Turn on versioning on the bucket and keep previous versions at least as long as your MySQL backups. A document deleted in the platform is deleted from the bucket; versioning is what brings it back after restoring an older dump.
  • Or replicate the bucket to a second bucket or provider, on the same schedule as the dump.
  • With Silo, include silo_data in the volume snapshot above.

Restore

Prepare the host

Install Docker, copy docker-compose.yml and .env back into the project directory. Use the same image tag as the backup, or a newer one: migrations only move forward.

Restore MySQL

Start MySQL alone on an empty mysql_data volume; it creates the mlabtprm database and the application user from .env. Then load the dump:

docker compose up -d mysql
docker compose ps mysql        # wait for "healthy"
gunzip -c mlabtprm-2026-11-20.sql.gz | docker compose exec -T mysql sh -c \
  'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" mlabtprm'

Restore ClickHouse

From a volume snapshot, extract it into the empty volume before starting ClickHouse:

PROJECT=tprm-mlab              # your compose project name
docker compose create clickhouse
docker run --rm -v "${PROJECT}_clickhouse_data":/v -v "$PWD/backup":/b debian:bookworm-slim \
  tar xzf /b/clickhouse_data-2026-11-20.tgz -C /v

From a table export, start the whole stack first so the app creates the table, then insert:

docker compose up -d
gunzip -c activity-2026-11-20.native.gz | docker compose exec -T clickhouse sh -c \
  'clickhouse-client --user "$CLICKHOUSE_USER" --password "$CLICKHOUSE_PASSWORD" \
   --query "INSERT INTO mlabtprm.platform_activity FORMAT Native"'

Without either, the app creates an empty activity log: the business data is not affected.

Restore uploads and documents

Extract the uploads (and silo_data) archives the same way as clickhouse_data. For an external bucket, roll objects back to the dump's date, or point S3_ENDPOINT / S3_BUCKET at the replica.

Start and check

docker compose up -d
docker compose logs app | grep -E "Migrations completed|License guard"

Sign in, open a contract and download one of its documents. As an administrator, /api/v1/files/status?check=1 tests the bucket (see Documents).

Restore and the license

The instance id lives in MySQL, so a restored instance keeps the id, and the place, of the one it replaces. Don't run the old and the restored instance at the same time with the same key. A restore of an empty or foreign database gets a new instance id and needs a free place: see Places.

Test a restore

Restore on a separate host, or in a separate directory so compose uses another project name and other volumes. Two precautions keep the test from touching production:

.env of the test stack (example)
# Don't reach mlab.sh: the test runs on the kept license, without using a place
MLAB_LICENSE_URL=http://127.0.0.1:9
# Don't point at the production bucket: deleting a test document deletes the object
S3_ENDPOINT=
S3_BUCKET=

With mlab.sh unreachable, the instance runs on the signed license kept in the dump (status offline) while it is less than 7 days old; an older dump starts paused, and you check the data with SQL instead. To test documents, point the test stack at a copy of the bucket.

Then check, at least once a quarter:

docker compose exec mysql sh -c 'mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" mlabtprm \
  -e "SELECT MAX(version) FROM _migrations; SELECT COUNT(*) FROM users; SELECT COUNT(*) FROM organizations;"'

Compare the counts with production, sign in, and open the register.

Before an upgrade

Note the running image: docker compose images app.

Take the MySQL dump and the ClickHouse export above, or stop the stack and take the volume snapshots.

Read the release notes for migrations between your version and the target.

Upgrade. If you need to roll back after a migration, re-pin the old tag and restore MySQL (and ClickHouse) from these backups: schema migrations are not reversed automatically. See Rollback.

On this page