Buy traffic for your website

HOW TO TAKE MONGO CLUSTER DATABASE BACKUP IN AWS S3 FROM BASH SCRIPT

These tutorials show you an example to take a mongo cluster database backup and also move it into AWS S3 bucket by mongodump command line client-program and restore them with the help of mongorestore command line in Linux.

MONGO-REPLICA-BACKUP

mongodump is a command-line program used for taking a dump of a mongo cluster ( mongo replica set with primary, secondary, and arbiters ) in a single file.

Assume we have three servers running
Primary : 10.0.0.1
Secondary: 10.0.0.2
Arbiters: 10.0.0.3

And configure AWS-cli

Port: 27017

vim mongo-DB-dump-s3.sh (Copy and paste the below lines and change your IP, username, and password)

vim mongo-DB-dump-s3.sh (Copy and paste the below lines and change your IP, username, and password)

#/bin/bash
#Definevariable
TStamp=”$(date +”%d-%m-%y-%H-%M-%S”)”
S3BUC=”s3://mongodbbackup/dev/”
#command_to_take_dump
mongodump –uri=”mongodb://10.0.0.1:27017,10.0.0.2:27017,10.0.0.3:27017/” -u username -o mongo_backup
wait
echo “dump completed”
zip -r mongobackup-$TStamp.zip mongo_backup
wait
aws s3 cp mongobackup-*.zip $S3BUC
wait
echo “dump moved in s3 bucket successfully “

And this will be applied for all types of Mongo DB servers (Physical and Cloud: Linux ) Just replace it with your DB’s Credentials like HostName, UserName and other information.

Thank you

 

Leave a Reply

Your email address will not be published. Required fields are marked *