Back up and restore
Back up every store of the XTM stack together, with an Elasticsearch snapshot, PostgreSQL dumps and copies of the other volumes, and restore them on an empty deployment.
This page backs up a Docker Compose deployment of the XTM stack, FiligranHQ/xtm-docker, and restores it on an empty one. You get one consistent backup of all its data: the knowledge in Elasticsearch, the databases in PostgreSQL, the files in S3 storage, the other volumes and the secrets. The platforms are stopped during the backup, so plan a maintenance window.
- Elasticsearch → es-snapshots.tar.gz: snapshot
- PostgreSQL → Database dumps: pg_dump
- Other volumes → Volume archives: copy while stopped
- Secrets → File copies: copy
- es-snapshots.tar.gz → Outside storage
- Database dumps → Outside storage
- Volume archives → Outside storage
- File copies → Outside storage
What to back up
The data of the stack lives in six Docker volumes and one file. Their names start with COMPOSE_PROJECT_NAME from .env (xtm in .env.sample), for example xtm_esdata.
| What | Where | Holds | Backed up with |
|---|---|---|---|
| Elasticsearch | Volume esdata | The knowledge of OpenCTI and OpenAEV and its indices | A snapshot |
| PostgreSQL | Volume pgsqlshareddata | The openaev, opencrq and xtm_one databases | pg_dump |
| S3 storage (RustFS) | Volume s3data | The files of OpenCTI, OpenAEV, OpenCRQ and XTM One | A copy of the volume |
| Redis | Volume redisdata | Cache, sessions and live events | A copy of the volume |
| RabbitMQ | Volume amqpdata | The queues and the messages waiting in them | A copy of the volume |
| XTM Composer key | Volume rsakeys | The RSA key XTM Composer encrypts the integrations' configurations with | A copy of the volume |
| Secrets | File .env | Passwords, tokens and the encryption keys of the platforms | A copy of the file |
The platforms encrypt part of their data with keys from .env, such as OPENCTI_ENCRYPTION_KEY, OPENAEV_ADMIN_ENCRYPTION_KEY and XTM_ONE_SECRET_KEY, and XTM Composer with the key in rsakeys. Data restored without the same keys cannot be read. Keep the backup as safe as the secrets it holds.
Why everything is backed up together
A platform keeps one piece of information in several stores. OpenCTI writes an imported file to S3 storage and indexes it in Elasticsearch; OpenAEV and XTM One keep their records in PostgreSQL and their files in S3 storage. Stores backed up at different times disagree after a restore: a record points to a file that is missing, or the other way round. So the procedure below stops everything that writes, the platforms, their workers and the integrations, then backs up every store at the same point in time.
Elasticsearch does not support restoring from a copy of its data folder, even a stopped one: back it up with a snapshot. The other volumes are copied while their service is stopped.
Before you start
- The stack runs and is healthy: see Check that the platforms are healthy.
- Free disk space for the backup: about the size of the six volumes.
docker system df -vgives their size. - A snapshot repository for Elasticsearch, prepared once as below.
A stack with XTM One alone has no Elasticsearch and no RabbitMQ: skip the steps about Elasticsearch.
Prepare the snapshot repository
Elasticsearch writes snapshots to a folder declared in its path.repo setting. These steps make a folder es-snapshots, in the xtm-docker folder, that repository.
-
Create the folder. Elasticsearch runs as user
1000and group0in its container, and needs to write to it.mkdir -p es-snapshots chmod g+rwx es-snapshots sudo chgrp 0 es-snapshots -
Declare it in
docker-compose.override.yml, as Change the stack without editing docker-compose.yml describes. If the file exists, add theelasticsearchpart to it.services: elasticsearch: environment: - path.repo=/usr/share/elasticsearch/snapshots volumes: - ./es-snapshots:/usr/share/elasticsearch/snapshots -
Recreate Elasticsearch, then register the repository under the name
xtm-backup.docker compose up -d --wait elasticsearch docker compose exec elasticsearch curl -s -X PUT http://localhost:9200/_snapshot/xtm-backup \ -H 'Content-Type: application/json' \ -d '{"type":"fs","settings":{"location":"/usr/share/elasticsearch/snapshots"}}'Check that it workedIt answers
{"acknowledged":true}.
Back up the stack
Run every command from the xtm-docker folder.
-
Create the backup folder and record the versions you run: restore on the same ones.
mkdir -p backup git rev-parse HEAD > backup/xtm-docker-commit.txt docker compose images > backup/images.txt -
Stop everything that writes: every service except the stores.
docker compose stop $(docker compose config --services | grep -vxE 'elasticsearch|pgsql|redis|minio|rabbitmq|rsa-key-generator')Check that it workeddocker compose ps --format '{{.Service}}'It lists only stores:
elasticsearch,pgsql,redis,minio,rabbitmq, andrsa-key-generatorif XTM Composer is deployed. -
Take an Elasticsearch snapshot of all the indices.
docker compose exec elasticsearch curl -s -X PUT \ "http://localhost:9200/_snapshot/xtm-backup/snapshot-$(date +%Y%m%d-%H%M%S)?wait_for_completion=true"Check that it workedThe answer contains
"state":"SUCCESS". -
Dump the three PostgreSQL databases.
docker compose exec -T pgsql sh -c 'pg_dump -U "$POSTGRES_USER" -Fc openaev' > backup/openaev.dump docker compose exec -T pgsql sh -c 'pg_dump -U "$POSTGRES_USER" -Fc opencrq' > backup/opencrq.dump docker compose exec -T pgsql sh -c 'pg_dump -U "$POSTGRES_USER" -Fc xtm_one' > backup/xtm_one.dumpCheck that it workedls -l backup/*.dumpThe three files exist and are not empty.
-
Have Redis write its data to disk, then stop the stores.
docker compose exec redis redis-cli SAVE docker compose stopRedis answers
OK. -
Copy the other volumes, each into an archive.
set -a; . ./.env; set +a for v in s3data redisdata amqpdata rsakeys; do docker volume inspect "${COMPOSE_PROJECT_NAME}_$v" >/dev/null 2>&1 || continue docker run --rm -v "${COMPOSE_PROJECT_NAME}_$v:/data:ro" -v "$PWD/backup:/backup" \ alpine:3.20 tar -czf "/backup/$v.tar.gz" -C /data . doneThe loop skips a volume your modules do not create, such as
rsakeyswithout XTM Composer. -
Copy the secrets, the override file and the snapshot repository.
cp .env docker-compose.override.yml backup/ tar -czf backup/es-snapshots.tar.gz es-snapshots -
Start the stack again.
docker compose up -dCheck that it workeddocker compose ps --format '{{.Service}} {{.Health}}' | grep -E '^(opencti|openaev|xtm-one|opencrq) 'Each platform you run says
healthyafter a few minutes.
Move the backup folder to storage outside the machine.
Elasticsearch snapshots are incremental: each one stores only what changed since the previous ones in the same repository, so es-snapshots grows slowly. Delete a snapshot you no longer need with docker compose exec elasticsearch curl -s -X DELETE http://localhost:9200/_snapshot/xtm-backup/<name>, never by deleting files from the folder.
Restore the stack
The restore puts a backup back on an empty deployment: a new machine, or the same one after docker compose down -v.
Restore before the platforms ever start on the new deployment. A platform that starts on empty stores creates its own data, and the restore then fails or mixes the two.
-
Get the same version of xtm-docker, and put the backup in it.
git clone https://github.com/FiligranHQ/xtm-docker.git cd xtm-docker git checkout "$(cat /path/to/backup/xtm-docker-commit.txt)" cp -r /path/to/backup ./backup cp backup/.env backup/docker-compose.override.yml . tar -xzf backup/es-snapshots.tar.gz chmod -R g+rwX es-snapshots && sudo chgrp -R 0 es-snapshotsReplace
/path/to/backupwith the folder of your backup. -
Create the containers and the volumes, without starting anything.
docker compose create -
Put the copied volumes back.
set -a; . ./.env; set +a for v in s3data redisdata amqpdata rsakeys; do [ -f "backup/$v.tar.gz" ] || continue docker run --rm -v "${COMPOSE_PROJECT_NAME}_$v:/data" -v "$PWD/backup:/backup:ro" \ alpine:3.20 tar -xzf "/backup/$v.tar.gz" -C /data done -
Restore PostgreSQL.
xtm-one-db-initfirst creates the XTM One role, its database and the pgvector extension, andopencrq-db-initthe OpenCRQ database, then each database is restored.docker compose up -d --wait pgsql docker compose run --rm xtm-one-db-init docker compose run --rm opencrq-db-init docker compose exec -T pgsql sh -c 'pg_restore -U "$POSTGRES_USER" -d openaev' < backup/openaev.dump docker compose exec -T pgsql sh -c 'pg_restore -U "$POSTGRES_USER" -d opencrq' < backup/opencrq.dump docker compose exec -T pgsql sh -c 'pg_restore -U "$POSTGRES_USER" -d xtm_one' < backup/xtm_one.dump -
Start Elasticsearch, register the repository and list its snapshots.
docker compose up -d --wait elasticsearch docker compose exec elasticsearch curl -s -X PUT http://localhost:9200/_snapshot/xtm-backup \ -H 'Content-Type: application/json' \ -d '{"type":"fs","settings":{"location":"/usr/share/elasticsearch/snapshots"}}' docker compose exec elasticsearch curl -s "http://localhost:9200/_cat/snapshots/xtm-backup?v" -
Restore the snapshot you choose, with its indices, index templates and lifecycle policies. Replace
<snapshot>with its name from the list.docker compose exec elasticsearch curl -s -X POST \ "http://localhost:9200/_snapshot/xtm-backup/<snapshot>/_restore?wait_for_completion=true" \ -H 'Content-Type: application/json' \ -d '{"indices":"*","include_global_state":true}'Check that it workedThe answer gives the restored indices with
"failed":0inshards. -
Start the stack.
docker compose up -dCheck that it workedEach platform says
healthyindocker compose ps, and shows the data you had when you took the backup.
Restore on the image versions of backup/images.txt. If you start newer images, the platforms migrate the restored data as they would during an upgrade: see Upgrade.
What's next
- Upgrade: take a backup before every upgrade.
- Manage Elasticsearch indices, how OpenCTI organizes its Elasticsearch indices.
- Harden the deployment, to protect the secrets and the stores.