Skip to main content

A Django app to create and load backups.

Project description

Django Backup Utils

With django-backup-utils you can:

  • create backups with or without compression
  • list available backups for your host & project
  • restore database
  • restore migration files
  • backup/restore any directory inside BASE_DIR (relative to)
  • manage backups via admin interface
  • check if migrations are consistent with your migration recorder (Consistent Migrations).

A backup always contains

  • timestamp
  • per default a full dump of your database as json (using dumpdata)
  • all migration .py files that are currently migrated.
  • a customizable version stamp (e.g. commit hash)
  • identifiers such as hostname, django project name

When restoring a backup

  • automatically get the latest backup for your host + project
  • see the backup's version stamp
  • see the current version stamp
  • see differences between backup und current migrations
  • per default a blank unittest is run to ensure the fixture can be loaded (before anything is changed)

Backup logs are saved to database.

You can create/synchronize and restore backups via admin interface.

Project-Structure needed

  projectname/
    projectname/
      __init__.py
      settings.py
      ...
    App1 /
      migrations /
        __init__.py
        ...
    ...

Quick start

  1. $ pip install django-backup-utils

  2. settings.py:

  INSTALLED_APPS = [
    ...
    'django_backup_utils.apps.BackupUtilsConfig',
  ]

  BACKUP_ROOT = "/my/path/to/backupdir/"
  BACKUP_SYSTEM_VERSION = "my_build_id"
  

BACKUP_ROOT specifies a directory where your backups will be stored.

BACKUP_SYSTEM_VERSION identification tag for your backup (e.g. your git commit hash/tag).

Optional:

BACKUP_DIRS = [] (Default = []), specifies directories relative to BASE_DIR that will be included in the backup,
can also be an empty array. Example: BACKUP_DIRS = ["media", "somedir"]

BACKUP_IGNORE_CONSISTENCY = True (Default = False), ignores inconsistency between the MigrationRecorder and local migration files.
(Default): Backups that would contain inconsistent migrations cannot be created and raise MigrationNotFound exception.
When changed to True, your backup will still contain all migration files that match the MigrationRecorder,
however migration files that are not found locally can not be included in the backup. (This can only happen if you delete/rename migration files before you create a backup).

  1. urls.py:
from django.urls import path, include

urlpatterns = [
    ...
    path('backup/', include('django_backup_utils.urls')),
]
  1. $ python3 manage.py migrate

Usage

$ python3 manage.py createbackup

  - create a backup that contains all database data, migration files and specified directories

    optional arguments:
      -h, --help            show this help message and exit
      --compress            compresses backup (.gz)
      --exclude             exclude specific apps or models <appname>.<model>
      --silent              mutes some output

$ python3 manage.py loadbackup

  - load the latest backup

    optional arguments:
      -h, --help            show this help message and exit
      --tarpath TARPATH     load the specified backup tarfile
      --flush               flush the database (delete existing data)
      --deletedirs          delete all directories specified in settings.BACKUP_DIRS (before restoring)
      --noinput             disable all prompts
      --loadmigrations      restore all migration files
      --skiptest            skip the unittest for loading database dump
      --silent              mutes some output

$ python3 manage.py listbackups

  - show backups located at settings.BACKUP_ROOT

    optional arguments:
      -h, --help            show this help message and exit
      --hostname HOSTNAME   show backups for specified hostname
      --projectname PROJECTNAME
                            show backups for specified django project
      --all                 show all backups
      --showinfo            show backup metadata
      --showlatest          show only latest backup

$ python3 manage.py syncbackups

  - synchronizes existing backups for project + host with database

    optional arguments:
      -h, --help            show this help message and exit
      --silent              mutes some output

Admin Interface

What means what?

Backup Overview:

  • System Migrations: currently applied number of migrations recorded by your MigrationRecorder.
  • System Migration files: current number of found migration files locally.
  • Current System Version: your BACKUP_SYSTEM_VERSION as it is right now.

A Backup object:

  • Consistent Migrations: True when the MigrationRecorder matches local migration files (None is missing).
  • System Migrations (At dump time): number of system migrations when the dump was created.
  • Dump Migration Files: number of migration files that have been archived in your dump.

Permissions

Permission for restoring backups:

django_backup_utils | can_restore_backup

Permission for creating/synchronizing 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.2.5.tar.gz (18.9 kB view details)

Uploaded Source

File details

Details for the file django-backup-utils-0.2.5.tar.gz.

File metadata

  • Download URL: django-backup-utils-0.2.5.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for django-backup-utils-0.2.5.tar.gz
Algorithm Hash digest
SHA256 0543c72ac1a8666a7ac03a29f18376017003017bb5e472cac0bcb7cd8f6e8bff
MD5 92e93ea612c12f72d12df99f0396eccb
BLAKE2b-256 97522810cd60aa0059d02932dfa3d63f6682ce650d12e15eb021183875aeaf1e

See more details on using hashes here.

Supported by

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