backup-mongo-to-s3
v2.0.0
Published
Make mongo db backup to s3
Downloads
15
Maintainers
Readme
backup-mongo-to-s3
A module that makes database backup and uploads to s3.
INTRODUCTION
This module involves the following steps.
- Make DB backup on disk.
- Make a zip file out of localbackup.
- Delete the local-backup directory.
- Upload the zip file to s3.
- Delete zip file, if 'keepLocalBackups' parameter is not set to true.
- Delete outdated cloud backup zip files, outdated refers to zip files older than the latest 'noOfTotalBackups'.
USAGE
- Require the module.
- Use the init method to pass argument object.
- Use the start method to start the process.
- Compatible with cron-job to schedule backup-process.
PARAMETERS
1. mongodbUri : MANDATORY | <string> | e.g. "localhost:27017"
2. backupDir : MANDATORY | <string> | e.g. "/tmp/backupDir" => The path to the directory, where localDB will be dumped.
3. zipPath : MANDATORY | <string> | e.g. '/tmp/backup.zip' => The path where the backupDir is zipped to.
4. key : MANDATORY | <string> | e.g. "jfdasdlkfjfdak3al2lkasdfjlk" => aws s3 key value.
5. secret : MANDATORY | <string> | e.g. "fdjaksdf_e34jk53wlksdj2092jk" => aws s3 secret value.
6. region : MANDATORY | <string> | e.g. 'us-southwest-01' => the region name of the s3 bucket.
7. bucket : MANDATORY | <string> | e.g. 'scheduled-backups' => The name of the bucket, where backup zips will be posted to.
8. dir : MANDATORY | <string> | e.g. 'backupDir' => The directory in the bucket, where zips are stored into.
9. name : OPTIONAL | <string> | default : 'backup' => The alias with which we want to store our backup.zip by.
10. debugMode : OPTIONAL | <boolean> | default : false => Enable logs from module, if false, module simply throws.
11. keepLocalBackups : OPTIONAL | <boolean> | default : false => retain or delete localBackup.
12. noOfTotalBackups : OPTIONAL | <number> | default : 7 => The no. of latest n-backup to keep, older ones are automatically deleted.
EXAMPLE
const module = require ('backup-mongo-to-s3');
// Take note of the MANDATORY and OPTIONAL parameters.
const config = {
mongodbUri : <string>,
backupDir : <string>,
zipPath : <string>,
keepLocalBackups : <boolean>,
noOfTotalBackups : <number>,
debug : <boolean>,
s3 : {
key : <string>,
secret : <string>,
region : <string>,
bucket : <string>,
name : <string>,
dir : <string>,
},
};
// synchronous method.
module.init (config);
// asynchronous method.
module.start ();