Skip to main content

A Django app to create and load backups.

Project description

Django Backup Utils

django-backup-utils offers a very bare-bone solution for managing backup/restore in your Django projects.
It is based on default django commands such as "dumpdata" and "loaddata".

DISCLAIMER:

django-backup-utils is designed to help in dev environments, when migration files are possibly not yet committed to VCS.
I do not recommend it for use in productive environments.

What this package provides:

  • Create backups with or without compression (tar/tar:gz)
  • Restore database backup
  • Restore migration files (only if specified)
  • Backup and restore any directory on your system, for example "./media", or "/tmp/hello_world/"
  • Manage backups/restoration through the Django admin interface
  • Verify migrations are consistent with the current migration recorder

Backup Contents

Each backup includes:

  • A timestamp
  • A full database dump in JSON format (using dumpdata) by default
  • All .py migration files that are currently migrated (if found)
  • A customizable version stamp (e.g., a commit hash)
  • Identifiers such as hostname and Django project name

Restoration Features

When restoring from a backup, you can:

  • Automatically retrieve the latest backup for your host and project
  • View the backup’s version stamp alongside the current version
  • See differences between backup migrations and current migrations (file count / missing files)
  • Run a blank unittest (done by default) to ensure that the fixture can be loaded (via "loaddata") before making changes

All backup logs are stored in the database. You can manage backups, including creation, synchronization, and restoration, via the Django admin interface.

Quick Start

  1. Install the package:

    $ pip install django-backup-utils
    
  2. Update settings.py:

    INSTALLED_APPS = [
      ...
      'django_backup_utils.apps.BackupUtilsConfig',
    ]
    
    BACKUP_ROOT = "/my/path/to/backupdir/"
    BACKUP_SYSTEM_VERSION = "my_build_id"
    APPS_DIR = BASE_DIR  # Change this accordingly if you use for example django-cookiecutter
    
    • BACKUP_ROOT: Directory where your backups will be stored.
    • BACKUP_SYSTEM_VERSION: Identification tag for your backup (e.g., git commit hash or tag).
    • APPS_DIR: Where your django-apps are located.

    Optional settings:

    • BACKUP_DIRS = [] (Default = []): Specifies additional directories to include in the backup.
    • BACKUP_IGNORE_CONSISTENCY = True (Default = False): Ignores inconsistencies between the MigrationRecorder and local migration files. By default, backups with inconsistent migrations raise a MigrationNotFound exception.
  3. Update urls.py:

    from django.urls import path, include
    
    urlpatterns = [
      ...
      path('backup/', include('django_backup_utils.urls')),
    ]
    
  4. Run migrations:

    $ python3 manage.py migrate
    

Usage

  • Create a Backup:

    $ python3 manage.py createbackup
    

    Optional arguments:

    • --compress: Compresses the backup (.gz).
    • --exclude: Exclude specific apps or models (<appname>.<model>).
    • --silent: Mutes some output.
  • Restore a Backup:

    $ python3 manage.py loadbackup
    

    Optional arguments:

    • --tarpath: Load the specified backup tar file.
    • --flush: Flush the database (delete existing data).
    • --deletedirs: Delete all directories specified in settings.BACKUP_DIRS before restoring.
    • --loadmigrations: Restore migration files.
    • --skiptest: Skip the unittest for loading the database dump.
  • List Available Backups:

    $ python3 manage.py listbackups
    

    Optional arguments:

    • --hostname: Show backups for a specific hostname.
    • --projectname: Show backups for a specific Django project.
    • --all: Show all backups.
    • --showinfo: Display backup metadata.
    • --showlatest: Show only the latest backup.
  • Synchronize Backups:

    $ python3 manage.py syncbackups
    

    Checks your BACKUP_ROOT and synchronizes it with DB

    Optional arguments:

    • --silent: Mutes some output.

Admin Interface Overview

  • System Migrations: Displays the number of migrations currently applied (from the MigrationRecorder).
  • System Migration Files: Shows the current number of local migration files.
  • Current System Version: Displays the current BACKUP_SYSTEM_VERSION.

Each Backup object includes:

  • Consistent Migrations: True if MigrationRecorder matches local migration files.
  • System Migrations (At dump time): Number of system migrations when the dump was created.
  • Dump Migration Files: Number of migration files archived in the dump.

Permissions

  • Restore Backups:
    django_backup_utils | can_restore_backup

  • Create/Synchronize Backups:
    django_backup_utils | can_add_backup

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_backup_utils-0.3.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_backup_utils-0.3.2-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file django_backup_utils-0.3.2.tar.gz.

File metadata

  • Download URL: django_backup_utils-0.3.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for django_backup_utils-0.3.2.tar.gz
Algorithm Hash digest
SHA256 e7f5a65d8fc2dbd4936c8fe39a2a0eb33bbd55adbcd5ccfb0037bd4aac786796
MD5 f5b34ceead4bdcfd63bda1513466c584
BLAKE2b-256 efde7fb3c9dbfdea85987da84ccd7dacd351ce7827c5ae687f49932093b46676

See more details on using hashes here.

File details

Details for the file django_backup_utils-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_backup_utils-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a012e09459e73d6c99310a0b62fa88509b0ebb71007273318c8525a9d5e662de
MD5 db0598d7a87be026f51e862eece4e7e0
BLAKE2b-256 bc9449eb354cb670e55f49b76f7d8d40f8e168ff09cddfd0688441b156dc3929

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page