Backups & disaster recovery for Django in production
Backups that restore, point-in-time recovery, and the plans and runbooks for the worst day.
A backup is only as good as the last restore you tested from it. Recovery also needs media, secrets, and a plan for who does what when it matters.
The guides cover PostgreSQL dumps and point-in-time recovery, media backups, disaster recovery planning, and incident response.
Set it up
Guides that take this from nothing to running in production.
- Move a Django Site to a New Server
Migrate a production Django site to a new server or provider with minimal downtime: rebuild the stack from code, copy media with rsync, move PostgreSQL with dump and restore or replication, lower DNS TTL, cut over, and keep the old server as a fallback.
- Back Up and Replicate a Django SQLite Database With Litestream
Use Litestream to continuously replicate a Django SQLite database to S3-compatible storage: enable WAL mode, run Litestream as a sidecar or systemd service, restore on startup in containers, test point-in-time recovery, and know the limits of single-writer SQLite.
Run it well
Tuning, reliability, and operations once it works.
- Backup and Restore PostgreSQL for Django Apps
A Django app is only recoverable if its PostgreSQL data is recoverable. In production, that means more than occasionally running pg_dump.
- Back Up Django Media Files
Back up Django uploads reliably: MEDIA_ROOT with restic, S3 versioning and replication, consistency with database backups, retention, and restores.
- Write a Disaster Recovery Plan for a Django App
Write a practical disaster recovery plan for Django: RPO and RTO targets, failure scenarios, point-in-time recovery, runbooks, access, and drills.
- PostgreSQL Point-in-Time Recovery for Django
Set up point-in-time recovery for a Django PostgreSQL database with pgBackRest: WAL archiving, full and incremental backups, restoring to a timestamp before a bad migration, and managed-service PITR.
- Automate Database and Media Backups With django-dbbackup
Use django-dbbackup to back up the Django database and media to S3 or other storage on a schedule: configuration, compression and GPG encryption, cleanup, restores with dbrestore and mediarestore, and its limits compared with native tools.
- Encrypt Django Database and Media Backups
Encrypt PostgreSQL dumps and media backups for a Django app: use age or GPG for client-side encryption, restic or pgBackRest built-in encryption, server-side encryption with KMS on S3, manage and store keys separately, and test restores with decryption.
- Test a Full PostgreSQL Restore for a Django App
Prove your Django backups work by restoring them regularly: automate a restore into a scratch database, measure restore time against your RTO, verify row counts and run Django checks and smoke tests, test point-in-time recovery, and record the results.
- Upgrade PostgreSQL to a New Major Version for Django
Upgrade the PostgreSQL behind a Django app to a new major version: check Django and psycopg support, choose dump and restore, pg_upgrade, or logical replication, then analyze, verify, and roll back safely.
- PostgreSQL High Availability and Failover for Django
Keep a Django app running through database failures: managed Multi-AZ PostgreSQL, Patroni or CloudNativePG for self-hosted clusters, connection endpoints that follow the primary, CONN_HEALTH_CHECKS and retries, and testing failover.
Check it
Review lists to run before launch or after a change.
- Django Backup and Recovery Checklist
Check that Django backups actually protect you: what to back up, schedules, off-site copies, encryption, retention, restore drills, and monitoring.
- Django Incident Response Runbook
A runbook for Django production incidents: declare and assign roles, triage with a fixed checklist across proxy, app, workers, database, and cache, mitigate first, communicate, and run a blameless review.
- Django Project Handover Checklist
Hand over a production Django project cleanly: repository and access, infrastructure inventory, secrets rotation, deploy and rollback runbooks, backups and restore tests, monitoring, domains, and third-party accounts.
Fix it
Errors and symptoms, each traced to a cause and a fix.
- Fix "duplicate key value violates unique constraint" After a Restore
Fix Django IntegrityError duplicate key value violates unique constraint on the id column after loaddata, a restore, or a migration from another database: reset PostgreSQL sequences with sqlsequencereset or setval.
- Fix PostgreSQL WAL Files Filling the Disk on a Django Server
Fix PostgreSQL pg_wal growing until the disk is full on a Django database: find inactive replication slots, broken WAL archiving, or high max_wal_size, free space safely without deleting WAL by hand, and add alerts so it does not happen again.