Backup and restore¶
Take a config archive on a schedule, and restore one as a single validated revision.
GET /api/backup returns a gzip-compressed tar of the declarative config
only: every object YAML under config/<kind>/ plus config/settings.yaml.
It does not include .git history (that's what git clone/git bundle
the config repo is for, if you want commit history too), the certs/
directory, or session.db. It needs the admin scope specifically, not
*:read: unlike the JSON API, the raw YAML carries the api-tokens
directory's stored digests, which are offline-crackable.
Because backup is admin-scoped, there is no narrower "backup:read" token you
can hand to a cron job: an automation credential that can back up the config
can, by the same scope, do everything else admin can. Mint one deliberately
for this and nothing else, and treat it with the same care as the break-glass
password:
sudo install -m 0400 -o gpm -g gpm /dev/null /etc/gpm/backup_auth
curl -s -X PUT https://<admin>/api/api-tokens/backup-cron \
-b "<admin session cookie>" -H "X-CSRF-Token: <token from /api/me>" \
-H 'Content-Type: application/json' \
-d '{"scopes":["admin"]}' \
| jq -r '"Authorization: Bearer " + .token' | sudo tee /etc/gpm/backup_auth >/dev/null
The token is shown once; this writes it straight into an owner-only file as a ready-made header line, so it never passes through the terminal or a command line.
Cron:
# /etc/cron.d/gpm-backup - runs as the gpm user
0 3 * * * gpm curl -fsS -H @/etc/gpm/backup_auth \
https://<admin>/api/backup \
-o /var/backups/gpm/gpm-config-$(date +\%Y-\%m-\%dT\%H\%M\%S).tar.gz \
&& find /var/backups/gpm -name 'gpm-config-*.tar.gz' -mtime +30 -delete
-H @file makes curl read the header from the file, so the token does not show
up in the process list. https://<admin> is the admin panel's HTTPS hostname
(Reach the admin UI through gpm itself): the
admin listener on :8081 is plain HTTP, so a token sent to it from another
host crosses the network in clear text.
(A systemd timer works the same way if you'd rather not use cron: a
Type=oneshot service running the same curl line, triggered by an
OnCalendar= timer unit.) % needs escaping as \% in a crontab; a plain
shell script invoked by cron doesn't have that gotcha.
Restore replaces the entire current config, validates the result, and commits it as one revision. If the archive doesn't validate (a dangling reference, including one a discovery template or profile names, a literal un-placeholdered secret, a corrupt/oversized upload) the working tree is rolled back to the pre-restore commit and nothing is committed: a bad restore attempt is a no-op, not a half-applied one:
curl -fsS -X POST https://<admin>/api/restore \
-H "Authorization: Bearer gpm_<admin-scoped-token>" \
-H 'Content-Type: application/gzip' \
--data-binary @gpm-config-2026-08-22T030000.tar.gz
Max upload size is 8MB gzipped. X-Config-Commit in the response header (and
.commit in the JSON body) names the new commit, so a restore is itself
revertible with POST /api/revert like any other change.
What a restore does not bring back, and what to plan for separately:
certs/: acustom-typeCertificatereferences cert/key files by relative path in that directory; restoring config that names one does not restore the files themselves. Back upcerts/alongside the config archive (a plain file copy, it isn't git-backed) if you use custom certificates, and copy it back beforePOST /api/restore: a restore whose config names custom certificate files that do not load is refused and nothing is committed (see Writes must compile).acme-type certificates need nothing extra: DNS-01 credentials round-trip in the restoredDNSProvider/Certificateobjects, and gpm re-issues on next load if the on-disk artifact is missing.session.db: restoring config never touches it; every admin session active at restore time stays valid (or invalid) exactly as it was before.api-tokensare never brought back from an archive: a restore keeps the instance's live tokens and ignores the archive's token files (logged asrestore: archive api-token files ignored), the same rule as Revert, for the reason in APIToken. Restoring onto a fresh instance therefore leaves it with no tokens: re-mint the ones your automation needs (backup cron, metrics scrapers) afterwards.
Symbolic links (see Symbolic links):
- Backup archives a link that resolves inside the config directory as the regular file it names. A link that resolves outside it, or not at all, fails the backup with an error naming the file.
- Restore writes regular files only: a symbolic-link or hard-link entry is
skipped and logged (
restore: archive entry is a link, not a regular file; skipped), so its file is missing from the result. A restore never removes or writes a file through a kind directory that links outside the config directory: it is refused instead.
Verify a backup is actually restorable periodically, not just that the cron
job exits 0: a GET/POST /api/restore round trip against a disposable
test instance is the only thing that proves the archive is usable, the same
way an untested backup anywhere else is a hope, not a backup.
Analytics rollups¶
analytics.db (GPM_ANALYTICS_DB, default /data/analytics.db) holds the hourly
traffic rollups behind the Analytics view's 7d and 30d ranges. It is runtime data, not
config: it is not part of GET /api/backup, and losing it costs history only (the
collector starts a fresh file). Copy it with the data directory if the history matters;
stop gpm first or copy the -wal and -shm files with it. A release can rebuild the
file's schema on first start (the upgrade notes say when); a copy taken
before the upgrade is the only way back to the previous release with history intact.