Last active
July 5, 2023 12:26
-
-
Save iambryancs/1a77c0ebf219489b8a8ad72b4054c753 to your computer and use it in GitHub Desktop.
MongoDB dump and restore using mongodump and mongorestore.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SRC_DB_URI='mongodb+srv://username:password@src_host/' | |
SRC_DB_NAME=src_db_name | |
DEST_DB_URI='mongodb+srv://username:password@dest_host/' | |
#not probably needed as well as the `--db` under `mongorestore` | |
DEST_DB_NAME=dest_db_name | |
mongodump \ | |
--archive \ | |
--uri=$SRC_DB_URI \ | |
--db=$SRC_DB_NAME \ | |
--port=27017 | \ | |
mongorestore \ | |
--archive \ | |
--nsInclude="*" \ | |
--nsFrom="src_db_name.*" \ | |
--nsTo="dest_db_name.*" \ | |
--uri=$DEST_DB_URI \ | |
--db=$DEST_DB_NAME \ | |
--port=27017 -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment