Skip to content

mro-nerd/DB-Backup-Utility-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database Backup CLI

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.


Key Features

  • 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, and raw formats with configurable compression levels.
  • Hybrid UI: Includes a lightweight Express-based Web Dashboard for visual management.
  • Flexible Config: Supports YAML files, .env files, and direct CLI flag overrides.

Project Structure

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


🛠️ Installation

Global Install (Recommended)

npm install -g .
# The "db-backup" command is now available globally

Local Development

npm install
node ./src/cli.js --help

⌨️ Command Reference

All commands support the global flags:

  • -c, --config <path>: Path to YAML config (Default: config/default.yaml).
  • -v, --verbose: Enable detailed debug logging.

1. backup

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

2. restore <file>

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

3. verify <file>

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

4. list

Lists all available backups in the configured storage directory.

  • Example: db-backup list

5. prune

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

6. schedule

Starts the Cron-based scheduler.

  • Options:

  • --run-now: Execute one backup immediately and then start the schedule.

  • Example: db-backup schedule

7. profile

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

Contributing

  1. Fork the repo and create your branch: git checkout -b feature/new-connector.
  2. Ensure native tools are installed for the database you are testing.
  3. Run Tests: Use the testing/docker-compose.yml to spin up test databases.
  4. Submit a PR: Provide a clear description of changes and any new dependencies.

License

This project is licensed under the ISC License.


About

A pluggable CLI for automated database backups, verification, and scheduling across Postgres, MySQL, MongoDB, and SQLite. It features built-in retention policies, a lightweight web dashboard, and unified commands to simplify data lifecycle management.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors