$ show RealOrangeOne/docker-db-auto-backup
This repository provides a Docker-based tool for automatically discovering and backing up databases running in Docker containers. The core logic resides in a single Python script (`db-auto-backup.py`) that uses the Docker SDK to list running containers, identifies database containers by image name (PostgreSQL, MySQL/MariaDB, Redis), and executes native backup commands (pg_dumpall, mysqldump, redis-cli SAVE). Backups are written to a configurable directory with optional compression (gzip, lzma, bz2, zstd) and can be scheduled via cron expressions using the pycron library. The tool also supports success hooks (e.g., healthchecks.io, Uptime Kuma) and environment variable configuration. It is designed to run as a standalone Docker container with access to the Docker socket, making it a lightweight, self-contained backup solution for Docker hosts. The codebase is well-structured with type hints, linting, and a comprehensive test suite that validates backup generation and compression across multiple database types.
The LLM identified 3 files worth highlighting for reuse:
The `resolve_image` function parses Docker image tags to extract the canonical image name, handling registry prefixes, the 'library/' prefix for official images, and tag stripping. It is a self-contained utility that could be reused in any Docker-related Python project requiring image name normalization.
The `get_success_hook_url` function implements a clean fallback pattern for resolving a success hook URL from multiple environment variables (SUCCESS_HOOK_URL, HEALTHCHECKS_ID/HEALTHCHECKS_HOST, UPTIME_KUMA_URL). It is a reusable configuration resolution pattern applicable to any project needing prioritized environment variable lookups.
The `open_file_compressed` and `get_compressed_file_extension` functions provide a clean abstraction over multiple compression algorithms (gzip, lzma, bz2, zstd, plain). They encapsulate file opening and extension mapping in a simple, extensible factory pattern that can be extracted and reused in any Python backup or data processing tool.