Dump Mongo DB and move it to an S3 bucket.
#!/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 |
This comment has been minimized.
This comment has been minimized.
You can replace:
By:
It's nicer and in case you have a script with several times questions to ask, it stays cleaner that way. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
http://www.crybit.com/dump-mongo-db-and-move-to-s3/
Details added here.