Skip to main content

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

Release files for django-sync-env 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-sync-env 1.0.2
File Size Uploaded
django_sync_env-1.0.2.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-sync-env 1.0.2
File Interpreter ABI Platform
django_sync_env-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 56.9 kB

Release files / django_sync_env-1.0.2.tar.gz

Download URL django_sync_env-1.0.2.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fabacfc63e4735f944c6288a86565fc6e35f844e7ecab76c591325b208158650
BLAKE2b-256 checksum
How to use checksums
d74ed4d5314c9e3d3d8c82337a03a0e2dca1ed71cae66d04227882f9693bc5ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.14 Linux/6.19.13-orbstack-gbd1dc07b8cf4

Release files / django_sync_env-1.0.2-py3-none-any.whl

Download URL django_sync_env-1.0.2-py3-none-any.whl
Size 34.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae61e311a79314fd232d424ed782148901daf43f38f3b9d9fd66791c5bf6ab80
BLAKE2b-256 checksum
How to use checksums
2e51197d25fac75268228f9b48580dae30b6fdb26b55b9595fe502fe955f3468
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.14 Linux/6.19.13-orbstack-gbd1dc07b8cf4

Release history Release notifications | RSS feed

1.1.0

2 release files

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.2

2 release files

0.3.0

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page