Metadata-Version: 2.2
Name: django-postgres-backup-ganaf
Version: 0.1.2
Summary: A Django app to backup PostgreSQL databases to S3
Home-page: https://github.com/yourusername/django-postgres-backup
Author: Your Name
Author-email: your.email@example.com
Project-URL: Bug Tracker, https://github.com/yourusername/django-postgres-backup/issues
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENCE
Requires-Dist: Django>=3.2
Requires-Dist: boto3>=1.26.0
Requires-Dist: apscheduler>=3.9.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Django PostgreSQL Backup

A reusable Django app to automatically backup PostgreSQL databases to S3.

## Features

- Scheduled or manual backups of PostgreSQL databases
- S3 storage of backups
- Automatic cleanup of old backups
- Configurable scheduling

## Installation

```bash
pip install django-postgres-backup
```

Or add to your requirements.txt:

```
django-postgres-backup==0.1.0
```

## Configuration

Add to your `INSTALLED_APPS` in settings.py:

```python
INSTALLED_APPS = [
    # other apps
    'django_backup',
]
```

Configure your settings.py with the following settings:

```python
# Database settings
DB_HOST = 'localhost'
DB_PORT = '5432'
DB_NAME = 'your_database'
DB_USER = 'postgres'
DB_PASSWORD = 'your_password'

# S3 settings
AWS_STORAGE_BUCKET_NAME = 'your-bucket-name'
AWS_ACCESS_KEY_ID = 'your-access-key'
AWS_SECRET_ACCESS_KEY = 'your-secret-key'

# Backup settings
BACKUP_DIR = 'database_backups'
BACKUP_SCHEDULER_ENABLED = True  # Set to False to disable automatic backups
BACKUP_UPLOAD_TO_S3 = True       # Set to False to disable S3 upload
BACKUP_CLEANUP_ENABLED = True    # Set to False to disable automatic cleanup
BACKUP_KEEP_COUNT = 2            # Number of backups to keep

# Optional: Server ownership settings
IS_LOCAL = False                # Set to True for local development
SERVER_USER = 'www-data'        # User who should own backup files
SERVER_GROUP = 'www-data'       # Group who should own backup files

# Backup schedule (uses APScheduler cron syntax)
BACKUP_SCHEDULE = {
    'hour': '0',     # Run at midnight
    'minute': '0',
}
```

## Usage

### Automatic Backups

If `BACKUP_SCHEDULER_ENABLED` is set to `True`, backups will run automatically according to your schedule.

### Manual Backups

Run a backup manually:

```bash
python manage.py run_backup
```

Options:
- `--upload`: Force upload to S3 (even if disabled in settings)
- `--cleanup`: Force cleanup of old backups
- `--keep-count=N`: Specify number of backups to keep when cleaning up

## How It Works

1. The app creates backups using PostgreSQL's pg_dump tool
2. If pg_dump is not available, it falls back to using a Docker container
3. Backups are stored locally in the directory specified by `BACKUP_DIR`
4. If enabled, backups are uploaded to the S3 bucket
5. Old backups are cleaned up, keeping only the most recent ones

## License

MIT
