1.1.0 • Published 2 years ago

@dotmind/node-mongo-dump v1.1.0

Weekly downloads
41
License
ISC
Repository
github
Last release
2 years ago

node-mongo-dump

Menu

Backup your MongoDB database on a specific frequency using mongodump.

Version

💻 Installation

npm i @dotmind/node-mongo-dump --save

🔨 Usage

Declare the function in the js file that start your server

const nodeMongoDump = require('@dotmind/node-mongo-dump');

nodeMongoDump({
  dbName: 'YOUR_DB_NAME'
});

You can use the dumpDb function to dump the database once

const dumpDb = require('@dotmind/node-mongo-dump/lib/dumpDb');

dumpDb({
  dbName: 'dbName',
  host: 'localhost',
  port: '27017',
  nbSaved: 5,
  outPath: './dumps/',
  withStdout: false,
  withStderr: false,
  withClose: false,
});

And you can use await for a sync usage. The dumpDb function will return the path where the file is saved.

const file = await dumpDb({
  dbName: 'dbName',
  host: 'localhost',
  port: '27017',
  nbSaved: 5,
  outPath: './dumps/',
  withStdout: false,
  withStderr: false,
  withClose: false,
});

And then... That's it, you're ready to go 🚀

📖 Options

ArgumentsRequiredtypeDefault ValueCommentary
dbName*truestringYour database name
frequencyfalsestring'0 0 * * *'How often you want to dump your database.
nbSavedfalsenumber14The number of dumps you want to keep. If you reach the nbSaved, it will delete the oldest before saving a new one.
hostfalsestring'localhost'Your mongodb host.
portfalsestring'27017'Your mongodb port.
outPathfalsestring'./../../dumps/'The directory where you want to save the dumps.
withStdoutfalsebooleanfalseVariable to log the output of mongodump command
withStderrfalsebooleanfalseVariable to log the errors of mongodump command
withClosefalsebooleanfalseVariable to log the ouendtput of mongodump command

dumpDb

ArgumentsRequiredtypeDefault ValueCommentary
dbName*truestringYour database name
nbSavedfalsenumber14The number of dumps you want to keep. If you reach the nbSaved, it will delete the oldest before saving a new one.
hostfalsestring'localhost'Your mongodb host.
portfalsestring'27017'Your mongodb port.
outPathfalsestring'./../../dumps/'The directory where you want to save the dumps.
withStdoutfalsebooleanfalseVariable to log the output of mongodump command
withStderrfalsebooleanfalseVariable to log the errors of mongodump command
withClosefalsebooleanfalseVariable to log the ouendtput of mongodump command

Return the path where the file is saved.

📜 License

ISC