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.1.tar.gz (19.7 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.1-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_backup_utils-0.3.1.tar.gz
  • Upload date:
  • Size: 19.7 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.1.tar.gz
Algorithm Hash digest
SHA256 80af543abb1f89e1aefac7d08099eb36133fe0770a91914658a28d7265f9f7c7
MD5 49d4e382e3e3798af438e1b47fb32f17
BLAKE2b-256 6d6c048f04de7c2bdf0a38ec77487e499f3004f3a894b55c459bc4f3bde89b53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_backup_utils-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92958e3dd77c603baacf6a6cfe041fcc932ff90c969d84107e495000a8c08747
MD5 6ff57844fe3175d41f69718ef941df3e
BLAKE2b-256 dad372a533a08814c6c7a01980840692b907f9565eaba01cafec15c74e3b767b

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