Skip to content

Backups & Restore

TrixOS keeps all of its state in Postgres. Two things need a backup:

  1. The database, nightly.
  2. The .env file, once and after every change. It holds TRIXOS_MASTER_KEY, which decrypts the BMC, switch and webhook credentials stored in the database. A database backup without the key restores everything except those credentials.

Keep .env out of the nightly backup, for example in your password manager, so that a stolen backup file alone doesn’t reveal credentials.

The repository contains deploy/hosts/trixos-backup. Installed as /usr/local/sbin/trixos-backup with a systemd timer, it writes a compressed dump every night and keeps 14 days:

#!/bin/bash
set -euo pipefail
umask 077
f=/var/backups/trixos/trixos-$(date +%F-%H%M).dump
docker compose --project-directory /opt/trixos exec -T postgres pg_dump -U trixos -d trixos -Fc > "$f"
find /var/backups/trixos -name "trixos-*.dump" -mtime +14 -delete

Copy the dumps off the host. A good pattern is a write-only target: the panel may upload but not read or delete (for example rrsync -wo on the target), so a compromised panel can’t destroy its own backups.

Terminal window
cd /opt/trixos
docker compose stop api worker poller assets viewer
docker compose exec -T postgres pg_restore -U trixos -d trixos --clean --if-exists < /var/backups/trixos/<file>.dump
docker compose up -d

Use the .env (master key) that belonged to the installation the dump came from.

Restore the newest dump into a scratch database every few months and open the panel against it. A backup you haven’t restored is a guess.