diff --git a/common/scripts/dump_mongo.sh b/common/scripts/mongo_dump.sh similarity index 56% rename from common/scripts/dump_mongo.sh rename to common/scripts/mongo_dump.sh index a1fafd7f80..05b3e58d2a 100755 --- a/common/scripts/dump_mongo.sh +++ b/common/scripts/mongo_dump.sh @@ -3,6 +3,8 @@ MONGO_URL="mongodb://127.0.0.1:27017" DAYS=365 dump='dump' +trap "exit" INT + mkdir -p ${dump} mkdir -p ${dump}/workspaces @@ -14,15 +16,10 @@ mongosh ${MONGO_URL} --eval "$get_dbs" > ${dump}/databases.list mongodump --uri="${MONGO_URL}" --gzip --db account --archive="${dump}/account.gz" mongodump --uri="${MONGO_URL}" --gzip --db '%ai-bot' --archive="${dump}/ai-bot.gz" mongodump --uri="${MONGO_URL}" --gzip --db '%github' --archive="${dump}/github.gz" - -echo '#restore script' > ${dump}/restore.sh -echo "MONGO_URL=\"${MONGO_URL}\"" >> ${dump}/restore.sh -echo "do_drop=" >> ${dump}/restore.sh -echo "#do_drop=--drop" >> ${dump}/restore.sh - -echo 'mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "account" --nsTo "account" --archive=./account.gz ' >> ${dump}/restore.sh -echo 'mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "%ai-bot" --nsTo "%ai-bot" --archive=./ai-bot.gz ' >> ${dump}/restore.sh -echo 'mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "%github" --nsTo "%github" --archive=./github.gz ' >> ${dump}/restore.sh +mongodump --uri="${MONGO_URL}" --gzip --db 'calendar-service' --archive="${dump}/calendar-service.gz" +mongodump --uri="${MONGO_URL}" --gzip --db 'analytics-collector' --archive="${dump}/analytics-collector.gz" +mongodump --uri="${MONGO_URL}" --gzip --db 'gmail-service' --archive="${dump}/gmail-service.gz" +mongodump --uri="${MONGO_URL}" --gzip --db 'telegram-service' --archive="${dump}/telegram-service.gz" while IFS= read -r line; do arr=($line) @@ -35,6 +32,5 @@ while IFS= read -r line; do else mongodump --uri="$MONGO_URL" --gzip --db $db --archive=$aName fi - echo "mongorestore --uri=\"\${MONGO_URL}\" --gzip \${do_drop} --nsFrom \"${db}\" --nsTo \"${db}\" --archive=\"./workspaces/${db}-${lastVisit}.gz\"" >> ${dump}/restore.sh done < ${dump}/databases.list diff --git a/common/scripts/mongo_restore.sh b/common/scripts/mongo_restore.sh new file mode 100644 index 0000000000..de5cf2cf35 --- /dev/null +++ b/common/scripts/mongo_restore.sh @@ -0,0 +1,34 @@ +MONGO_URL="mongodb://127.0.0.1:27017" +do_drop= +#export do_drop=--drop + +postfix= +#postfix='-huly' + +trap "exit" INT + +mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "account.*" --nsTo "%account${postfix}.*" --archive=./account.gz +mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "%ai-bot.*" --nsTo "%ai-bot${postfix}.*" --archive=./ai-bot.gz +mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "%github.*" --nsTo "%github${postfix}.*" --archive=./github.gz +mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "calendar-service.*" --nsTo "%calendar-service${postfix}.*" --archive=./calendar-service.gz +mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "analytics-collector.*" --nsTo "%analytics-collector${postfix}.*" --archive=./analytics-collector.gz +mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "gmail-service.*" --nsTo "%gmail-service${postfix}.*" --archive=./gmail-service.gz +mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "telegram-service.*" --nsTo "%telegram-service${postfix}.*" --archive=./telegram-service.gz + + +while IFS= read -r line; do + arr=($line) + db="${arr[0]}" + lastVisit="${arr[1]}" + aName="./workspaces/$db-$lastVisit.gz" + stampName="./workspaces/$db-$lastVisit.gz.restored" + if [ -f $aName ]; then + if [ -f $stampName ]; then + echo "DB already restored $aName" + else + echo "Restoring DB $aName" + mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "${db}" --nsTo "${db}" --archive="./workspaces/${db}-${lastVisit}.gz" + touch ${stampName} + fi + fi +done < ./databases.list