Skip to content

mryellow/node-mongo-dump

 
 

Repository files navigation

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',
  uri: '',
  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',
  uri: '',
  nbSaved: 5,
  outPath: './dumps/',
  withStdout: false,
  withStderr: false,
  withClose: false,
});

And then... That's it, you're ready to go πŸš€

πŸ“– Options

Arguments Required type Default Value Commentary
dbName* true string Your database name
frequency false string '0 0 * * *' How often you want to dump your database.
nbSaved false number 14 The number of dumps you want to keep. If you reach the nbSaved, it will delete the oldest before saving a new one.
host false string 'localhost' Your mongodb host.
port false string '27017' Your mongodb port.
uri false string '' Your mongodb URI.
outPath false string './../../dumps/' The directory where you want to save the dumps.
withStdout false boolean false Variable to log the output of mongodump command
withStderr false boolean false Variable to log the errors of mongodump command
withClose false boolean false Variable to log the ouendtput of mongodump command

dumpDb

Arguments Required type Default Value Commentary
dbName* true string Your database name
nbSaved false number 14 The number of dumps you want to keep. If you reach the nbSaved, it will delete the oldest before saving a new one.
host false string 'localhost' Your mongodb host.
port false string '27017' Your mongodb port.
uri false string '' Your mongodb URI.
outPath false string './../../dumps/' The directory where you want to save the dumps.
compress true boolean true Tar and Gzip dump directory
withStdout false boolean false Variable to log the output of mongodump command
withStderr false boolean false Variable to log the errors of mongodump command
withClose false boolean false Variable to log the ouendtput of mongodump command

Return the path where the file is saved.

πŸ“œ License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%