Skip to main content

Database-native backup tool for FastAPI and SQLAlchemy

Project description

fastapi-dbbackup

Database-native backup tool for FastAPI and SQLAlchemy. Similar to django-dbbackup.

Features

  • Database Support: SQLite, PostgreSQL, MySQL.
  • 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, and list commands.

Installation

pip install 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

Restore

Restore the latest backup:

fastapi-dbbackup restore

Restore a specific backup:

fastapi-dbbackup restore default-20260131-120000.dump.gz

List Backups

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.

Example Dockerfile

FROM python:3.11-slim

# Install database clients (Postgres/MySQL)
RUN apt-get update && apt-get install -y \
    postgresql-client \
    default-mysql-client \
    sqlite3 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY . .
RUN pip install fastapi-dbbackup

# Your command to run the app or a cron job
CMD ["fastapi-dbbackup", "backup"]

Tips for Docker:

  • Storage: Use DBBACKUP_STORAGE=s3 to ensure your backups survive container restarts.
  • Volumes: If using local storage, mount a volume to DBBACKUP_DIR (default: backups).
  • Database URL: Ensure your DATABASE_URL uses the service name defined in your docker-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

fastapi_dbbackup-0.1.2.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_dbbackup-0.1.2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_dbbackup-0.1.2.tar.gz.

File metadata

  • Download URL: fastapi_dbbackup-0.1.2.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastapi_dbbackup-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c6837ad30676073cfe1c3c25cac4abda5c4bf848c79225c9e4166d363e327346
MD5 b2a44469bfc253e60fac5c5102af2958
BLAKE2b-256 131b63b38c702d0143510a34734af881ca1da48bd6d9926a1f698201ab130f5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_dbbackup-0.1.2.tar.gz:

Publisher: publish.yml on rajsolodev/fastapi-dbbackup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_dbbackup-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_dbbackup-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fe1516e67bab8f9658f1d9c289af11b5e563f3c28d7d8042011254ba1250915b
MD5 a7b075c072f7deac5f14ba2f520955dc
BLAKE2b-256 2fc0d826f1888fbc7b51cbe58d1188a79e857fa326669536f21891e0b3db83b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_dbbackup-0.1.2-py3-none-any.whl:

Publisher: publish.yml on rajsolodev/fastapi-dbbackup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page