Guide
Backups and restore
What to back up on a Heimnull server, how to automate it, and how to restore onto the same or a new server.
What to back up
Section titled “What to back up”| What | How | Holds |
|---|---|---|
.env |
Copy it somewhere safe, once and after each change | Every secret, including HN_SECRET_KEY |
| PostgreSQL | pg_dump, daily (below) |
Users, configuration, attacks, mitigations, the audit log, notification history, the license |
| Configuration bundle | Configure → Export / import | Your configuration in a portable form, for another server |
| ClickHouse | Usually not backed up | Flow records and rollups: analytics data that ages out anyway |
Back up PostgreSQL
Section titled “Back up PostgreSQL”cd /opt/heimnullsudo docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" -Fc "$POSTGRES_DB"' > ~/heimnull-$(date +%F).pgdumpThis takes a consistent copy while Heimnull runs and writes it to your home directory. The dump holds password hashes and the encrypted secrets, so store it as carefully as .env.
To take one every night, create /etc/cron.d/heimnull-backup (cron runs it as root, so no sudo), and keep 14 days:
30 3 * * * root cd /opt/heimnull && mkdir -p /var/backups/heimnull && docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" -Fc "$POSTGRES_DB"' > /var/backups/heimnull/heimnull-$(date +\%F).pgdump && find /var/backups/heimnull -name '*.pgdump' -mtime +14 -deleteThen copy /var/backups/heimnull off the server with your usual backup tool.
Restore onto the same or a new server
Section titled “Restore onto the same or a new server”-
Install as in the install guide, but use your saved
.envinstead of runningenv-template: copy it to/opt/heimnull/.env(sudo chmod 600it). -
Start Heimnull once, so the databases exist, then stop the application:
cd /opt/heimnullsudo docker compose up -d --waitsudo docker compose stop heimnull -
Restore the dump:
sudo docker compose exec -T postgres sh -c 'pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --clean --if-exists' < ~/heimnull-2026-10-19.pgdump -
Start everything again:
sudo docker compose up -d --wait
Sign in with your usual account. Restore with the same Heimnull release the dump came from, or a newer one: migrations bring an older database forward, never back.
The configuration bundle
Section titled “The configuration bundle”Configure → Export / import downloads your configuration as one JSON file: networks, hostgroups, exporters, interfaces, classification rules, host names, saved searches, settings, BGP and notification routing.
- Without secrets (the default), it’s safe to keep in version control or send to someone helping you.
- With secrets, it also holds the users, API tokens (as hashes) and every stored secret in plain text. Export it that way only for a file you’ll keep somewhere safe.
It imports into any Heimnull server, including one with a different HN_SECRET_KEY. Use it to move your setup to a fresh server when you don’t need the attack history, or to copy a configuration between servers. From a script, an admin API token can fetch it from GET /api/config/export (see API).
Flow history (optional)
Section titled “Flow history (optional)”Flow records age out (30 days of raw flows by default), so most servers don’t back them up. To keep them anyway, stop the stack and copy the heimnull_hn-ch volume, or use ClickHouse’s own BACKUP command with a backup disk configured.