Backup and Restore¶
Everything in the database can be regenerated from the OSM extract. What cannot be regenerated is your configuration.
What to back up¶
| Data | Location | Backup needed? |
|---|---|---|
| OSM playground data | pgdata Docker volume |
Optional — re-importable from PBF |
| PBF cache | pbf_cache Docker volume |
Optional — re-downloadable from Geofabrik |
| Configuration | .env file |
Yes — contains your passwords and settings |
Custom registry.json |
your deployment directory | Yes (if Hub mode) |
The most important thing to back up is your .env file. The database can always be rebuilt from the Geofabrik PBF (how long that takes). A lost .env means a lost POSTGRES_PASSWORD and requires recreating the stack from scratch.
Back up the database¶
For a hot backup (database running):
For a cold backup (database stopped), or to back up the raw volume:
docker compose --profile data-node-ui stop db
# Copy the volume to a compressed tar
docker run --rm \
-v spieli_pgdata:/data \
-v $(pwd):/backup \
alpine tar czf /backup/pgdata-$(date +%Y%m%d).tar.gz -C /data .
docker compose --profile data-node-ui start db
Replace spieli_pgdata with the actual volume name (docker volume ls to find it; typically <project-name>_pgdata).
Restore the database¶
From a pg_dump backup:
# Stop the stack, recreate the DB volume, then restore
docker compose --profile data-node-ui down
docker volume rm spieli_pgdata # ⚠️ destroys all data — only run if you have a backup!
docker compose --profile data-node-ui up -d db
# Wait for the DB to initialise (watch `docker compose logs -f db`)
# Restore
gunzip -c spieli-backup-20260501.sql.gz | docker compose exec -T db psql -U osm osm
# Apply the API schema (recreates PostgREST functions + materialised view).
# API_ONLY matters: without it this would be a full import that overwrites the restored data.
docker compose --profile data-node-ui run --rm -e API_ONLY=1 importer
# Restart the full stack
docker compose --profile data-node-ui up -d
Re-import instead of restoring¶
Because the PBF is re-downloadable, a re-import is often simpler than a full restore:
docker compose --profile data-node-ui down
docker volume rm spieli_pgdata # clear the database
docker compose --profile data-node-ui up -d
The import then starts as described in Refresh Data → After deleting the database.
The PBF files are stored in the pbf_cache volume and are reused automatically. If you deleted the volume too, the importer downloads a fresh copy (~300 MB for a state extract).
Scheduled backups¶
To schedule daily backups with cron (adjust paths to your deployment):
0 3 * * * cd /opt/spieli && docker compose exec -T db pg_dump -U osm osm | gzip > /opt/backups/spieli-$(date +\%Y\%m\%d).sql.gz && find /opt/backups -name 'spieli-*.sql.gz' -mtime +14 -delete
This dumps the database at 3 AM and deletes backups older than 14 days.
See also¶
- Configuration reference —
POSTGRES_PASSWORDand other variables to keep in your.envbackup - Scheduled import — automating regular OSM data refreshes