Skip to content

Instantly share code, notes, and snippets.

@wahengchang
Last active August 30, 2017 14:56
Show Gist options
  • Save wahengchang/9c0c5f1cd7e3a2560c22bdd5c7f74185 to your computer and use it in GitHub Desktop.
Save wahengchang/9c0c5f1cd7e3a2560c22bdd5c7f74185 to your computer and use it in GitHub Desktop.
Shell script for backing up Mongo Databases on a given server. To dump and restore production MongoDB databases.
#####################################
####### Config Your host here #####
#####################################
FROM_DB_HOST="abc.com:1024"
TO_DB_HOST="def.mlab.com:1111"
FROM_DB_NAME="peter"
TO_DB_NAME="peter-dev"
#####################################
echo "Dump DB from :"$FROM_DB_HOST
echo " To :"$TO_DB_HOST
mongodump --host $FROM_DB_HOST --db $FROM_DB_NAME -u username -p password -o ./
echo "DB is downloaded ..."
mongorestore --host $TO_DB_HOST --db $TO_DB_NAME -u username -p password --drop ./$FROM_DB_NAME
echo "DB is cloned to target host ..."
rm -f -R ./$FROM_DB_NAME
echo "Local file is deleted ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment