authcha learn

Learn / Operations

Backups, restores and the restore drill

Module 2 of 6 · 30 minutes

By the end you can

  • List the scheduled jobs and what each one protects
  • Name what is not in a backup and must be saved separately
  • Restore a backup onto the same host
  • Run and read the restore drill

Two kinds of backup

Authcha takes two independent database backups. Both contain everything in PostgreSQL: users, devices, policies, accounting, audit log and license.

Scheduled backups on the host

The installer sets up these jobs in /etc/cron.d/authcha.

JobWhenWhat it does
BackupEvery 6 hoursWrites a compressed dump, radius-<timestamp>.dump, to /opt/authcha/backups/ with a .sha256 file. Next to it: the RADIUS certificate volume (including the server key), the RADIUS clients and saved site policies, and a small text file with the version and a short fingerprint of the encryption key. Files older than 14 days are removed. .env is not included.
Restore drillSundays 02:00Restores the latest dump into a temporary database, checks the key tables are filled, checks the archives, and proves that the key in .env can decrypt every encrypted secret in the restored copy. Then it deletes the temporary database
Audit retentionDaily 03:00Archives security logs older than 180 days, then removes them from the database

Run them yourself whenever you like:

sudo authcha backup                         # back up now
sudo authcha backup verify                  # drill the newest dump

Console backups

The console also writes a daily compressed SQL backup to its own storage and keeps it for 30 days by default (BACKUP_RETENTION_DAYS; 0 turns it off). List and download them under System → Automated backups. Backup database on the same page downloads a fresh one at any moment. Do this before every upgrade.

What you must back up yourself

WhatWhy
The backups/ directoryThe scheduled backups live on the same host. Copy them off it. Set BACKUP_OFFSITE_PATH=backup@host:/srv/authcha-backups/ and every dump is synced there with rsync over SSH
.env and otp.envThey hold every bootstrap secret and are not in the database backup. Store them encrypted. PKI_KEY_ENCRYPTION_KEY matters most: without it, the certificate authority keys, identity-provider signing keys and MDM secrets in every backup cannot be read
Your own TLS certificate and keyIn /opt/authcha/config/tls/, if you supplied them
Audit archivesIn backups/audit-archive/, if regulations require logs beyond the retention window

Restore

Stop the services that use the database and make an empty one:

cd /opt/authcha
docker compose stop admin freeradius
docker compose exec db dropdb -U radius radius
docker compose exec db createdb -U radius radius

Load a scheduled backup, after checking its checksum:

sha256sum -c backups/radius-20260901T000000Z.dump.sha256
docker compose exec -T db pg_restore -U radius -d radius --no-owner --no-acl --exit-on-error \
  < backups/radius-20260901T000000Z.dump

A console backup (.sql.gz) loads with gunzip -c file | docker compose exec -T db psql -U radius -d radius -q -v ON_ERROR_STOP=1.

Then put back the RADIUS certificates from the matching archive, put the same PKI_KEY_ENCRYPTION_KEY back in .env, recreate every container (do not just restart) and check the key:

docker compose up -d --force-recreate
sudo authcha kek-check

kek-check prints how many items of each kind it decrypted. If it fails, the key in .env is not the one the backup was made with.

The restore drill

A backup is only worth what a restore proves. Run the drill after installing, after every upgrade and at least once a quarter.

  1. sudo authcha backup, and wait.
  2. sudo authcha backup verify. It must end with drill PASSED.
  3. At least once, restore for real onto a spare host with the escrowed key, run sudo authcha kek-check, sign in and authenticate one 802.1X client. Write down the date and the result.

The weekly job does step 2. If it warns KEK not verified, the admin image or .env was not available to it. Fix that, because a drill that skips the key check can pass on a backup you could not actually use. Check its log now and then:

tail -n 20 /var/log/authcha-restore-drill.log

LabHands-on

Needs your own install (or a test VM).

  1. Run sudo authcha backup. List /opt/authcha/backups/ and find the dump, its .sha256 and the companion files.
  2. Open System → Automated backups in the console and download the newest one.
  3. Run sudo authcha backup verify. Confirm drill PASSED.
  4. Check the weekly drill's log with tail -n 20 /var/log/authcha-restore-drill.log.
  5. Set BACKUP_OFFSITE_PATH to another host you control, recreate the admin service, run a backup and confirm the files arrive there.
  6. On a spare host with the same Authcha version, do a full restore with the escrowed key. Run sudo authcha kek-check, sign in and write down the date.

Check yourselfQuiz

1What is NOT in the database backup?
2How often do scheduled backups run?
3What does drill PASSED prove?
4After a restore you run kek-check and it fails. What is the likely cause?
5Why should you copy backups off the host?

Cheat sheetKeep this

  • Scheduled: backup every 6 h, drill Sundays 02:00, audit retention daily 03:00. Kept 14 days on the host.
  • Console backup: daily, 30 days, under System → Automated backups.
  • Now: sudo authcha backup, sudo authcha backup verify.
  • Not in the backup: .env, otp.env, your TLS key. Escrow the encryption key separately.
  • Restore: stop admin freeradius, drop and create the database, pg_restore, restore certs, same key, recreate everything, sudo authcha kek-check.
  • Drill after install, after each upgrade, and at least quarterly. Do one real restore.
  • Read more: Operations.