https://github.com/charan379/mongodb-backup
This Node.js package allows you to backup a MongoDB database to a zip file.
https://github.com/charan379/mongodb-backup
backup mongodb mongodb-database
Last synced: about 2 months ago
JSON representation
This Node.js package allows you to backup a MongoDB database to a zip file.
- Host: GitHub
- URL: https://github.com/charan379/mongodb-backup
- Owner: charan379
- License: gpl-3.0
- Created: 2023-07-21T14:23:30.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-25T07:55:15.000Z (over 1 year ago)
- Last Synced: 2025-03-15T05:19:58.173Z (3 months ago)
- Topics: backup, mongodb, mongodb-database
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@charan379/mongodb-backup
- Size: 42 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongodb-backup
This Node.js package allows you to backup a MongoDB database to a zip file.
## Usage
### Method 1: Importing the Package
### Installation
First you need to install this package via npm:
```bash
npm install @charan379/mongodb-backup
```You can use this package by importing the `backupDatabaseToZip` function into your Node.js application, like below
```
const { backupDatabaseToZip } = require("mongodb-backup");const connectionString = 'mongodb://localhost:27017/your_database'; // Replace with your MongoDB connection string
const outputZipPath = 'backup.zip'; // The path where the zip file will be savedbackupDatabaseToZip(connectionString, outputZipPath)
.then(() => {
console.log('Backup completed successfully.');
})
.catch((err) => {
console.error('Error while performing the backup:', err);
});
```In this method, you can use the `backupDatabaseToZip` function with the desired MongoDB connection string and output zip path directly within your application.
### Method 2: Command Line Usage
### Installation
First you need to clone this repository from github:
```bash
git clone https://github.com/charan379/mongodb-backup.git
```To backup your MongoDB database from the command line, navigate to project folder where exportDB.js exists :
```bash
cd mongodb-backup
```
You can use the provided script `exportDB.js` directly with the node command by passing the MongoDB connection string and output zip file path as runtime arguments.##### Example command:
```bash
node exportDB.js
```Replace `` with your actual MongoDB connection string, and `` with the desired path to save the backup zip file.
###### For example:
```bash
node exportDB.js mongodb://localhost:27017/my_database my_backup.zip
```The script will connect to the specified MongoDB database, export each collection to a JSON file, zip the files into `my_backup.zip`, and save it in the current directory.
### Dependencies
This package depends on the following modules:
[archiver](https://www.npmjs.com/package/archiver) (^5.3.1)
[mongodb](https://www.npmjs.com/package/mongodb) (^5.7.0)
[shelljs](https://www.npmjs.com/package/shelljs) (^0.8.5)## Authors
- [@charan379](https://www.github.com/charan379)
## License
[](https://www.gnu.org/licenses/agpl-3.0.en.html)