Skip to content

Instantly share code, notes, and snippets.

@mrfrase3
Last active October 4, 2019 02:46
Show Gist options
  • Save mrfrase3/5d0218b0ac5229ce7daf25a6507e1446 to your computer and use it in GitHub Desktop.
Save mrfrase3/5d0218b0ac5229ce7daf25a6507e1446 to your computer and use it in GitHub Desktop.
Transfer Mongo Database Between Servers
#!/bin/bash
# Author: mrfrase3
# run:
# chmod +x ./transfer.sh
# ./transfer.sh <oldURI> <newURI> <oldDBName> <newDBName>
# e.g.
# ./transfer.sh "mongodb://olduser:oldpass@old-server.com/old-db" "mongodb://newuser:newpass@new-server.com/new-db" "old-db" "new-db"
mongodump --uri="$1" --gzip --archive="transfer.gz"
mongorestore --nsFrom "$3.*" --nsTo "$4.*" --uri "$2" --drop --gzip --archive="transfer.gz"
rm transfer.gz
@mrfrase3
Copy link
Author

mrfrase3 commented Oct 4, 2019

I keep getting annoyed having to refer to the docs every time I want to do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment