# Backups

# Backups

Drillmark stores everything in Postgres: parsed records, raw report blobs, tenants, data sources, alert state. Back up the database and the environment configuration together.

## What to back up

- The Postgres database named in `DATABASE_URL` (the sample stack uses the `dmarc_reporter` database owned by `dmarc_reporter`).
- The `.env` file and `compose.yml` on the host.
- The IP2Location LITE binary file if `IP2LOCATION_DB_PATH` is set. The file is reproducible from the public download, so re-downloading is also an option.

## What NOT to back up

- The `api` container image. Rebuildable from source.
- The Caddy configuration if stock. Rebuildable from `oci-build/Caddyfile`.

## ENCRYPTION_KEY

Back up `ENCRYPTION_KEY` the same way you back up the database, and keep the two paired. The key decrypts `data_sources.encrypted_password` and `data_sources.oauth_refresh_token_enc`; a database restored under a different key cannot recover source credentials, and there is no online rotation path. Operators must disable every source, change the key, and re-enter credentials on each source.

## Postgres backup

Any standard Postgres backup method works. From the host running the stack:

```
docker compose exec --no-TTY db pg_dump --username=dmarc_reporter --format=custom dmarc_reporter > drillmark-$(date --utc +%Y%m%dT%H%M%SZ).dump
```

Restore into a fresh database with `pg_restore --clean --if-exists --username=dmarc_reporter --dbname=dmarc_reporter drillmark-*.dump`.

For continuous backups, use base backups plus WAL archiving (or a managed Postgres), same as for any Postgres workload. Drillmark adds no special requirements here.

## Blob size

Raw report blobs dominate database size. See [retention](/docs/drillmark/operations/retention) for how to bound the growth.
