backinghum
v1.0.6
Published
Interactive CLI to create, list, restore, and delete MongoDB/MySQL/PostgreSQL backups.
Downloads
736
Maintainers
Readme
BACKINGHUM (A DB Backup CLI)
A Node.js command-line tool to create, list, restore, and delete database backups for:
- MongoDB
- MySQL
- PostgreSQL (local/remote and Docker mode)
The CLI is interactive and stores backup metadata in a local JSON registry under your home directory.
Install from npm
npm install -g backinghumVerify installation:
backinghum --versionDocumentation
- Installation guide: docs/INSTALLATION.md
- Commands reference: docs/COMMANDS.md
- Internal architecture: docs/ARCHITECTURE.md
Features Implemented
- Unified CLI interface for backup lifecycle operations.
- Interactive prompts for database-specific connection details.
- Adapter architecture (
BaseAdapter+ per-database adapters) for extensibility. - Backup creation for:
- MongoDB (
mongodump) - MySQL (
mysqldump) - PostgreSQL (
pg_dump) - PostgreSQL in Docker (
docker exec ... pg_dump)
- MongoDB (
- Optional backup compression during backup create:
- MySQL/PostgreSQL:
.sql.gz - MongoDB:
.tar.gzarchive of dump folder
- MySQL/PostgreSQL:
- Backup listing from registry.
- Backup restore by backup ID:
- MongoDB (
mongorestore) - MySQL (
mysql) - PostgreSQL (
psql)
- MongoDB (
- Backup deletion by backup ID (file/folder + registry entry).
- Registry persistence in
$HOME/.db_backup/backupRegistry.json. - Optional
DB_BACKUP_REGISTRY_PATHoverride is accepted only when the path is inside the current user's home directory. - Connection snapshot saved with each backup entry to support future restore runs.
Project Structure
bin/cli.js– CLI entrypoint and command wiring.src/commands/backup/– command handlers:create.jslist.jsrestore.jsdelete.js
src/adapters/– DB adapters:baseAdapter.jsadaptorFactory.jsmongoAdapter.jsmysqlAdaptor.jspostgresAdapter.js
src/prompts/– interactive prompt flows per database.src/registry/registry.js– registry read/write helpers.- Runtime registry path:
$HOME/.db_backup/backupRegistry.json. src/utils/– option normalization + utility helpers.
Prerequisites
Install Node.js (recommended LTS), then install the database client tools used by the adapters.
Required CLI tools by database
- MongoDB
mongoshmongodumpmongorestoretar(for compression)
- MySQL
mysqlmysqldumpgzip/gunzip
- PostgreSQL
psqlpg_dumpgzip/gunzip
- PostgreSQL Docker mode
docker- Container must have PostgreSQL client tools available
Installation
A) End users (recommended)
npm install -g backinghum
B) Contributors / local development
From the project root:
- Install dependencies:
npm install
- Run CLI directly:
node bin/cli.js --help
- Optional local link:
npm link
After linking, the executable command is backinghum.
CLI Walkthrough
The CLI defines these commands:
backup:createbackup:listbackup:restore <id>backup:delete <id>
Main options currently wired on backup:create:
-c, --compress→ enable compression-v, --verbose→ verbose logs
1) Create a backup
Run:
backinghum backup:create- Optional flags:
backinghum backup:create --compressbackinghum backup:create --verbosebackinghum backup:create --compress --verbose
Flow:
- CLI starts backup flow.
- Prompts for database type (
mongodb,mysql,postgres). - Runs database-specific prompt flow.
- Builds adapter from
adaptorFactory. - Tests database connection.
- Executes backup.
- Saves backup metadata in registry JSON.
MongoDB prompt flow
- Connection type:
- Local
- MongoDB Atlas (URI)
If Atlas:
- URI
- Database name
- Output directory (default
./backups)
If Local:
- Auth required? (yes/no)
- Host (default
127.0.0.1) - Port (default
27017) - Optional user/password depending on auth
- Database name
- Output directory (default
./backups)
Mongo backup output:
- Uncompressed: folder (
<database>-<timestamp>) - Compressed:
.tar.gzarchive of that folder
MySQL prompt flow
- Connection type: Local or Remote
If Local:
- Host (default
127.0.0.1) - Port (default
3306) - User
- Password
- Database name
- Output directory (default
./backups)
If Remote:
- Connection method:
- Connection URI
- Manual details
Remote + URI:
- MySQL connection URI
- Output directory (default
./backups)
Remote + Manual details:
- Host
- Port (default
3306) - User
- Password
- Database name
- SSL required? (yes/no)
- Output directory (default
./backups)
MySQL backup output:
- Uncompressed:
.sql - Compressed:
.sql.gz
PostgreSQL prompt flow
- Connection type: Local, Remote, or Docker
If Docker:
- Container name
- User
- Password
- Database name
- Output directory (default
./backups) - Uses
docker exec+pg_dump
If Local:
- Host (default
127.0.0.1) - Port (default
5432) - User
- Password
- Database name
- Output directory (default
./backups)
If Remote:
- Connection method:
- Connection URI
- Manual details
Remote + URI:
- PostgreSQL connection URI
- Output directory (default
./backups)
Remote + Manual details:
- Host
- Port (default
5432) - User
- Password
- Database name
sslmode(disableorrequire)- Output directory (default
./backups)
PostgreSQL backup output:
- Uncompressed:
.sql - Compressed:
.sql.gz
2) List backups
Run:
backinghum backup:list
What it does:
- Reads
$HOME/.db_backup/backupRegistry.json(orDB_BACKUP_REGISTRY_PATHif set to a path inside the current user's home directory) - Prints backup history with:
- ID
- DB type
- database name
- file size
- created time
- stored path
3) Restore a backup
Run:
backinghum backup:restore <id>
Flow:
- Looks up backup by ID from registry.
- Verifies connection snapshot exists in that entry.
- Prompts for restore mode:
- Merge (keep existing data)
- Replace (drop existing data)
- For replace mode, asks confirmation.
- Rebuilds adapter using saved connection data.
- Runs adapter
restore().
Restore behavior by DB:
- MongoDB:
mongorestoreagainst backup folder path. - MySQL: pipes SQL into
mysql(supports.gzinput). - PostgreSQL: pipes SQL into
psql(supports.gzinput).
4) Delete a backup
Run:
backinghum backup:delete <id>
What it does:
- Finds backup in registry.
- Deletes backup file/folder from disk (if it exists).
- Removes registry entry.
- Prints delete confirmation.
Registry Format
Each created backup is saved as an entry containing fields similar to:
iddbdatabasepathconnection(uri/host/port/user/password/mode/container)sizecompressedcreatedAt
This allows restore operations to reuse the original connection details.
For URI-based backups, if database was not explicitly provided in prompts/options, the CLI derives it from the URI path (for example /mydb → mydb) before writing the registry entry.
Typical End-to-End Example
- Create backup:
backinghum backup:create --compress --verbose
- List backups:
backinghum backup:list
- Pick an ID from output.
- Restore backup:
backinghum backup:restore 1776174984348
- Delete old backup if needed:
backinghum backup:delete 1776174984348
Notes
- The linked executable from
package.jsonisbackinghum. - The registry file path can be overridden using
DB_BACKUP_REGISTRY_PATH, but only to a location inside the current user's home directory. - Backups can contain sensitive credentials in the saved connection snapshot; protect this project directory accordingly.
Security Hardening
- Run security checks before publish:
npm testnpm run audit
prepublishOnlyenforces tests + audit before publishing.- Package publish is restricted using the
filesallowlist inpackage.jsonto reduce accidental file leakage. - Unused dependencies were removed to reduce supply-chain risk.
- Use npm 2FA and OTP-based publish for account security.
Current Tech Stack
- Node.js (ES modules)
- Commander (CLI parsing)
- Inquirer (interactive prompts)
- Native
child_processfor invoking DB tools - JSON file registry for persistence
License
ISC
