Last active
March 27, 2019 04:49
-
-
Save grodrigo/61303a907cb5d6cd1410d4c9dbe141a7 to your computer and use it in GitHub Desktop.
bash select: dump or restor mongo from container
This file contains 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 | |
PS3='Please enter your choice: ' | |
options=("Dump lab database" "Restore dump from lab" "Quit") | |
PATHNAME="./backups" | |
CWD="${PWD##*/}" | |
MACHINE=$CWD | |
MACHINE+=_mongo_1 | |
NOW=$(date +"%m-%d-%Y") | |
CWD="${PWD##*/}" | |
FILENAME="lab_${CWD}_mongo_${NOW}" | |
while true; do | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
"Dump lab database") | |
echo "Removing previous lab dump" | |
rm $PATHNAME/$FILENAME -rf | |
docker exec -it $MACHINE mongodump --gzip --archive=$PATHNAME/$FILENAME.gz | |
;; | |
"Restore dump from lab") | |
echo "Restoring mongo on: $MACHINE" | |
docker exec -it $MACHINE mongorestore --drop --gzip --archive=$PATHNAME/$FILENAME.gz | |
echo "done!" | |
;; | |
"Quit") | |
break 2 | |
;; | |
*) printf "Invalid option $REPLY, valid values: 1 and 2.\n 3 for quit\n";; | |
esac | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment