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 

Comments


  1. Thanks For Sharing your informatio!!!!!
    You do not need any technical knowledge to learn how to use sendy email. It’s setup takes only 50 seconds to install. Emails are sent via sendy Amazon SES setup at a very low rates. SendyBay offers powerful Sendy email marketing tool

    ReplyDelete
    Replies
    1. @sandy Bay You have replied to the wrong blog -- & by the way its sendy setup with nginx configuration is the info i have shared where people face problems setting up in nginx environment .
      But thanks :)

      Delete

Post a Comment

Popular posts from this blog

Important GIT COMMANDS

Docker Compose YML - Application , REDIS , MongoDB

Sendy Nginx Configuration