1.0.1 • Published 2 years ago

mongodb_backup_s3 v1.0.1

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

Bakcup and Uplaod MongoDB to AWS S3

What can it do ?

A package to backup mongodb database to amazon s3 bucket

How do I get set up?

  • Install the package npm install mongodb_backup_s3
  • Import it into your file
  • Setup a backup client with your aws credential
  • Initiate the backup

Notes about the generated dump

The generated mongo dump is an archive, so while restoring you should mark the --archive flag on

mongorestore --archive=/path/to/dump

Working example:

const mongoS3Backup = require("mongodb_backup_s3");

const bucketName = process.env.AWS_S3_DUMP_BUCKET;
const accessKey = process.env.AWS_ACCESS_KEY_ID;
const accessSecret = process.env.AWS_SECRET_ACCESS_KEY;
const dbConnectionUri = process.env.MONGO_URI;

const backupClient = mongoS3Backup({ bucketName, accessKey, accessSecret });

backupClient
  .backupDatabase({
    uri: dbConnectionUri,
    backupName: "test_backup_" + Date.now(),
    prefix: "backups/",
    ACL : "public-read"
  })
  .then((response) => {
    console.log("Success response ", response);
  })
  .catch((err) => {
    console.log("error is ", err);
  });

Possible options passed to backupDatabase method

  • uri: string required the connection string for the mongo database `
  • backupName: string required the name of the backup to be dumped on s3
  • gzip: true|false wheather to use gzip option for the dump command, defaults to false

The package supports both promises & callback patterns