Metadata-Version: 2.4
Name: django-sync-env
Version: 1.1.0rc1
Summary: Backup, Sync and Restore Databases and Media
Author: Dan Brosnan
Author-email: dan.brosnan@octave.nz
Requires-Python: >=3.10,<4.0
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Provides-Extra: artifacts
Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
Requires-Dist: bagit (>=1.9.0,<2.0.0) ; extra == "artifacts"
Requires-Dist: django (>=4.2,<7)
Requires-Dist: django-storages (>=1.14.2,<2.0.0)
Requires-Dist: inquirer (>=3.2.4,<4.0.0)
Requires-Dist: slack-sdk (>=3.27.0,<4.0.0)
Description-Content-Type: text/markdown

# Django sync env

django-sync-env is a Django app for backing up and restoring Django databases and media assets. It also supports
secondary backup destinations and optional BagIt artifact backups.

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 `--noinput` for CI/CD and automation
- 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",
   ]
```

2. 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](docs/example_partials.md)

There is a basic [S3 Terraform example](docs/example_terraform_aws_s3_bucket.md) for provisioning a private backup
bucket and granting a workload principal access to it. Use IAM or equivalent workload authentication where the runtime
and storage provider support it; otherwise supply S3 access keys through environment variables or a secrets manager.
Apply your organisation's encryption, retention, versioning, and recovery requirements before using it in production.

## Feature guides

- [Database backups and secondary destinations](docs/database_backups.md)
- [Artifact backups](docs/artifact_backups.md) (advanced, optional workflow for arbitrary directory exports)

See the [management command reference](docs/management_commands.md) for command syntax and flags.

- `./manage.py sync_env_backup_db`
- `./manage.py sync_env_backup_media`
- `./manage.py sync_env_restore_db`
- `./manage.py sync_env_restore_media`
- `./manage.py sync_env_list_db_backups`
- `./manage.py sync_env_prepare_artifact_bag`
- `./manage.py sync_env_validate_artifact_bag`
- `./manage.py sync_env_backup_artifact_bag`
- `./manage.py sync_env_list_artifact_bags`
- `./manage.py sync_env_download_artifact_bag`

Artifact bag commands require the optional BagIt dependency:

```shell
pip install "django-sync-env[artifacts]"
```

## Supported versions

django-sync-env 1.1.0 supports Python 3.10 through 3.14 and Django 4.2 through 6.1. Release gates cover these
representative pairs:

| Python | Django |
|--------|--------|
| 3.10   | 4.2    |
| 3.11   | 5.0    |
| 3.12   | 5.1    |
| 3.12   | 5.2    |
| 3.12   | 6.0    |
| 3.13   | 6.1    |
| 3.14   | 6.1    |

See [Tasks](docs/tasks.md) for more details for each of the tasks available.

## Development and Publishing

See [documentation](docs/development_and_release_notes.md).

## Existing project migration

* To create a one-off database backup without storing anything on the local server, use the AWS CLI with its normal
  credential chain. Prefer a workload role or other short-lived credentials where available; otherwise provide the
  access key and secret key through the process environment.

```shell
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

