Back up and restore Repod¶
Repod's relational data (users, manifests index, inventory, install jobs,
package search, SSH ssh_known_hosts fingerprints) lives in PostgreSQL
(DATABASE_URL, postgres_data volume). The filesystem under /repos/
holds everything else: package artifacts, manifests JSON, repo metadata
trees, GPG keyring, CVE caches, and audit logs. This guide explains what to
back up, how to run and schedule backup.sh, how to copy backups offsite,
and how to perform a full restore.
1. What to back up¶
| Data | Location | Importance | Notes |
|---|---|---|---|
| Application database | PostgreSQL (DATABASE_URL, postgres_data volume) |
Critical | Users, manifests index, inventory, install jobs, package search, TOFU SSH fingerprints. Back up with pg_dump -F c (custom format, restorable with pg_restore). |
| Settings | /repos/settings.json |
Critical | LDAP, OIDC, CVE policy, scheduler, mirror config. |
| GPG keyring | /repos/gnupg/ |
Critical | Private signing key. Loss means generating a new key and reconfiguring every client machine. |
| Generated secrets | /repos/secrets/ |
Critical | Keys Repod generated, including the one that signs the Alpine index. Without the first, encrypted settings cannot be read back; without the second, every Alpine client must import a new key. Included by backup.sh and the built-in backup. |
| Audit logs | /repos/audit/*.jsonl |
High | Append-only JSONL files, one per day. Needed for compliance and incident investigation. |
| Security/CVE data | /repos/security/ |
High | RSSI CVE review decisions and KEV/EPSS caches. |
| Stored SBOMs | /repos/sboms/ |
Medium | CycloneDX files kept at scan time and used to re-match new CVEs without re-opening the package. Included by backup.sh and the built-in backup. |
| Package manifests | /repos/manifests/ |
Medium | JSON metadata for each package. Can be rebuilt by re-indexing the package pool, but this takes time. |
| Maven, PyPI and npm storage | /repos/maven/, /repos/pypi/, /repos/npm/ |
Critical if you use them | The storage is the only copy of these artifacts (nothing can regenerate them). Included by backup.sh. |
| Container images | ./repos/oci/data (Zot) |
High if you use the registry | Not included by backup.sh nor by the built-in backup: they belong to another service. Back them up by volume snapshot. |
| APT index, reprepro database, RPM and Alpine trees | /repos/db/, /repos/dists/, /repos/conf/, /repos/rpm/, /repos/apk/ |
Critical | Nothing regenerates them from pool/. POST /distributions/init only writes conf/ and exports empty repositories. Without these directories a restored server has all its packages on disk and apt update sees none. Included in the archive by backup.sh and the built-in backup. |
| Package pool | /repos/pool/ |
Medium | .deb/.rpm/.apk canonical store. Large, but included by default by backup.sh. Can be rebuilt by re-uploading or re-importing packages from upstream. |
GPG keyring loss is painful
If you lose the GPG keyring without a backup, you must generate a new signing key and distribute it to every client machine that trusts your repository. This is a significant operational burden in large fleets. Treat the gnupg/ directory as critical infrastructure.
2. Using backup.sh¶
The backup.sh script is included at the root of the Repod repository. It
runs pg_dump against DATABASE_URL (custom format, -F c) and archives it
together with the critical /repos/ paths into a timestamped .tar.gz file.
Basic usage:
By default, the archive is written to ./backups/:
backups/repod_backup_20260601_020000.tar.gz
├── postgres.dump ← pg_dump -F c (all relational data)
├── pool/
├── settings.json
├── audit/
├── security/
├── manifests/
├── db/ dists/ conf/ ← reprepro database, APT index, distributions
├── rpm/ apk/ ← RPM and Alpine trees
├── maven/ pypi/ npm/ ← only the ones that exist
├── secrets/ ← generated keys (Alpine index signing key, ...)
└── gnupg/
Configuration via environment variables:
| Variable | Default | Description |
|---|---|---|
DATABASE_URL |
— | Required. PostgreSQL connection string. The script fails (fail()) if unset or if pg_dump is not installed — it never produces an archive without a database dump. |
BACKUP_DIR |
./backups |
Directory where archive files are written. |
REPOS_DIR |
./repos |
Directory holding the non-relational /repos/ data. |
BACKUP_RETENTION_DAYS |
30 |
Archives older than this many days are deleted automatically. Set to 0 to disable pruning. |
Example with custom paths:
DATABASE_URL=postgresql://repod:CHANGE_ME@localhost:5432/repod \
BACKUP_DIR=/mnt/nas/repod-backups \
BACKUP_RETENTION_DAYS=90 \
./backup.sh
Dry run — print what would be backed up without creating an archive:
Connecting to PostgreSQL from the host
The db service (PostgreSQL) is not published to the host by default.
Either temporarily publish container port 5432, or run pg_dump inside
the repod-db container and copy the dump out before archiving:
Legacy SQLite installs
If /repos/auth/users.db still exists (a pre-PostgreSQL-migration
install that hasn't been cleaned up), backup.sh also backs it up via
sqlite3 .backup for safety. Current installations do not have this file.
Built-in alternative
Repod also ships an admin-triggered backup that produces the same
archive format via the API (POST /api/v1/backup/) or the Sauvegarde page (Administration group of the sidebar), plus a daily scheduled job (backup_daily). See
Backup & Restore (operations) for
details on the integrated mechanism and restore procedure.
3. Scheduling with cron¶
Run backups automatically by adding an entry to the crontab of the user who owns the Repod data:
Add a daily backup at 02:00 UTC, logging output to a file:
# Repod daily backup — 02:00 UTC
0 2 * * * cd /opt/repod && DATABASE_URL=postgresql://repod:CHANGE_ME@localhost:5432/repod \
BACKUP_DIR=/mnt/nas/repod-backups BACKUP_RETENTION_DAYS=60 \
./backup.sh \
>> /var/log/repod-backup.log 2>&1
Verify the cron job is registered:
Check the log after the first scheduled run:
Tip
Rotate the log file with logrotate to prevent it from growing unbounded. Create /etc/logrotate.d/repod-backup with a weekly rotation and 4-week retention policy.
4. Offsite copy¶
A backup that lives on the same host as the data it protects is not a real backup. Copy archives to a separate location after each run.
# Add this after ./backup.sh in your cron job, or in a wrapper script
rsync -avz --delete \
/mnt/nas/repod-backups/ \
[email protected]:/volume1/backups/repod/
Use SSH key authentication so this runs unattended. Restrict the NAS user to SFTP and the backup directory.
Tip
For S3-compatible targets, enable object versioning or object lock on the bucket so that a ransomware event on the Repod host cannot overwrite your offsite copies.
5. Restore procedure¶
Follow these steps to restore Repod from a backup archive. Read through the entire procedure before you start.
Step 1 — Stop the stack
Step 2 — Identify and extract the archive
ls -lht /mnt/nas/repod-backups/
# Pick the most recent clean backup, e.g.:
ARCHIVE=repod_backup_20260601_020000.tar.gz
mkdir -p /tmp/repod-restore
tar -xzf /mnt/nas/repod-backups/$ARCHIVE -C /tmp/repod-restore
ls /tmp/repod-restore/
Step 3 — Restore the PostgreSQL database
docker compose up -d db
sleep 5 # wait for PostgreSQL to accept connections
# --clean --if-exists drops and recreates objects safely on an empty database
BACKUP_NAME="${ARCHIVE%.tar.gz}"
docker exec -i repod-db pg_restore -U repod -d repod --clean --if-exists \
< "/tmp/repod-restore/$BACKUP_NAME/postgres.dump"
Step 4 — Copy /repos/ data back
The volume mount paths depend on your docker-compose.yaml. Adjust the destination paths to match your setup:
RESTORE_DIR="/tmp/repod-restore/$BACKUP_NAME"
# Settings
cp "$RESTORE_DIR/settings.json" /opt/repod/repos/settings.json
# Audit logs (merge, not overwrite, to preserve any logs written since the backup)
cp -n "$RESTORE_DIR"/audit/*.jsonl /opt/repod/repos/audit/
# GPG keyring
rm -rf /opt/repod/repos/gnupg/
cp -r "$RESTORE_DIR/gnupg/" /opt/repod/repos/gnupg/
chmod 700 /opt/repod/repos/gnupg/
# Generated secrets (keep the permissions)
[ -d "$RESTORE_DIR/secrets" ] && cp -rp "$RESTORE_DIR/secrets/." /opt/repod/repos/secrets/
# Manifests, security data, package pool
cp -r "$RESTORE_DIR/manifests/." /opt/repod/repos/manifests/
cp -r "$RESTORE_DIR/security/." /opt/repod/repos/security/
cp -r "$RESTORE_DIR/pool/." /opt/repod/repos/pool/
# APT index and reprepro database, RPM and Alpine trees, Maven, PyPI and npm storage
# (only the directories present in the archive)
for d in db dists conf rpm apk sboms maven pypi npm; do
[ -d "$RESTORE_DIR/$d" ] && cp -r "$RESTORE_DIR/$d/." "/opt/repod/repos/$d/"
done
Warning
Set the correct ownership on restored files before starting the containers. If the backend container runs as a non-root user (UID 1000 by default), ensure the restored files are owned by that UID: chown -R 1000:1000 /opt/repod/repos/
Step 5 — Start the stack
Nothing has to be regenerated: the APT index (db/, dists/, conf/) and the RPM and Alpine trees came back with the archive in step 4, and the backend recognises a complete conf/distributions at startup.
An archive made by an earlier version has no APT index
Archives created before this change contain pool/ but not db/, dists/ or conf/. Restored as they are, the repository is empty: the packages are on disk but reprepro knows none of them, and POST /distributions/init does not add them back (it only writes the configuration and exports empty repositories). There is no tested procedure to rebuild the index from pool/ and the manifests. scripts/rebuild-apt-db.py exists, but it was written for the former flat pool layout and has not been validated against the current one. Take a new backup now, with this version, so that your next restore is complete.
The backup briefly locks reprepro
To copy db/ and dists/ in the same state, the backup creates db/lockfile for the few seconds the copy takes and always removes it afterwards. An upload or import that starts in that instant fails and can simply be retried. If the lock cannot be taken within 30 seconds, the backup fails with a clear message instead of saving a possibly inconsistent copy. If that message appears while nothing is running, db/lockfile is a stale file: delete it.
Step 6 — Verify
# Check all containers are healthy
docker compose ps
# Confirm the API responds
curl -s http://localhost:8000/health | jq .
# Confirm packages are visible
curl -s -H "Authorization: Bearer $TOKEN" \
"http://localhost:8000/api/v1/artifacts/?distribution=jammy&per_page=1" | jq '.total'
# Test apt update on a client machine
sudo apt update
6. Testing restores¶
A backup you have never tested is a backup you cannot trust.
Test restores quarterly using this checklist:
- Spin up a separate VM or container with a clean Docker installation.
- Copy the most recent backup archive to the test VM.
- Follow the restore procedure above on the test VM.
- Confirm the API returns the expected package count.
- Confirm
apt update(ordnf/zypper/apk update) succeeds against the test instance. - Confirm the web UI is accessible, login works, and settings look correct.
- Document the time taken from archive copy to verified restore.
Record the results in your operations runbook. If a restore takes longer than your RTO (recovery time objective), investigate whether the archive size, network speed, or procedure can be optimised.
7. GPG keyring warning¶
Lost GPG backup = mandatory key rotation
If your restore fails because the GPG keyring backup is missing or corrupted, you cannot recover the original signing key. You must:
- Generate a new GPG key via Administration → Paramètres, section Clé GPG du dépôt, bouton Générer une nouvelle clé.
- Distribute the new public key to every client machine.
- Remove the old key from every client machine's trusted keyring (
/etc/apt/trusted.gpg.d/,rpm --import,/etc/apk/keys/, depending on format).
This is a significant effort in large fleets. See GPG signing keys for how the key is served and trusted. Preventing this situation by verifying your gnupg/ backup is included in every archive is strongly recommended.