Skip to main content

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_db management command for timestamped PostgreSQL SQL dumps
  • restore_db management command for restoring a named dump from S3
  • seed_db management command for "restore only if the database is still empty"
  • list_backups and delete_backup management commands
  • S3 bucket bootstrap on first use
  • Configurable connection overrides and host aliases
  • Retention cleanup and optional latest.sql alias 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:

  1. Scheduled job in DEV runs backup_db --latest-alias latest.sql --keep-count 5.
  2. PR preview containers run seed_db latest.sql --env DEV.
  3. 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 optionally s3: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.

Metadata

Release files for dj-dbbackup 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-dbbackup 0.1.0
File Size Uploaded Provenance Actions
dj_dbbackup-0.1.0.tar.gz 10.3 kB With provenance Details for dj_dbbackup-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dj-dbbackup 0.1.0
File Interpreter ABI Platform Actions
dj_dbbackup-0.1.0-py3-none-any.whl Python 3 none any Details for dj_dbbackup-0.1.0-py3-none-any.whl

Total release size: 21.7 kB

Release files / dj_dbbackup-0.1.0.tar.gz

Download URL dj_dbbackup-0.1.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dab04ce70bc8de1aa38960b37c299a485dc6d75fc6f04ba1ea5cef4f98226c6c
BLAKE2b-256 checksum
How to use checksums
c5ced5cd50b3579b8c390b76aec696716c23d7454db651febb175aae806353ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2026.

Transparency log

Release files / dj_dbbackup-0.1.0-py3-none-any.whl

Download URL dj_dbbackup-0.1.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc4e8366058152d6ed955b3de381236dbd997267a7af1f0b531d8bbbd36db39f
BLAKE2b-256 checksum
How to use checksums
ccdfc8446694ff8b46a2a97a38608ed00e238efcdf756365645e5781e9d4ce66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2026.

Transparency log

Security for dj-dbbackup 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dj_dbbackup-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page