Skip to content

Commit

Permalink
Merge pull request #1432 from arooshap/mongo-manage
Browse files Browse the repository at this point in the history
Some changes to the mongo_manage script to make it work properly.
  • Loading branch information
arooshap authored Oct 20, 2023
2 parents 7cd8292 + 8d066e4 commit 7d28c16
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions docker/mongodb/source/mongotools/mongo_manage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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 rm -rf;
}

backup_status()
Expand Down

0 comments on commit 7d28c16

Please sign in to comment.