Django PostgreSQL Backup
A reusable Django app to automatically backup PostgreSQL databases to S3.
Features
- Scheduled or manual backups of PostgreSQL databases
- S3 storage of backups
- Automatic cleanup of old backups
- Configurable scheduling
Installation
pip install django-postgres-backup
Or add to your requirements.txt:
django-postgres-backup==0.1.0
Configuration
Add to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
# other apps
'django_backup',
]
Configure your settings.py with the following settings:
# Database settings
DB_HOST = 'localhost'
DB_PORT = '5432'
DB_NAME = 'your_database'
DB_USER = 'postgres'
DB_PASSWORD = 'your_password'
# S3 settings
AWS_STORAGE_BUCKET_NAME = 'your-bucket-name'
AWS_ACCESS_KEY_ID = 'your-access-key'
AWS_SECRET_ACCESS_KEY = 'your-secret-key'
# Backup settings
BACKUP_DIR = 'database_backups'
BACKUP_SCHEDULER_ENABLED = True # Set to False to disable automatic backups
BACKUP_UPLOAD_TO_S3 = True # Set to False to disable S3 upload
BACKUP_CLEANUP_ENABLED = True # Set to False to disable automatic cleanup
BACKUP_KEEP_COUNT = 2 # Number of backups to keep
# Optional: Server ownership settings
IS_LOCAL = False # Set to True for local development
SERVER_USER = 'www-data' # User who should own backup files
SERVER_GROUP = 'www-data' # Group who should own backup files
# Backup schedule (uses APScheduler cron syntax)
BACKUP_SCHEDULE = {
'hour': '0', # Run at midnight
'minute': '0',
}
Usage
Automatic Backups
If BACKUP_SCHEDULER_ENABLED is set to True, backups will run automatically according to your schedule.
Manual Backups
Run a backup manually:
python manage.py run_backup
Options:
--upload: Force upload to S3 (even if disabled in settings)--cleanup: Force cleanup of old backups--keep-count=N: Specify number of backups to keep when cleaning up
How It Works
- The app creates backups using PostgreSQL's pg_dump tool
- If pg_dump is not available, it falls back to using a Docker container
- Backups are stored locally in the directory specified by
BACKUP_DIR - If enabled, backups are uploaded to the S3 bucket
- Old backups are cleaned up, keeping only the most recent ones
License
MIT
Metadata
Release files for django-postgres-backup-ganaf 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_postgres_backup_ganaf-0.1.2.tar.gz | 9.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_postgres_backup_ganaf-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.3 kB
Release files / django_postgres_backup_ganaf-0.1.2.tar.gz
| Download URL | django_postgres_backup_ganaf-0.1.2.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01466e13c4b40630dd0c77eac05ae4bf77ad71fb618281f606f7c0e7f9313064
|
|
BLAKE2b-256 checksum How to use checksums |
ca1a3abc258aae0ec695d8569d7d9eb8d8e012e79c59c35693057d34733d0058
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / django_postgres_backup_ganaf-0.1.2-py3-none-any.whl
| Download URL | django_postgres_backup_ganaf-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e896485235a82ed8bb04d96fadbcca6937c4b7f949a19c64b35c209c1cac9da
|
|
BLAKE2b-256 checksum How to use checksums |
d0192166c248f070d7d8832ca3c5cfb3acc9a9e1c3e5e9e9eaaf5fa2a158c8f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|