Easily backup your docker databases
Find a file
James Paterni 67bea93bb2
Some checks are pending
Test and Build Docker Image / test (push) Waiting to run
Test and Build Docker Image / build (push) Blocked by required conditions
Fix timestamp-dependent test failures by using dynamic patterns
- Replace hardcoded timestamps with regex patterns in integration tests
- Use dynamic file discovery instead of exact filenames in unit tests
- Change timestamp pattern from specific values to \d{10} regex for 10-digit unix timestamps
- Update backup file assertions to use Dir.glob and pattern matching
- Ensure tests are robust across different execution environments and times

This resolves intermittent test failures caused by timestamp variations
between test runs and different execution contexts.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-13 23:19:12 -04:00
.github/workflows Add comprehensive RSpec testing infrastructure and enhance CI/CD pipeline 2025-07-13 23:12:59 -04:00
app Fix timestamp-dependent test failures by using dynamic patterns 2025-07-13 23:19:12 -04:00
.dockerignore Initial Commit 2025-04-14 09:39:37 -04:00
.gitignore add automatic docker building 2025-05-08 23:02:29 -04:00
.tool-versions Initial Commit 2025-04-14 09:39:37 -04:00
CLAUDE.md Add comprehensive RSpec testing infrastructure and enhance CI/CD pipeline 2025-07-13 23:12:59 -04:00
docker-compose.yml update docker-compose.yml file to run at midnight 2025-05-08 23:23:37 -04:00
Dockerfile Initial Commit 2025-04-14 09:39:37 -04:00
entrypoint.sh Initial Commit 2025-04-14 09:39:37 -04:00
LICENSE Initial commit 2025-04-05 13:58:02 +00:00
README.md update docker hub url 2025-05-08 22:54:50 -04:00
TODO.md Add comprehensive RSpec testing infrastructure and enhance CI/CD pipeline 2025-07-13 23:12:59 -04:00

baktainer

Easily backup databases running in docker containers.

Features

  • Backup MySQL, PostgreSQL, MongoDB, and SQLite databases
  • Run on a schedule using cron expressions
  • Backup databases running in docker containers
  • Define which databases to backup using docker labels

Installation

services:
  baktainer:
    image: jamez001/baktainer:latest
    container_name: baktainer
    restart: unless-stopped
    volumes:
      - ./backups:/backups
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - BT_CRON="0 0 * * *" # Backup every day at midnight
      - "BT_DOCKER_URL=unix:///var/run/docker.sock" 
      - BT_THREADS=4
      - BT_LOG_LEVEL=info
      # Enable if using SSL over tcp
      #- BT_SSL = true
      #- BT_CA
      #- BT_CERT
      #- BT_KEY    

Environment Variables

Variable Description Default
BT_CRON Cron expression for scheduling backups 0 0 * * *
BT_THREADS Number of threads to use for backups 4
BT_LOG_LEVEL Log level (debug, info, warn, error) info
BT_SSL Enable SSL for docker connection false
BT_CA Path to CA certificate none
BT_CERT Path to client certificate none
BT_KEY Path to client key none
BT_DOCKER_URL Docker URL unix:///var/run/docker.sock

Usage

Add labels to your docker containers to specify which databases to backup.

services:
  db:
    image: postgres:17
    container_name: my-db
    restart: unless-stopped
    volumes:
    - db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: "${DB_BASE:-database}"
      POSTGRES_USER: "${DB_USER:-user}"
      POSTGRES_PASSWORD: "${DB_PASSWORD:-StrongPassword}"
    labels:
      - baktainer.backup=true
      - baktainer.db.engine=postgres
      - baktainer.db.name=my-db
      - baktainer.db.user=user
      - baktainer.db.password=StrongPassword
      - baktainer.name="MyApp"

Possible Values for Labels

Label Description
baktainer.backup Set to true to enable backup for this container
baktainer.db.engine Database engine (mysql, postgres, mongodb, sqlite)
baktainer.db.name Name of the database to backup
baktainer.db.user Username for the database
baktainer.db.password Password for the database
baktainer.name Name of the application (optional). Determines name of sql dump file.

Backup Files

The backup files will be stored in the directory specified by the BT_BACKUP_DIR environment variable. The files will be named according to the following format:

/backups/<date>/<db_name>-<timestamp>.sql

Where <date> is the date of the backup ('YY-MM-DD' format) <db_name> is the name provided by baktainer.name, or the name of the database, <timestamp> is the unix timestamp of the backup.

Roadmap

  • Add support for SQLite backups
  • Add support for MongoDB backups
  • Add support for MySQL backups
  • Add support for PostgreSQL backups
  • Add support for cron scheduling
  • Add support for Docker labels to specify which databases to backup
  • Add support for Docker socket
  • Add support for Docker API over TCP
  • Add support for Docker API over SSL
  • Add support for Docker API over HTTP
  • Add support for Docker API over HTTPS
  • Add support for Docker API over Unix socket
  • Add individual hook for completed backups
  • Add hook for fullly completed backups
  • Optionally limit time for each backup