A modular Node.js CLI tool for backing up MongoDB, MySQL, and PostgreSQL databases to JSON files. Automate your database exports for migration, archiving, or disaster recovery. 🚀
- 🔒 Secure, interactive CLI for credentials
- 🗄️ Supports MongoDB, MySQL, PostgreSQL
- 📁 Validates and creates output directories
- 📦 Exports each table/collection as a separate JSON file
- 🌊 Streaming backups for MongoDB — memory-efficient for large datasets
- 🔌 Adapter pattern architecture — add new databases without touching core logic
- 🧪 Unit tested with Vitest
- 🖥️ Verbose mode toggle for detailed or silent output
git clone https://github.com/MB-PieSec/Database-Backup-Utility.git
cd Database-Backup-Utility
npm installnpm run startThe CLI will guide you through the following steps:
- Enable or disable verbose mode
- Select your database type (MongoDB, MySQL, PostgreSQL)
- Enter connection details — manual or connection string (MongoDB & PostgreSQL)
- Confirm backup and specify output directory
Each collection or table is saved as a separate .json file in your chosen directory:
backups/
users.json
products.json
orders.json
The project is built around the IDatabaseBackupService interface, which all database adapters implement:
interface IDatabaseBackupService {
connectToDatabase(): Promise<boolean | void>;
backup(outputPath: string): Promise<void>;
disconnect(): Promise<void>;
}Adding support for a new database requires only creating a new service class that implements this interface — no changes to the core CLI or controller logic.
MongoDB backups use Node.js Streams and pipeline to handle large collections with minimal memory overhead — documents are serialized and written to disk one at a time rather than loading the entire collection into memory.
src/
cli/
index.ts — entry point, database selection
controllers/
mongoController.ts
postgreSQLController.ts
mySQLController.ts
services/
mongoBackupService.ts
postgreSQLBackupService.ts
mySQLBackupService.ts
interfaces/
IDatabaseBackupService.ts
Credentials.ts
utils/
askQuestions.ts
getCredentials.ts
validateOutputPath.ts
__tests__/
getCredentials.test.ts
mongoBackupService.test.ts
Tests are written with Vitest and cover:
getCredentials— all three database types, manual and connection string paths, validation errorsMongoBackupService— connection success/failure, backup happy path, edge cases
npm testPull requests are welcome! Please open issues for bugs or feature requests.
This project is licensed under the MIT License.
Made with ❤️ by MB-PieSec
For questions, reach out via GitHub Issues