Backup Mongo Database to S3 Script
Hi , Some people face problems in automating the mongo database and storing into Aws S3 Before that please add a role of s3 to the instance and please do not keep you Aws credentials in your server . Below is the script where you can backup your mongo Db and store in your S3 account #!/bin/sh echo "Started" DIR=`date +%m%d%y` AWSPATH="/home/ubuntu/.local/bin/aws" MONGODUMP_PATH="/usr/bin/mongodump" ORGDEST=~/db_backups DEST=~/db_backups/$DIR S3FILES=$(aws s3 ls s3:// s3-name /db_backups/ 2>&1 | grep "$DIR" ) if [ ! -z "$S3FILES" ]; then echo "$S3FILES exist" exit 1 fi mkdir -p $DEST $MONGODUMP_PATH -u admin -p "Your Passoword" --authenticationDatabase admin -o $DEST --oplog cd $ORGDEST tar cvzf $DIR.tar.gz $DIR rm -r $DIR $AWSPATH s3 cp $DIR.tar.gz s3:// s3-name /db_backups/ rm -rf $DIR.tar.gz You can run this script in your cron tab for periodically Backup