Skip to content

Instantly share code, notes, and snippets.

@vbguard
Last active July 22, 2020 08:32
Show Gist options
  • Save vbguard/a639147868954d2ddba10b0e4232d693 to your computer and use it in GitHub Desktop.
Save vbguard/a639147868954d2ddba10b0e4232d693 to your computer and use it in GitHub Desktop.
Backup mongo database with all collection to folder in shell
# (1) prompt user, and read command line argument
read -p "Run the backUp DB script now? (y|n) : " answer
# (2) handle the command line argument we were given
while true
do
case $answer in
[yY]* ) read -p "Enter DB port: " port
read -p "Enter DB name: " dbName
read -p "Enter output file path with name or name: " output
mongodump --port $port -d $dbName -o $output
echo "Okay, well done."
break;;
[nN]* ) echo "Have, a nice day!"
exit;;
* ) echo "Dude, just enter Y or N, please."; break ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment