Last active
July 31, 2021 19:49
-
-
Save ashokarun/83db353f82c7637a46f3b040a4aa70f5 to your computer and use it in GitHub Desktop.
Dump Mongo DB and move it to an S3 bucket.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This will create a full db dump and store it to s3 bucket my-db-backup-bucket in folder full-db-backup | |
# You can modify all variables as you wish | |
# Here we are making dump to /data/database-backup/ make sure that the directory is there. | |
# Here we're not keeping dumps locally. | |
echo "Enter DB name: " | |
read db | |
echo "removing current backups from /data/database-backup/" | |
rm -rf /data/database-backup/* | |
echo "Creating db dump to /data/database-backup/" | |
mongodump --db $db -o /data/database-backup/$db-$(date +%F:%R) | |
status=$(echo "$?") | |
if [ $status != 0 ]; then | |
echo "Something Wrong!!" | |
else | |
echo "All set" | |
echo "Moving backup to the s3 bucket mongo-db-backup-bucket" | |
cmd="aws s3 sync /data/database-backup/ s3://my-db-backup-bucket/full-db-backup --profile user2" | |
nohup $cmd & | |
echo "Done!" | |
fi |
You can replace:
echo "Enter DB name: "
read db
By:
read -p "Enter DB name: " db
It's nicer and in case you have a script with several times questions to ask, it stays cleaner that way.
You can replace:
echo "Enter DB name: " read db
By:
read -p "Enter DB name: " db
It's nicer and in case you have a script with several times questions to ask, it stays cleaner that way.
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.crybit.com/dump-mongo-db-and-move-to-s3/
Details added here.