{"id":7169,"library":"django-dbbackup","title":"Django DBBackup","description":"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.","status":"active","version":"5.3.0","language":"en","source_language":"en","source_url":"https://github.com/Archmonger/django-dbbackup","tags":["Django","backup","database","media","storage","automation"],"install":[{"cmd":"pip install django-dbbackup","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core framework dependency, requires Django 3.2+","package":"Django"},{"reason":"Required for GPG encryption and decryption features.","package":"python-gnupg","optional":true},{"reason":"Required for cloud storage backends like S3, Google Cloud Storage, Dropbox, etc.","package":"django-storages","optional":true}],"imports":[{"note":"django-dbbackup is primarily designed to be interacted with via Django management commands (e.g., `dbbackup`, `dbrestore`, `mediabackup`), not direct Python imports for command execution. Direct imports are typically only for extending functionality like custom connectors or signal receivers.","wrong":"import dbbackup; dbbackup.some_function()","symbol":"dbbackup","correct":"Django management commands are run via `python manage.py dbbackup`"}],"quickstart":{"code":"import os\nfrom pathlib import Path\n\n# settings.py\nBASE_DIR = Path(__file__).resolve().parent.parent\n\nINSTALLED_APPS = [\n    # ... other apps\n    'dbbackup',\n]\n\n# Configure a storage backend for backups\n# Using FileSystemStorage for local backups\nDB_BACKUP_LOCATION = os.path.join(BASE_DIR, 'my_backups')\nos.makedirs(DB_BACKUP_LOCATION, exist_ok=True)\n\nSTORAGES = {\n    \"dbbackup\": {\n        \"BACKEND\": \"django.core.files.storage.FileSystemStorage\",\n        \"OPTIONS\": {\n            \"location\": DB_BACKUP_LOCATION,\n        },\n    },\n}\n\n# Example of running commands (from your project root)\n# Make a backup:\n# python manage.py dbbackup --noinput\n# python manage.py mediabackup --noinput\n\n# Restore latest backup:\n# python manage.py dbrestore --noinput\n# python manage.py mediarestore --noinput","lang":"python","description":"1. Add 'dbbackup' to your `INSTALLED_APPS` in `settings.py`.\n2. 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.\n3. Run `python manage.py dbbackup` to create a database backup and `python manage.py mediabackup` for media files. Use `dbrestore` and `mediarestore` to restore."},"warnings":[{"fix":"Migrate your storage configuration to use Django's standard `STORAGES` setting under the 'dbbackup' key. Refer to the official documentation's 'Storage' section for examples.","message":"The legacy settings `DBBACKUP_STORAGE` and `DBBACKUP_STORAGE_OPTIONS` were removed in version 5.0.1.","severity":"breaking","affected_versions":">=5.0.1"},{"fix":"Always restore backups to a database using the same engine they were created from. If you need to migrate between database types, use Django's `dumpdata` and `loaddata` commands.","message":"By default, `dbrestore` prevents restoring a backup created for one database engine (e.g., PostgreSQL) to a different engine (e.g., SQLite) by checking metadata.","severity":"gotcha","affected_versions":">=5.1.0"},{"fix":"Ensure the necessary database client tools (e.g., `postgresql-client` for `pg_dump`) are installed and their executables are accessible in the PATH of the environment running `manage.py dbbackup`. In Docker, this often means installing them in the same container as your Django app or executing the backup from the database container itself.","message":"The `dbbackup` command relies on external database utilities like `pg_dump` (PostgreSQL) or `mysqldump` (MySQL) being available in the system's PATH where the command is executed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always configure `STORAGES['dbbackup']` with a dedicated and distinct storage location, preferably with restricted permissions, separate from your `MEDIA_ROOT`.","message":"Configuring backup storage with the same configuration as your media files (e.g., `DEFAULT_FILE_STORAGE`) can risk exposing sensitive backups in public directories.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Update your `settings.py` to use `STORAGES = {'dbbackup': {...}}` as per the documentation. For example, `STORAGES = {'dbbackup': {'BACKEND': 'django.core.files.storage.FileSystemStorage', 'OPTIONS': {'location': '/path/to/backups/'}}}`.","cause":"Using the deprecated `DBBACKUP_STORAGE` or `DBBACKUP_STORAGE_OPTIONS` settings in `settings.py`.","error":"ImproperlyConfigured: DBBACKUP_STORAGE setting has been removed in favor of Django's STORAGES setting."},{"fix":"Install the appropriate database client tools (e.g., `postgresql-client-common` or `postgresql-client` on Linux) in the environment where your Django app is running, and ensure they are discoverable in the system's PATH.","cause":"The `pg_dump` executable (or equivalent for other databases) is not found in the system's PATH where the Django application is running.","error":"dbbackup.db.exceptions.CommandConnectorError: Error running: pg_dump ... [Errno 2] No such file or directory: 'pg_dump'"},{"fix":"Ensure the database user configured in `settings.DATABASES` for the target database has `CREATEDB` privileges or is the owner of the database. Alternatively, use the `--no-drop` option for `dbrestore` (available since 4.2.1) if you want to avoid dropping tables.","cause":"`dbrestore` attempts to drop and recreate the database, but the specified user lacks the necessary permissions, or the database doesn't exist to be dropped by the user.","error":"CommandError: Error running: [u'dropdb', u'--username=dev', u'--host=localhost', u'mydatabase'] FATAL: database \"mydatabase\" does not exist or FATAL: permission denied for database \"mydatabase\""},{"fix":"Restore the backup to a database with the same `ENGINE` as it was created from. For cross-database migrations, use Django's `dumpdata` and `loaddata` utilities.","cause":"Attempting to restore a database backup created for one type of database (e.g., PostgreSQL) to a different type of database (e.g., SQLite). This check was introduced for data integrity.","error":"dbbackup.db.exceptions.CommandConnectorError: Restoring to a different database engine is not supported. Backup was for 'django.db.backends.postgresql', but you are restoring to a database using 'django.db.backends.sqlite3'."}]}