A powerful, containerized CLI tool for backing up and restoring PostgreSQL, MySQL, and MongoDB databases. Built with Spring Boot and Spring Shell.
- Multi-Database Support: Seamlessly backup and restore PostgreSQL, MySQL, and MongoDB.
- Dockerized: Runs entirely within Docker for consistent environments and easy deployment.
- Interactive CLI: User-friendly command-line interface powered by Spring Shell.
- Local & Cloud Storage: Save backups locally or extend to cloud providers (S3 support ready).
- Secure: Handles credentials securely via environment variables.
- Observability: Built-in Prometheus metrics for monitoring backup success/failure rates.
- Docker & Docker Compose installed on your machine.
- (Optional) Java 17+ if running outside Docker.
git clone <repository-url>
cd dbbackup-cli
docker-compose up -d --buildWe provide a handy PowerShell script to access the CLI directly:
.\dbbackup.ps1Or use the raw Docker command:
docker exec -it dbbackup-cli-app java -jar app.jarRun .\dbbackup.ps1 to enter the interactive shell:
shell:> help
Backup a database to local storage:
# PostgreSQL
backup --dbType postgres --host postgres_test --port 5432 --database testdb --username user --password secret
# MySQL
backup --dbType mysql --host mysql_test --port 3306 --database testdb --username root --password secret
# MongoDB
backup --dbType mongo --host mongo_test --port 27017 --database testdb --username root --password secretRestore a database from a backup ID:
restore --backupId <BACKUP_ID> --targetHost postgres_test --targetPort 5432 --targetDatabase testdb --username user --password secretView all available backups:
list-backupsThe application is configured via application.yml and environment variables in docker-compose.yml.
| Variable | Description | Default |
|---|---|---|
SPRING_DATASOURCE_URL |
Metadata DB URL | jdbc:postgresql://db:5432/db_backup_meta |
STORAGE_PROVIDER |
Storage backend | local |
STORAGE_LOCAL_PATH |
Local backup path | /var/lib/dbbackup |
- Core: Spring Boot 3.2 + Spring Shell
- Database: PostgreSQL (Metadata storage)
- Containerization: Docker + Docker Compose
- Base Image: Alpine Linux (Eclipse Temurin JRE 17)
This project follows the Hexagonal Architecture pattern to ensure the core domain logic remains independent of external frameworks and tools.
- Domain Layer (
domain): Contains the core business logic and entities. It has no dependencies on Spring Boot or external libraries. - Ports (
domain.port): Interfaces that define how the domain interacts with the outside world.- Inbound Ports: Use Cases (e.g.,
BackupUseCase,RestoreUseCase) invoked by the CLI. - Outbound Ports: Interfaces for external services (e.g.,
StoragePort,DatabaseDumpPort,MetricsPort).
- Inbound Ports: Use Cases (e.g.,
- Adapters (
adapter): Implementations of the ports.- Inbound Adapters: The CLI layer (
BackupCliAdapter) that drives the application. - Outbound Adapters: Concrete implementations for storage (
LocalStorageAdapter), database operations (PostgresDumpAdapter), and observability (PrometheusMetricsAdapter).
- Inbound Adapters: The CLI layer (
dbbackup-cli/
├── src/ # Source code
├── Dockerfile # Multi-stage Docker build (Alpine)
├── docker-compose.yml # Services (App, Postgres, MySQL, Mongo)
└── dbbackup.ps1 # Helper script for easy access
- Fork the repository.
- Create a feature branch (
git checkout -b feature/amazing-feature). - Commit your changes.
- Push to the branch.
- Open a Pull Request.
Made with ❤️ by the ChiBao Team.