platform/common/scripts/mongo_restore.sh
Andrey Sobolev 925e028bde
Fix backup restore scripts (#7195)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
2024-11-22 13:25:09 +07:00

35 lines
1.6 KiB
Bash

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