https://github.com/trapcodeio/mongo-backup
Backup and restore mongodb database. A wrapper around mongodb's database tools
https://github.com/trapcodeio/mongo-backup
Last synced: 12 months ago
JSON representation
Backup and restore mongodb database. A wrapper around mongodb's database tools
- Host: GitHub
- URL: https://github.com/trapcodeio/mongo-backup
- Owner: trapcodeio
- Created: 2022-08-17T23:56:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-10T12:25:36.000Z (over 3 years ago)
- Last Synced: 2025-03-20T05:34:56.636Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
```
= DB_USER
= DB_PASSWORD (Encoded)
= DB_NAME
```
with the above example given
```dotenv
DB_PASSWORD=hello@world
DB_NAME=myapp
DB_SERVER="mongodb+srv://admin:@server3.mongodb.net/?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
```