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.
  • Compression: Gzip compression supported.
  • 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 database URL (Required) -
DBBACKUP_DIR Local 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
DBBACKUP_S3_BUCKET S3 bucket name (Required for S3) -
DBBACKUP_S3_REGION S3 region name -
DBBACKUP_S3_PREFIX S3 prefix/folder ""

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

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.0.tar.gz (10.7 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.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_dbbackup-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for fastapi_dbbackup-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e5ba2d8a7a900e29860e64180936fe4501464a1b61f88ab934c558b49d9e38b7
MD5 b1f66e1fdf27ec496150b12366114fe6
BLAKE2b-256 d3e11bf252db01277cbcdfd83d8e5b94a3630ec759ff6f5e3ce804f1c01cb861

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_dbbackup-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 821c5bf0c36365e14e6b1cb2184771112391332a7fab3a7457d80e2bd963060e
MD5 dad4d91f8619a0f5577f6c0bfc05848e
BLAKE2b-256 a80cac999e494629e75f5d0ca351719f429395c8cba1117b4eb75fa65531623b

See more details on using hashes here.

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