A Django app to backup PostgreSQL databases to S3
Project description
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
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 django_postgres_backup_ganaf-0.1.2.tar.gz.
File metadata
- Download URL: django_postgres_backup_ganaf-0.1.2.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01466e13c4b40630dd0c77eac05ae4bf77ad71fb618281f606f7c0e7f9313064
|
|
| MD5 |
c49ecd60198b19791f4a1b381363da7b
|
|
| BLAKE2b-256 |
ca1a3abc258aae0ec695d8569d7d9eb8d8e012e79c59c35693057d34733d0058
|
File details
Details for the file django_postgres_backup_ganaf-0.1.2-py3-none-any.whl.
File metadata
- Download URL: django_postgres_backup_ganaf-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e896485235a82ed8bb04d96fadbcca6937c4b7f949a19c64b35c209c1cac9da
|
|
| MD5 |
7d76fbe576989c98a90eb1421a5fc993
|
|
| BLAKE2b-256 |
d0192166c248f070d7d8832ca3c5cfb3acc9a9e1c3e5e9e9eaaf5fa2a158c8f2
|