Reusable Django app for PostgreSQL backup, restore, and preview seeding via S3.
Project description
dj-dbbackup
dj-dbbackup is a reusable Django app for PostgreSQL backup, restore, and preview-database seeding using S3-compatible object storage.
It started as Ionisium's internal dbbackup app, then was extracted so multiple Django projects can share the same workflow.
Features
backup_dbmanagement command for timestamped PostgreSQL SQL dumpsrestore_dbmanagement command for restoring a named dump from S3seed_dbmanagement command for "restore only if the database is still empty"list_backupsanddelete_backupmanagement commands- S3 bucket bootstrap on first use
- Configurable connection overrides and host aliases
- Retention cleanup and optional
latest.sqlalias for preview deployments
Installation
pip install dj-dbbackup
Add the app to Django:
INSTALLED_APPS = [
...,
"dj_dbbackup",
]
Configuration
Preferred setting names:
| Setting | Description |
|---|---|
DJ_DBBACKUP_BUCKET |
Required bucket name used for backup storage. |
DJ_DBBACKUP_ENV |
Backup namespace, defaults to settings.CURRENT_ENV and then LOCAL. |
DJ_DBBACKUP_AWS_REGION |
S3 region, defaults to settings.AWS_S3_REGION_NAME and then us-east-1. |
DJ_DBBACKUP_PG_DUMP_BIN |
Optional absolute path to pg_dump. |
DJ_DBBACKUP_PSQL_BIN |
Optional absolute path to psql. |
DJ_DBBACKUP_CONNECTION_OVERRIDES |
Optional dict merged into DATABASES["default"]. |
DJ_DBBACKUP_HOST_ALIASES |
Optional dict mapping logical DB hosts to actual hosts. |
DJ_DBBACKUP_UNSUPPORTED_SETTINGS |
Dump SET statements stripped during restore. Defaults to ("transaction_timeout",). |
DJ_DBBACKUP_EMPTY_TABLE_EXCLUDES |
Optional iterable of table names ignored by seed_db when checking emptiness. |
Legacy Ionisium-style names such as DB_BACKUP_S3_BUCKET are still accepted for compatibility.
Minimal example:
DJ_DBBACKUP_BUCKET = "myapp-db-backups"
DJ_DBBACKUP_ENV = "DEV"
DJ_DBBACKUP_CONNECTION_OVERRIDES = {"HOST": "db"}
Commands
Create a backup:
python manage.py backup_db --latest-alias latest.sql --keep-count 5
Useful options:
--env DEV--db-host host.docker.internal--filename-prefix preview-seed--latest-alias latest.sql--keep-count 5
Restore a backup:
python manage.py restore_db DEV-20260309120000.sql --env DEV
python manage.py restore_db latest.sql --env DEV
Seed only if the database is empty:
python manage.py seed_db latest.sql --env DEV
List or delete backups:
python manage.py list_backups --env DEV
python manage.py delete_backup latest.sql --env DEV
Preview deployment pattern
One common workflow is:
- Scheduled job in
DEVrunsbackup_db --latest-alias latest.sql --keep-count 5. - PR preview containers run
seed_db latest.sql --env DEV. - Migrations run after the restore completes.
That keeps preview databases reproducible without project-specific shell restore logic.
Requirements
- PostgreSQL client tools available in the runtime image
- AWS credentials or another supported boto3 credential source
- Access to
s3:GetObject,s3:PutObject,s3:DeleteObject,s3:ListBucket, and optionallys3:CreateBucket
Packaging
Build a distribution:
python -m build
Validate the built metadata:
python -m twine check dist/*
Publishing is handled by GitHub Actions with PyPI Trusted Publishing. The exact one-time PyPI setup and tag-based release process are documented in docs/RELEASING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dj_dbbackup-0.1.0.tar.gz.
File metadata
- Download URL: dj_dbbackup-0.1.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dab04ce70bc8de1aa38960b37c299a485dc6d75fc6f04ba1ea5cef4f98226c6c
|
|
| MD5 |
182cdce09681ff5728a4f5de62b247d9
|
|
| BLAKE2b-256 |
c5ced5cd50b3579b8c390b76aec696716c23d7454db651febb175aae806353ca
|
Provenance
The following attestation bundles were made for dj_dbbackup-0.1.0.tar.gz:
Publisher:
publish.yml on dakixr/dj-dbbackup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_dbbackup-0.1.0.tar.gz -
Subject digest:
dab04ce70bc8de1aa38960b37c299a485dc6d75fc6f04ba1ea5cef4f98226c6c - Sigstore transparency entry: 1067245725
- Sigstore integration time:
-
Permalink:
dakixr/dj-dbbackup@0ed88174c4f32055959a19a9d1e1156fa83c4661 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dakixr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0ed88174c4f32055959a19a9d1e1156fa83c4661 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dj_dbbackup-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dj_dbbackup-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc4e8366058152d6ed955b3de381236dbd997267a7af1f0b531d8bbbd36db39f
|
|
| MD5 |
68079be53acec5ed63c61d819a1cedad
|
|
| BLAKE2b-256 |
ccdfc8446694ff8b46a2a97a38608ed00e238efcdf756365645e5781e9d4ce66
|
Provenance
The following attestation bundles were made for dj_dbbackup-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on dakixr/dj-dbbackup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_dbbackup-0.1.0-py3-none-any.whl -
Subject digest:
fc4e8366058152d6ed955b3de381236dbd997267a7af1f0b531d8bbbd36db39f - Sigstore transparency entry: 1067245833
- Sigstore integration time:
-
Permalink:
dakixr/dj-dbbackup@0ed88174c4f32055959a19a9d1e1156fa83c4661 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dakixr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0ed88174c4f32055959a19a9d1e1156fa83c4661 -
Trigger Event:
push
-
Statement type: