Database-native backup tool for FastAPI, SQLAlchemy, and SQLModel projects.
Project description
fastapi-dbbackup
Database-native backup tool for FastAPI, SQLAlchemy, and SQLModel projects. Similar to django-dbbackup.
Features
- Database Support: SQLite, PostgreSQL, MySQL (SQL-only).
- Storage Support: Local File System, AWS S3, DigitalOcean Spaces.
- Direct Streaming: Direct pipe from database to cloud for Postgres/MySQL (No local disk usage).
- Compression: Gzip compression supported (including streaming compression).
- Security: Secure credential handling via environment variables (no passwords in process lists).
- Restoration: Easy database restoration from backups.
- Retention: Automatic purging of old backups.
- CLI: Intuitive CLI with
backup,restore, andlistcommands.
Database Version Support
| Database | Supported Versions | Requirement |
|---|---|---|
| PostgreSQL | All (9.x - 17+) | pg_dump client version must be ≥ Server version |
| MySQL | All (5.7, 8.0+) | mysqldump client version must be ≥ Server version |
| SQLite | All | No special requirements |
Installation
pip install fastapi-dbbackup
# If using UV:
uv add fastapi-dbbackup
Configuration
The tool is configured via environment variables. It automatically loads variables from a .env file in your current directory or any parent directory.
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
SQLAlchemy-style URL. Required for connection details. Credentials and host are optional if your environment supports it (e.g. Trust auth or local sockets). | - |
DBBACKUP_ENGINE |
Database engine (postgres, mysql, sqlite, or auto) |
auto |
DBBACKUP_DIR |
Local or Cloud directory for backups | backups |
DBBACKUP_STORAGE |
Storage backend (local or s3) |
local |
DBBACKUP_COMPRESS |
Whether to compress backups | true |
DBBACKUP_RETENTION_DAYS |
Number of days to keep backups (0 = forever) | 0 |
DBBACKUP_MAX_BACKUPS |
Maximum number of backups to keep (0 = unlimited) | 0 |
AWS_S3_ACCESS_KEY_ID |
AWS/DigitalOcean access key ID | - |
AWS_S3_SECRET_ACCESS_KEY |
AWS/DigitalOcean secret access key | - |
AWS_S3_ENDPOINT_URL |
Custom endpoint URL (e.g. for DigitalOcean Spaces) | - |
AWS_S3_REGION |
S3 region name | - |
AWS_STORAGE_BUCKET_NAME |
S3 bucket name | - |
AWS_S3_DEFAULT_ACL |
Uploaded file ACL (private or public-read) |
private |
Usage
Backup
fastapi-dbbackup backup
# if using UV:
uv run fastapi-dbbackup backup
Restore
Restore the latest backup:
fastapi-dbbackup restore
# if using UV:
uv run fastapi-dbbackup restore
Restore a specific backup:
fastapi-dbbackup restore default-20260131-120000.dump.gz
List Backups
fastapi-dbbackup list
# if using UV:
uv run fastapi-dbbackup list
Docker Usage
Yes! fastapi-dbbackup works great with Docker. However, because it uses native database tools for maximum reliability, you must ensure the appropriate CLI clients are installed in your container.
Check Docker Usage
Tips for Docker:
- Storage: Use
DBBACKUP_STORAGE=s3to ensure your backups survive container restarts. - Volumes: If using
localstorage, mount a volume toDBBACKUP_DIR(default:backups). - Database URL: Ensure your
DATABASE_URLuses the service name defined in yourdocker-compose.yml(e.g.,postgres://user:pass@db:5432/dbname).
License
MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_dbbackup-0.1.4.tar.gz.
File metadata
- Download URL: fastapi_dbbackup-0.1.4.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5099f8c18dd12c57fc4d5d0cdd50f3fa280fd35cb20671fcb9f584e2d0e4a4ac
|
|
| MD5 |
26374037b2de1f9db2670894ff9ce5e9
|
|
| BLAKE2b-256 |
f2cbc5db948fbf0583937963bc7b0c89ba875c0e6a124689b40d5a1ccbb2ad23
|
Provenance
The following attestation bundles were made for fastapi_dbbackup-0.1.4.tar.gz:
Publisher:
publish.yml on rajsolodev/fastapi-dbbackup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_dbbackup-0.1.4.tar.gz -
Subject digest:
5099f8c18dd12c57fc4d5d0cdd50f3fa280fd35cb20671fcb9f584e2d0e4a4ac - Sigstore transparency entry: 894751649
- Sigstore integration time:
-
Permalink:
rajsolodev/fastapi-dbbackup@59be81bb6a60a53eda6bf366ddc9dc186bf37208 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/rajsolodev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@59be81bb6a60a53eda6bf366ddc9dc186bf37208 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_dbbackup-0.1.4-py3-none-any.whl.
File metadata
- Download URL: fastapi_dbbackup-0.1.4-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d25154859afcdae35a8607ce859e69ae002981ccbcdb5c58dca942ea9f951c7
|
|
| MD5 |
c10c2ee755e6bd48d8c28677dd64265c
|
|
| BLAKE2b-256 |
520f873d3b864dca528817c42b84d7aa40e8a99d1715b1eea23a10c2e4b86210
|
Provenance
The following attestation bundles were made for fastapi_dbbackup-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on rajsolodev/fastapi-dbbackup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_dbbackup-0.1.4-py3-none-any.whl -
Subject digest:
3d25154859afcdae35a8607ce859e69ae002981ccbcdb5c58dca942ea9f951c7 - Sigstore transparency entry: 894751668
- Sigstore integration time:
-
Permalink:
rajsolodev/fastapi-dbbackup@59be81bb6a60a53eda6bf366ddc9dc186bf37208 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/rajsolodev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@59be81bb6a60a53eda6bf366ddc9dc186bf37208 -
Trigger Event:
release
-
Statement type: