Django DBBackup

5.3.0 · active · verified Thu Apr 16

Django DBBackup is an active and frequently updated (multiple minor releases per quarter) Django application that provides management commands to simplify backing up and restoring project databases and media files. It supports various storage backends like local filesystem, Amazon S3, Dropbox, and any Django-supported storage, offering features such as GPG encryption, compression, remote archiving, and the ability to set up automated backups via Crontab or Celery.

Common errors

Warnings

Install

Imports

Quickstart

1. Add 'dbbackup' to your `INSTALLED_APPS` in `settings.py`. 2. Configure a `STORAGES['dbbackup']` entry to define where your backups will be stored. It's recommended to use a dedicated directory, not your `MEDIA_ROOT`, to avoid accidental public exposure. 3. Run `python manage.py dbbackup` to create a database backup and `python manage.py mediabackup` for media files. Use `dbrestore` and `mediarestore` to restore.

import os
from pathlib import Path

# settings.py
BASE_DIR = Path(__file__).resolve().parent.parent

INSTALLED_APPS = [
    # ... other apps
    'dbbackup',
]

# Configure a storage backend for backups
# Using FileSystemStorage for local backups
DB_BACKUP_LOCATION = os.path.join(BASE_DIR, 'my_backups')
os.makedirs(DB_BACKUP_LOCATION, exist_ok=True)

STORAGES = {
    "dbbackup": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
        "OPTIONS": {
            "location": DB_BACKUP_LOCATION,
        },
    },
}

# Example of running commands (from your project root)
# Make a backup:
# python manage.py dbbackup --noinput
# python manage.py mediabackup --noinput

# Restore latest backup:
# python manage.py dbrestore --noinput
# python manage.py mediarestore --noinput

view raw JSON →