From 08f2b8432f1e1dd6abd470f290830cb5112da228 Mon Sep 17 00:00:00 2001 From: Aroosha Pervaiz Date: Fri, 20 Oct 2023 14:40:26 +0200 Subject: [PATCH 1/2] Changes to mongo_manage script to work properly. Changes to mongo_manage script to work properly. Changes to mongo_manage script to work properly. --- .../mongodb/source/mongotools/mongo_manage.sh | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docker/mongodb/source/mongotools/mongo_manage.sh b/docker/mongodb/source/mongotools/mongo_manage.sh index 948b2da78..d32a035e0 100755 --- a/docker/mongodb/source/mongotools/mongo_manage.sh +++ b/docker/mongodb/source/mongotools/mongo_manage.sh @@ -37,6 +37,7 @@ init(){ USERNAME=`cat $CONFIG | grep USERNAME | sed -e "s,USERNAME=,,g"` PASSWORD=`cat $CONFIG | grep PASSWORD | sed -e "s,PASSWORD=,,g"` BACKUP_DIR=`cat $CONFIG | grep BACKUP_DIR | sed -e "s,BACKUP_DIR=,,g"` + RS_NAME=`cat $CONFIG | grep RS_NAME | sed -e "s,BACKUP_DIR=,,g"` else if [ -z "$AGE_KEY" ]; then echo "AGE_KEY environment is not set, please generate appropriate key file" @@ -51,6 +52,7 @@ init(){ USERNAME=`age -i $AGE_KEY --decrypt -o - $CONFIG | grep USERNAME | sed -e "s,USERNAME=,,g"` PASSWORD=`age -i $AGE_KEY --decrypt -o - $CONFIG | grep PASSWORD | sed -e "s,PASSWORD=,,g"` BACKUP_DIR=`age -i $AGE_KEY --decrypt -o - $CONFIG | grep BACKUP_DIR | sed -e "s,BACKUP_DIR=,,g"` + RS_NAME=`age -i $AGE_KEY --decrypt -o - $CONFIG | grep RS_NAME | sed -e "s,RS_NAME=,,g"` fi if [ -z "$USERNAME" ]; then echo "Unable to locate USERNAME in $CONFIG" @@ -60,6 +62,10 @@ init(){ echo "Unable to locate PASSWORD in $CONFIG" exit 1 fi + if [ -z "$RS_NAME" ]; then + echo "Unable to locate RS_NAME in $CONFIG" + exit 1 + fi if [ "$ACTION" == "backup" ]; then if [ -z "$URI" ]; then echo "Unable to locate URI in $CONFIG" @@ -93,20 +99,14 @@ backup() # Get the current date and time DATE=$(date +%Y-%m-%d_%H-%M-%S) - # Loop through each database and run mongodump for dbName in "msOutputDBPreProd" "msPileupDBPreProd" "msUnmergedDBPreProd" do echo "Dumping database: $dbName" - mongodump -vvv \ - --uri="$URI/$dbName?replicaSet=mongodb-preprod" \ - --username="$USERNAME" \ - --password="$PASSWORD" \ - --authenticationDatabase="$authdb" \ - --out="$BACKUP_DIR/$DATE" \ - --db="$dbName" + + mongodump --uri "mongodb://$USERNAME:$PASSWORD@$URI/$dbName?$RS_NAME" --authenticationDatabase=$AUTHDB --out="$BACKUP_DIR/$DATE" done - find $BACKUP_DIR -mindepth 1 -maxdepth 1 -type d -ctime +10 | xargs sudo rm -rf; + find $BACKUP_DIR -mindepth 1 -maxdepth 1 -type d -ctime +10 | xargs rm -rf; } restore() @@ -128,7 +128,7 @@ restore() --password="$PASSWORD" \ --db="$dbName" done - sudo find $BACKUP_DIR -mindepth 1 -maxdepth 1 -type d -ctime +10 | xargs rm -rf; + find $BACKUP_DIR -mindepth 1 -maxdepth 1 -type d -ctime +10 | xargs sudo rm -rf; } backup_status() From 8d066e482e1dceb28c367bef6c9a123744b7f12a Mon Sep 17 00:00:00 2001 From: Aroosha Pervaiz Date: Fri, 20 Oct 2023 14:46:22 +0200 Subject: [PATCH 2/2] Changes to mongo_manage script to work properly. --- docker/mongodb/source/mongotools/mongo_manage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/mongodb/source/mongotools/mongo_manage.sh b/docker/mongodb/source/mongotools/mongo_manage.sh index d32a035e0..3ac92aa08 100755 --- a/docker/mongodb/source/mongotools/mongo_manage.sh +++ b/docker/mongodb/source/mongotools/mongo_manage.sh @@ -128,7 +128,7 @@ restore() --password="$PASSWORD" \ --db="$dbName" done - find $BACKUP_DIR -mindepth 1 -maxdepth 1 -type d -ctime +10 | xargs sudo rm -rf; + find $BACKUP_DIR -mindepth 1 -maxdepth 1 -type d -ctime +10 | xargs rm -rf; } backup_status()