Created
November 24, 2019 14:24
-
-
Save kehers/990e47685dbcb2f4244df75cbe39300b to your computer and use it in GitHub Desktop.
Quick way to transfer data from one mongodb server to another
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 | |
HOST="remote host" | |
PORT="remote port" | |
REMOTE_DB="" | |
LOCAL_DB="" | |
RUSER="user" | |
RPASS="pass" | |
LUSER="user" | |
LPASS="pass" | |
## DUMP REMOTE DATABASE | |
echo "Dumping '$HOST:$PORT/$REMOTE_DB'..." | |
mongodump --host $HOST:$PORT --db $REMOTE_DB -u $RUSER -p $RPASS | |
## RESTORE DUMP DIRECTORY | |
echo "Restoring to '$LOCAL_DB'..." | |
mongorestore --db $LOCAL_DB --drop dump/$REMOTE_DB -u $LUSER -p $LPASS | |
## REMOVE DUMP FILES | |
echo "Removing dump files..." | |
rm -r dump | |
echo "Finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment