Skip to main content

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 protocol.
  • RESTORE_CLASS must point to class which follows the SqliteRestore 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.

./manage.py backup

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

./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 to the environment where your application is running.

Note: You can use AWS_PROFILE environment variable to select the appropriate profile in case there is more than one or the default one is not the correct one to be used.

Licence

This package is distributed under MIT Licence.

Metadata

Release files for django-sqlite-backup 0.3.0

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

Built distribution (wheel)

Table of built distributions (wheels) for django-sqlite-backup 0.3.0
File Interpreter ABI Platform
django_sqlite_backup-0.3.0-py3-none-any.whl Python 3 none any Details

Release files / django_sqlite_backup-0.3.0-py3-none-any.whl

Download URL django_sqlite_backup-0.3.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c7b63dce6381cafa900be566ae3aedf91898d764b754fcc63d08ddcb2c2a60e
BLAKE2b-256 checksum
How to use checksums
11c180e8ccec820f8022b9be7228594ac291eff8ffee9f151aac9593ef014d91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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