Skip to content

Instantly share code, notes, and snippets.

@kehers
Created November 24, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kehers/990e47685dbcb2f4244df75cbe39300b to your computer and use it in GitHub Desktop.
Save kehers/990e47685dbcb2f4244df75cbe39300b to your computer and use it in GitHub Desktop.
Quick way to transfer data from one mongodb server to another
#!/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