A robust, pluggable, and developer-friendly CLI utility designed to automate the lifecycle of database backups. Whether you need a quick manual dump or a fully automated, scheduled, and verified backup strategy, this tool has you covered.
- Pluggable Connectors: Unified interface for Postgres, MySQL, MongoDB, and SQLite.
- Integrity Verification: Doesn't just backup; it verifies backups by comparing table/collection counts and computing checksums.
- Built-in Scheduler: Integrated Cron engine with timezone support for automated, hands-off operations.
- Smart Retention: Automatically prunes old backups based on count (
keepLast) or age (keepDays). - Compression: Supports
tar.gz,zip, andrawformats with configurable compression levels. - Hybrid UI: Includes a lightweight Express-based Web Dashboard for visual management.
- Flexible Config: Supports YAML files,
.envfiles, and direct CLI flag overrides.
DatabaseBackupUtility-CLI/
├── src/
│ ├── cli.js # Main entry point using Commander.js
│ ├── commands/ # Implementation of CLI sub-commands (backup, restore, etc.)
│ ├── connectors/ # Database-specific logic (Postgres, MySQL, Mongo, SQLite)
│ ├── config/ # Logic for merging YAML and Environment Variables
│ ├── scheduler/ # node-cron logic and process lock utilities
│ ├── server/ # Express.js server for the Web UI
│ └── utils/ # Shared helpers (Logger, File System, Compression)
├── config/ # Pre-defined configuration templates
├── testing/ # Dockerized environment for multi-DB local testing
├── public/ # Frontend assets for the Web Dashboard
└── backups/ # Default destination for generated dump files
npm install -g .
# The "db-backup" command is now available globally
npm install
node ./src/cli.js --help
All commands support the global flags:
-c, --config <path>: Path to YAML config (Default:config/default.yaml).-v, --verbose: Enable detailed debug logging.
Triggers a database backup based on the current configuration.
-
Options:
-
-d, --database <name>: Override the database name. -
--format <fmt>: Override format (tar.gz,zip,raw). -
--prune-after: Immediately run retention policy after successful backup. -
Example:
db-backup backup --prune-after
Restores a database from a specific backup file.
-
Options:
-
--clean: Drop existing database objects before restoring. -
--create-db: Create the target database if it doesn't exist. -
--target-db <name>: Restore into a different database name. -
Example:
db-backup restore ./backups/my-db.tar.gz --clean
Validates the integrity of a backup file.
-
Options:
-
--all: Check every single table/collection instead of a sample. -
--sample <n>: Number of objects to sample (Default: 20). -
--fast: Use estimated counts where supported by the engine. -
Example:
db-backup verify ./backups/my-db.tar.gz --all
Lists all available backups in the configured storage directory.
- Example:
db-backup list
Manually trigger the retention policy to delete old backups.
-
Options:
-
--keep-last <n>: Keep only the most recent files. -
--keep-days <d>: Keep files newer than days. -
--dry-run: Preview which files would be deleted without removing them. -
Example:
db-backup prune --keep-last 10 --dry-run
Starts the Cron-based scheduler.
-
Options:
-
--run-now: Execute one backup immediately and then start the schedule. -
Example:
db-backup schedule
Displays the current environment status, including masked connection strings and the availability/version of native tools (like mysqldump or pg_dump).
- Example:
db-backup profile
- Fork the repo and create your branch:
git checkout -b feature/new-connector. - Ensure native tools are installed for the database you are testing.
- Run Tests: Use the
testing/docker-compose.ymlto spin up test databases. - Submit a PR: Provide a clear description of changes and any new dependencies.
This project is licensed under the ISC License.