Skip to main content

Backup, Sync and Restore Databases and Media

Project description

Django sync env

django-sync-env is a Django app to manage backing up and restoring django databases and media assets easily.

Detailed documentation is in the "docs" directory (it's a work in progress).

Requirements:

  • configurable backups and restore which can be run on demand, celery cron or in dev.
  • support s3 bucket and file storage options first, add azure blob storage later
  • interactive prompts for local dev
  • command line options with --no-input for CICD and automations
  • restore latest option for media and backups for X env
  • backup before restore option

Setup

  1. Add "django_sync_env" to your INSTALLED_APPS setting like this:
   INSTALLED_APPS = [
   ...,
   "django_sync_env",
   ]
  1. Configure the app via a settings file .typically ./settings/partial/sync_env.py for base configuration, don't forget to import this file via your base.py settings file And override any required settings per environment via ./settings/partials/[env].py see example_partials

There is a s3 terraform example for provisioning an aws s3 bucket, iam user, roles and policy to allow for remote backup/restore to/from a secure s3 bucket.

See management commands for more details for each of the commands available.

  • ./manage.py sync_env_backup_db usage
  • ./manage.py sync_env_backup_media
  • ./manage.py sync_env_restore_db
  • ./manage.py sync_env_restore_media
  • ./manage.py sync_env_list_backups

See Tasks for more details for each of the tasks available.

Development and Publishing

See documentation.

Existing project migration

  • To run db backup manually without storing anything on the local server you can run following command
export AWS_ACCESS_KEY_ID="<backup-user-key>"
export AWS_SECRET_ACCESS_KEY="<backup-user-secret>"

pg_dump --dbname="postgresql://<db-user>:<db-password>@<db-host>:5432/<db-name>" --format=custom | gzip --stdout | aws s3 cp - "s3://<project-name>-<env>-backups/<sensible-name-here>-<db-name>-$(date +'%d-%m-%Y-%H%M%S').psql.bin.gz"
  • After that you can restore this database backup using ./manage.py sync_env_restore_db

TODO:

  • remove command options which we wont use
  • make sure all management commands work with good error logging and handling
  • Update the sync-env-backup command to enable the option to specify particular databases
  • Update the sync-env-backup command to exclude particular tables in particular databases

Project details


Release history Release notifications | RSS feed

This version

1.0.1

Download files

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

Source Distribution

django_sync_env-1.0.1.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

django_sync_env-1.0.1-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file django_sync_env-1.0.1.tar.gz.

File metadata

  • Download URL: django_sync_env-1.0.1.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.11 Linux/6.1.79

File hashes

Hashes for django_sync_env-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5169fb7e3febc46f20fd3f5fe2e42a2626d8099909826741aa010205fefec1d0
MD5 6503e718605ca2e930e108498d9fdc72
BLAKE2b-256 d020321b9ac2c84ba15f464445908b3b26b748c8a7c58f7ecb1ec6e3f5cb7790

See more details on using hashes here.

File details

Details for the file django_sync_env-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_sync_env-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.11 Linux/6.1.79

File hashes

Hashes for django_sync_env-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33c60c5cdc7e5e6df30163764aacd42e1cbb79cad9902d18efccfdce6bf1bb4e
MD5 26c2e8e174e75d9bdc201275b7becb41
BLAKE2b-256 a5bfc6c02e51d0654ca1f416a4c20a69c1f86b61b9bdb355993fde5c2d8897d4

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