Skip to Content
mlab docs

Backup and restore

What to back up on an ir.mlab.sh host, the exact commands for the MySQL dump and volume archives, how to restore on a new host, and how to test a restore without disturbing production.

What to back up

ItemWhereWhyMethod
MySQL mlabirmysql_data volumeAlerts, cases, incidents, users, API keys, settings, the instance id and kept licencemysqldump (online) and/or volume archive
ClickHouse mlabirclickhouse_data volumeActivity log with its hash chain, playbook run history, CVE cacheVolume archive (stack stopped)
Evidence and avatarsuploads volumeFiles attached to cases and incidentsVolume archive
.envProject directoryLICENSE_KEY, INTERNAL_SECRET, database passwordsCopy, store as a secret
docker-compose.yml (+ overrides)Project directoryImage tags, port bindings, proxy labelsCopy
Request logs./logOptional, if you keep request historyCopy the files

The MySQL and ClickHouse passwords are stored inside the database volumes at first init. Restored volumes only work with the .env they were created with, so always back up .env together with the data.

.env and the MySQL dump are secrets. The dump holds password hashes, API keys, webhook and integration credentials. Encrypt backups at rest and restrict who can read them.

The examples assume the project directory ir-mlab from the Quick start. Compose prefixes volume names with the project name, so the volumes are ir-mlab_mysql_data, ir-mlab_clickhouse_data and ir-mlab_uploads. Check yours with:

docker volume ls --filter name=ir-mlab_

Online: MySQL dump

Safe while the platform runs (InnoDB, single transaction). Uses the root password already set in the mysql container, so it never appears on your command line.

cd ~/ir-mlab
mkdir -p backup
docker compose exec -T mysql sh -c \
  'exec mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --single-transaction --routines --triggers --databases mlabir' \
  | gzip > backup/mysql-mlabir-$(date +%F).sql.gz

Run it from cron at least daily. Check the file is not a few bytes long: a failed mysqldump still produces a gzip file.

gunzip -c backup/mysql-mlabir-$(date +%F).sql.gz | tail -n 1
# -- Dump completed on ...

Full: volume archives (stack stopped)

This is the only method on this page that captures ClickHouse. Stop the stack so files on disk are consistent, archive the three volumes, start again. Downtime is the time to copy the data.

cd ~/ir-mlab
mkdir -p backup
docker compose stop

for v in mysql_data clickhouse_data uploads; do
  docker run --rm \
    -v ir-mlab_${v}:/data:ro \
    -v "$PWD/backup":/backup \
    debian:bookworm-slim \
    tar czf /backup/${v}-$(date +%F).tar.gz -C /data .
done

cp .env docker-compose.yml backup/
docker compose up -d

Volume snapshots at the storage layer (LVM, ZFS, a cloud disk snapshot) are equivalent, provided the stack is stopped or the snapshot is crash-consistent across all three volumes at once.

ClickHouse's own BACKUP DATABASE ... TO Disk('backups', ...) needs a backups disk declared in the ClickHouse server configuration. The compose file does not mount one, so that command fails on a stock install unless you add the configuration yourself.

Restore on a new host

Stop the old instance if it still runs. The instance id lives in MySQL, so a restored copy is the same instance to mlab.sh; two copies running at once share one licence. See Licensing.

Recreate the project directory with the backed-up docker-compose.yml and .env, then create the volumes without starting anything:

mkdir -p ~/ir-mlab/log && cd ~/ir-mlab
cp /path/to/backup/{docker-compose.yml,.env} .
docker compose up --no-start

Fill the volumes from the archives:

for v in mysql_data clickhouse_data uploads; do
  docker run --rm \
    -v ir-mlab_${v}:/data \
    -v /path/to/backup:/backup:ro \
    debian:bookworm-slim \
    sh -c "cd /data && tar xzf /backup/${v}-YYYY-MM-DD.tar.gz"
done

tar restores numeric owners, so MySQL, ClickHouse and the mlab user in app find their files with the right ownership.

Start and watch the boot:

docker compose up -d
docker compose logs -f app

Wait for Server ready to accept connections. If the backup came from an older release than the image you start, pending migrations apply now.

Restoring from the MySQL dump only

Use this when ClickHouse and uploads are intact (or acceptable to lose) and only MySQL needs rolling back.

cd ~/ir-mlab
docker compose stop app executor
gunzip -c backup/mysql-mlabir-YYYY-MM-DD.sql.gz \
  | docker compose exec -T mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"'
docker compose up -d

The dump includes CREATE DATABASE and the _migrations table, so migrations already applied are not replayed. Rows created in ClickHouse after the dump (activity entries, playbook runs) will refer to records MySQL no longer has.

Test a restore

A backup you have never restored is a hope. Restore to a separate host or VM at least once a quarter, and always before relying on a new backup method.

Keep the test copy from talking to mlab.sh: it carries production's instance id and licence key. Point its licence check at an address that does not answer; it then runs on the licence kept in the database (valid up to 7 days after it was last issued) and never contacts mlab.sh.

# .env of the TEST copy only
MLAB_LICENSE_URL=http://127.0.0.1:9

Do not blank LICENSE_KEY instead: an empty key locks the console immediately.

Then verify:

docker compose logs app | grep -E 'License guard|Migrations completed|Server ready'
docker compose exec -T mysql sh -c \
  'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" mlabir -e "SELECT COUNT(*) FROM alerts; SELECT COUNT(*) FROM cases;"'

Compare the counts with production, sign in, open a recent case and download one evidence file. Destroy the test copy afterwards (docker compose down -v).

Before an upgrade

Schema migrations are not rolled back automatically. Before changing an image tag:

  1. Note the current tags in docker-compose.yml.
  2. Take a full volume backup (above). A MySQL dump alone is not enough if the release touches ClickHouse; check the changelog.
  3. Upgrade as described in Update.
  4. To roll back, restore the volumes from step 2 and re-pin the previous tags. Starting an older image on a newer schema is not supported.

On this page