Skip to content

Promisifying and extending(mongodb-atlas-backup) to mongodump and mongorestore your MongoDB Atlas cluster

License

Notifications You must be signed in to change notification settings

omfd/mongodb-atlas-backup-restore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The human way to mongodump and mongorestore your MongoDB Atlas cluster.

Extending the mongodb-atlas-backup package to make it more configuration driven

Improvements

  • Configuration parameters -
  • mongodump - dump to specific directory. create the directory if it doesn't exist
  • skip a process(lets say only mongorestore not mongodump and vice-versa). skip = 1 to skip it
  • Promisified the whole process - get the full mongodump and than restore it to new server(localhost/atlascluster)
  • for atlascluster restoration - use the same config object as the atlas_connection with proper credentials. "host" is for other db connection
  • proper logs to get to know the progress
  • config.js in the src/config folder contains the default configuration if you want to set it once and not pass it as an argument to the MongoBackup constructor

Install

npm install
npm start

Setup & Use

import MongoBackup from './src/index'

// Create an instance of the database atlas_connection
const backup = new MongoBackup(
    {
        atlas_connection: {
            user: '<almightyUserName>',
            password: '<PASSWORD>',
            replicaSet: 'Cluster0-shard-0',
            nodes: [
                'cluster0-shard-00-00-abcdef.mongodb.net:27017',
                'cluster0-shard-00-01-abcdef.mongodb.net:27017',
                'cluster0-shard-00-02-abcdef.mongodb.net:27017'
            ],
            database: 'mydb',
            directory: "dump",
            skip: 0
        },
        restore: {
            user: undefined,
            password: undefined,
            host: 'localhost',
            port: 27017,
            database: 'mydb',
            directory: 'dump',
            skip: 0
        }
    })
    .then((res) => {
        // Dump your cluster
        return res.dump()
    })
    .then((res) => {
        // Restore data to your cluster
        return res.restore()
    })
    .catch((err) => {
        console.log(err);
        process.exit(0)
    });

sample.js contains the example for the using it. Can be improved further in terms of making the further more configurable to support more mongodump/mongorestore parameters

About

Promisifying and extending(mongodb-atlas-backup) to mongodump and mongorestore your MongoDB Atlas cluster

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published