Last updated: March 22, 2026

Step 9 - Backup and Restore Authentik

Authentik stores everything in PostgreSQL. Back it up with pg_dump:

#!/bin/bash
/usr/local/bin/backup-authentik.sh
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backups/authentik"
mkdir -p "$BACKUP_DIR"

Dump PostgreSQL from the authentik-postgresql container
docker exec authentik-postgresql-1 pg_dump -U authentik authentik \
  | gzip > "${BACKUP_DIR}/authentik-db-${DATE}.sql.gz"

Also backup the media directory (profile pictures, certificates)
tar czf "${BACKUP_DIR}/authentik-media-${DATE}.tar.gz" \
  /opt/authentik/media/ 2>/dev/null || true

Retain last 30 backups
find "$BACKUP_DIR" -name "*.sql.gz" -o -name "*.tar.gz" | sort | head -n -30 | xargs rm -f

echo "Authentik backup complete: ${BACKUP_DIR}/authentik-db-${DATE}.sql.gz"

Restore:

Stop Authentik, restore the DB, restart
docker compose -f /opt/authentik/docker-compose.yml stop server worker

gunzip -c /backups/authentik/authentik-db-20260322_120000.sql.gz | \
  docker exec -i authentik-postgresql-1 psql -U authentik authentik

docker compose -f /opt/authentik/docker-compose.yml start server worker

Related Reading

Related Articles