Skip to content

Commit

Permalink
Made script slightly more user friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Maelstromeous committed Jul 29, 2023
1 parent c62c187 commit 283835c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions mongo/export-from-remote-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,29 @@ urlencode() {
done
}

echo "Database password, please!"
read password
passwordSafe=$(urlencode $password)
if [ ! -d "dumps" ]; then
mkdir dumps
fi

if [ ! $DBURL ]; then
echo "Database password, please!"
read password
passwordSafe=$(urlencode $password)
DBURL="mongodb://ps2alerts:${passwordSafe}@10.0.5.2:27017/ps2alerts?authMechanism=SCRAM-SHA-1&readPreference=primary&ssl=false&directConnection=true"
exit 1
fi

# Change the username and hostname to suit you, I'm not doing everything for you. This is based off a local tunnel to the mongodb pod directly.
for i in ${!collections[@]};
do
collection=${collections[$i]}
echo "Exporting collection ${collection}..."
mongoexport --uri="mongodb://ps2alerts:${passwordSafe}@localhost:27018/ps2alerts?authSource=admin" --collection=$collection --out=dumps/temp/$collection.json
mongoexport --uri=$DBURL --collection=$collection --out=dumps/temp/$collection.json
echo "Collection ${collection} exported!"
done

echo "Moving from temp to real folder..."
mv dumps/temp/* dumps
echo "Done!"

ls -l dumps
ls -l dumps

0 comments on commit 283835c

Please sign in to comment.