<p align="center">
<img src="https://banners.beyondco.de/Masonite%20Backup.png?theme=light&packageManager=pip+install&packageName=masonite-backup&pattern=charlieBrown&style=style_2&description=Backup+solution+for+Masonite+Apps.&md=1&showWatermark=1&fontSize=100px&images=adjustments&widths=50&heights=50">
</p>

<p align="center">
  <a href="https://docs.masoniteproject.com">
    <img alt="Masonite Package" src="https://img.shields.io/static/v1?label=Masonite&message=package&labelColor=grey&color=blue&logo=data:image/png;base64, ">
  </a>
  <img alt="GitHub Workflow Status (branch)" src="https://github.com/py-package/masonite-backup/actions/workflows/pythonapp.yml/badge.svg">
  <img alt="PyPI" src="https://img.shields.io/pypi/v/masonite-backup">
  <img src="https://img.shields.io/badge/python-3.7+-blue.svg" alt="Python Version">
  <img alt="GitHub release (latest by date including pre-releases)" src="https://img.shields.io/github/v/release/py-package/masonite-backup?include_prereleases">
  <img alt="License" src="https://img.shields.io/github/license/py-package/masonite-backup">
  <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>

# Masonite Backup

Backup solution for Masonite.

### Features

- [x] Backup Database
- [x] Backup Files
- [x] Store Backup Locally in the filesystem
- [x] Email Backup
- [x] Store Backup in other Masonite Supported Storage Drivers [s3]


### Installation

```bash
pip install masonite-backup
```

### Configuration

Add BackupProvider to your project in `config/providers.py`:

```python
# config/providers.py
# ...
from backup import BackupProvider

# ...
PROVIDERS = [
    # ...
    # Third Party Providers
    BackupProvider,
    # ...
]
```

Then you can publish the package resources (if needed) by doing:

```bash
python craft package:publish backup
```

### Usage

Once you publish the package resources, you can use the `backup` command to backup your database and files. Before that if you want to configure options of backup then you can do that by updating `config/backup.py` configuration file.

```python
# config/backup.py

FILENAME = "backup"
DIRECTORY = "backup"
SOURCE = {
    "root": base_path(),
    "excludes": [
        ".git",
        "storage",
        "venv",
        "node_modules",
        "__pycache__",
        # add more...
    ],
}

S3_BACKUP = False # Whether or not to backup to S3.
EMAIL_BACKUP = False  # Whether or not to email the backup.
EMAIL_BACKUP_TO = ""  # The email address to send the backup to.
EMAIL_SUBJECT = "System Backup"  # The email subject.
```
> Note: Make sure you have `EMAIL_BACKUP` set to `True` and `EMAIL_BACKUP_TO` set to a valid email address, to send the backup via email. Also don't forget to setup SMTP in `config/mail.py` configuration file or in `.env` file. In case you want to backup to S3, then make sure you have `S3_BACKUP` set to `True` and S3 storage configuration.

```sh
MAIL_DRIVER=smtp
MAIL_FROM=
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=

AWS_CLIENT=
AWS_SECRET=
AWS_BUCKET=
AWS_REGION=
```

**Backup Database and Files**

```bash
python craft backup:run
```

**Backup Database Only**

```bash
python craft backup:run --only-db
```

**Backup Files Only**

```bash
python craft backup:run --only-files
```

## License

Backup is open-sourced software licensed under the [MIT license](LICENSE).

