-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update the scripts to include a help option and allow the changing of hosts and filenames * update readme to reflect script changes * Changes to readme with extra instruction and formatting * update scripts to use printf for better portability * update scripts to use printf for better portability --------- Co-authored-by: A. K <[email protected]>
- Loading branch information
1 parent
0f633ad
commit b1327ef
Showing
6 changed files
with
105 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,3 +111,6 @@ dist | |
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
# database dumps | ||
*.dump |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# /bin/sh | ||
|
||
R="\033[0;31m" | ||
G="\033[0;32m" | ||
|
||
POSITIONAL_ARGS=() | ||
|
||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-o|--output) | ||
OUTPUTPATH="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-r|--remote) | ||
if [ "$REMOTE" != "staging" ] && [ "$REMOTE" != "prod" ]; then | ||
printf "Error: Invalid value for remote. Allowed values are 'staging' or 'prod'." | ||
exit 1 | ||
fi | ||
REMOTE="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-h|--help) | ||
printf "This script will clone the mongodb data on either staging or prod so it can be used locally.\nkubectl will need to be setup and authenticated to access the cluster\n\n" | ||
printf "options:\n" | ||
printf "${G}-o --output The output path for the database dump including the filename (default: ./database.dump)\n" | ||
printf "${G}-r --remote Which remote to use, must be either 'staging' or 'prod' (default: staging)\n" | ||
exit 0 | ||
;; | ||
-*|--*) | ||
printf -e "${R}Unknown option $1" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
OUTPUTPATH="${OUTPUTPATH:-./database.dump}" | ||
REMOTE="${REMOTE:-staging}" | ||
|
||
# port forward to cluster | ||
kubectl port-forward -n epp--${REMOTE} service/epp-database-psmdb-db-replicaset 27017:27017 & | ||
process_pid=$! | ||
|
||
# get creds for db | ||
credentials=$(kubectl get secret epp-database-psmdb-db-secrets -o yaml -n epp--${REMOTE}) | ||
password=$(echo "$credentials" | grep 'MONGODB_DATABASE_ADMIN_PASSWORD' | cut -d ':' -f 2 | xargs | base64 -d | cut -d '%' -f 1) | ||
username=$(echo "$credentials" | grep 'MONGODB_DATABASE_ADMIN_USER' | cut -d ':' -f 2 | xargs | base64 -d | cut -d '%' -f 1) | ||
|
||
# clone db to local file | ||
mongodump --host 127.0.0.1 --port 27017 --username $username --password $password --authenticationDatabase admin --db epp --collection versioned_articles --out ${OUTPUTPATH} | ||
|
||
# kill port forwarding | ||
kill $process_pid |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# /bin/sh | ||
|
||
R="\033[0;31m" | ||
G="\033[0;32m" | ||
|
||
POSITIONAL_ARGS=() | ||
|
||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-i|--input) | ||
INPUTPATH="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-h|--help) | ||
printf "This script will restore a mongodb data dump into a local mongodb docker container." | ||
printf | ||
printf "options:" | ||
printf -e "${G}-i --input The input path for the database dump including the filename (default: ./database.dump)" | ||
exit 0 | ||
;; | ||
|
||
-*|--*) | ||
printf -e "${R}Unknown option $1" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
INPUTPATH="${INPUTPATH:-./database.dump}" | ||
|
||
# push local file to docker container | ||
mongo_container_id=$(docker ps -f 'name=mongodb' -q) | ||
docker cp ${INPUTPATH} $mongo_container_id:/tmp/database.dump | ||
|
||
docker compose exec mongodb mongorestore --uri="mongodb://admin:testtest@localhost:27017" --authenticationDatabase=admin --drop --nsInclude=epp.versioned_articles /tmp/database.dump |
This file was deleted.
Oops, something went wrong.