Metadata-Version: 2.1
Name: django-sqlite-backup
Version: 0.1.0
Summary: A Django app to easily backup your sqlite database through an endpoint.
Author-email: Ferran Jovell <ferran.jovell+gh@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Ferran Jovell
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/mrswats/django-sqlite-backup
Project-URL: Bug Tracker, https://github.com/mrswats/django-sqlite-backup/issues
Keywords: django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django ==4.1.1
Requires-Dist: asgiref ==3.8.1
Provides-Extra: aws
Requires-Dist: boto3 ; extra == 'aws'
Provides-Extra: test
Requires-Dist: boto3 ; extra == 'test'
Requires-Dist: coverage ; extra == 'test'
Requires-Dist: moto ; extra == 'test'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: pytest-django ; extra == 'test'
Requires-Dist: time-machine ; extra == 'test'

# Django Sqlite Backup

A Django application to backup you SQLite database by calling and endpoint.

## Installation

From PYPi using `pip`:

```
pip install django-sqlite-backup
```

## Usage

Add the app to the `INSTALLED_APPS`:

```
INSTALLED_APPS = [
    ...,
    "django_sqlite_backup",
    ...,
]
```

Then, add the app's URLs to the root URL conf:

```
    path("", include("django_sqlite_backup.urls")),
```

This will create a route in your application to backup your sqlite database:

```
GET /backup/

204: Successful backup
```

### Write your own view

If you want to use a different method or want to add some sort of authentication or other kinds of logic with the backup call, you can write your own view importing the `do_backup` function:

```
# views.py
from django.http import HttpRequest
from django.http import JsonResponse

from django_sqlite_backup import backup


def my_view(request: HttpRequest) -> JsonResponse:
    do_backup()
    return JsonResponse({}, status=204)
```

### Settings

You must define your settings in your `settings.py`:

```

SQLITE_BACKUP = {
"BACKUP_CLASS": ...,
"RESTORE_CLASS": ...,
"BUCKET_NAME": ...,
"S3_ENDPOINT": ...,
}

```

- `BACKUP_CLASS` must point to class which follows the [`SqliteBackup`](./django_sqlite_backup/backup.py) protocol.
- `RESTORE_CLASS` must point to class which follows the [`SqliteRestore`](./django_sqlite_backup/restore.py) protocol.
- `BUCKET_NAME` is the name of the bucket in S3 which can be written to.
- `S3_ENDPOINT` S3 endpoint override. Leave this blank if you use AWS S3 directly.

### Management commands

This app provides two commands for carrying out operations on the backups: `backup` and `restore`.

```console
./manage.py backup
```

Will back up the current sqlite database into the configured bucket.

```console
./manage.py restore [date_str]
```

Will restore your sqlite database from your configured bucket on the date specified.
The `date_str` is optional and defaults to today.

### AWS

By default, the backup class uses `boto3` to backup the sqlite database into S3. Therefore, you will need to also pass the [AWS Environment Variables](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html) to the environment where your application is running.

## Licence

This package is distributed under [MIT Licence](./LICENCE).
