Skip to content

This code will connect to a source MDB cluster, extract all namespaces and pass it through a dump & restore cycle. The dump is taken based on a query file to extract specific documents.

Notifications You must be signed in to change notification settings

Remmulp125/MongoDumpRestoreAllNamespaces

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SetUp

  • Download MongoDB Shell tools: https://www.mongodb.com/try/download/shell

  • Download Mongo Dump/ Restore tools (located in Database Tools): https://www.mongodb.com/try/download/database-tools

  • Create a folder to run the dump and restore from, the dump will create a folder 'dump/' at this location to store dump files.

  • Get the full path of mongodump.js and put it in executionCommand.sh

  • Get the full path of queryFile.json and put it in executionCommand.sh

  • Review the queryFile.json and understand what it is doing, should any changes be required these changes should be made now.

Note

The queryFile.json should be in extended json format. Aggregations can be used.

Running

  1. Export the source cluster connection string export $MONGODB_URI_DUMP=<source connection URI>

  2. Export the target cluster connection string export $MONGODB_URI_RESTORE=<target connection URI>

  3. From the location where the dump files will be stored, in your terminal copy and paste all of executionCommand.sh or make the executionCommand.sh executable and run the file.

  4. Monitor the output of the script for progress.

  5. Dump logs will be stored in dumplogs.out and Restore logs will be stored in restorelogs.out for future reference

Note

This is an example URI but it may vary based on the authentication method used mongodb+srv://username:[email protected]/

Important

Currently, the Mongo Restore command will not exit on failure when inserting documents e.g. duplicate key error. This can be changed, see Mongo Restore Options

Constructing Dump/ Restore command

If not using SCRAM-SHA connectivity, additional options will need to be defined in the Mongo Dump command in executionCommand.sh. See here for details: https://www.mongodb.com/docs/database-tools/mongodump/#std-option-mongodump.--sslCAFile

If not using SCRAM-SHA connectivity, additional options will need to be defined in the Mongo Restore command in executionCommand.sh. See here for details: https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--sslCAFile

If using anything other than SCRAM-SHA the authentication method will need to be defined in both Restore and Dump commands, see here: https://www.mongodb.com/docs/database-tools/mongodump/#std-option-mongodump.--authenticationMechanism

Links

Mongo Dump documentation: https://www.mongodb.com/docs/database-tools/mongodump/ Mongo Restore documentation: https://www.mongodb.com/docs/database-tools/mongorestore/

About

This code will connect to a source MDB cluster, extract all namespaces and pass it through a dump & restore cycle. The dump is taken based on a query file to extract specific documents.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published