# @trapcode/mongodb-backup

> Note this package depends on [MongoDb Database tools](https://www.mongodb.com/docs/database-tools/installation/installation). Make sure you have it installed in your machine.

Latest version **1.0.4** (published 2022-10-10) · 0 weekly downloads

## Install

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

Provides the command `mongodb-backup`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-10-10 |
| First published | 2022-08-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | trapcode |

## Links

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

## Dependencies (2)

- [ora](https://npm.io/package/ora.md) 5.4.1
- [@xpresser/env](https://npm.io/package/@xpresser/env.md) ^2.0.8

## Recent versions

- 1.0.4 (latest) — 2022-10-10
- 1.0.10 (next) — 2026-06-11
- 1.0.8 — 2026-06-11
- 1.0.3 — 2022-08-21
- 1.0.2 — 2022-08-20
- 1.0.1 — 2022-08-20
- 1.0.0 — 2022-08-20

## README

# mongo-backup

Note this package depends on [MongoDb Database tools](https://www.mongodb.com/docs/database-tools/installation/installation).
Make sure you have it installed in your machine.

## Configure using environment variables
First create a .env file of this format
```dotenv
# Required
DB_SERVER=

# Optional
DB_USER=
DB_NAME=
DB_PASSWORD=
```

**Note:** `DB_USER`, `DB_NAME` and `DB_PASSWORD` are optional. This is because they can be present in the `DB_SERVER` string.

If your `DB_SERVER` string has placeholders for `user`, `password` or `database` the env variables will be used to replace them.
For example
```
<user> = DB_USER
<password> = DB_PASSWORD (Encoded)
<database> = DB_NAME
```

with the above example given
```dotenv
DB_PASSWORD=hello@world
DB_NAME=myapp
DB_SERVER="mongodb+srv://admin:<password>@server3.mongodb.net/<database>?retryWrites=true&w=majority"

# server string will be converted to
# mongodb+srv://admin:hello%40world@server3.mongodb.net/myapp?retryWrites=true&w=majority"
```


## Backup or Restore

There are two ways to go about this:
- [Npx](#npx)
- [Host Locally](#host-locally)

### Npx
```bash
npx @trapcode/mongodb-backup backup
npx @trapcode/mongodb-backup restore

# custom env file
npx @trapcode/mongodb-backup backup .backup.env
npx @trapcode/mongodb-backup restore .restore.env
```

### Host Locally
- Clone this repo.
- Create .env file

```bash
node index.js backup
node index.js restore

# custom env file
node index.js backup .backup.env
node index.js restore .restore.env
```

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