Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@ashokarun

This comment has been minimized.

Copy link
Owner Author

ashokarun commented Nov 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.