# @charan379/mongodb-backup

> This Node.js package allows you to backup a MongoDB database to a zip file.

Latest version **1.0.2** (published 2023-09-25) · AGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @charan379/mongodb-backup
pnpm add @charan379/mongodb-backup
yarn add @charan379/mongodb-backup
bun add @charan379/mongodb-backup
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-09-25 |
| First published | 2023-07-21 |
| Weekly downloads | 0 |
| License | AGPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 39.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | charan379 |
| Maintainers | charan379 |
| Keywords | backup, mongodb-backup, mongodb |

## Links

- npm: https://www.npmjs.com/package/@charan379/mongodb-backup
- Repository: https://github.com/charan379/mongodb-backup
- Homepage: https://github.com/charan379/mongodb-backup#readme
- Issues: https://github.com/charan379/mongodb-backup/issues
- npm.io page: https://npm.io/package/@charan379/mongodb-backup

## Dependencies (3)

- [mongodb](https://npm.io/package/mongodb.md) ^5.7.0
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.5
- [archiver](https://npm.io/package/archiver.md) ^5.3.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-09-25
- 1.0.1 — 2023-07-21
- 1.0.0 — 2023-07-21

## 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 saved

backupDatabaseToZip(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 <MONGODB_CONNECTION_STRING> <OUTPUT_ZIP_PATH>
```

Replace `<MONGODB_CONNECTION_STRING>` with your actual MongoDB connection string, and `<OUTPUT_ZIP_PATH>` 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

[![AGPL License](https://img.shields.io/badge/LICENSE-GNU%20AGPLv3-brightgreen)](https://www.gnu.org/licenses/agpl-3.0.en.html)

---
_Source: https://npm.io/package/@charan379/mongodb-backup · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
