logo image

Writing shell script files to backup MongoDB databases

I want to share a shell script written for myself which i use to backup some of my important MongoDB databases on a regular basis. As i am going to run this script multiple times, what i am doing is every time i am creating a new folder with the name current date and time and doing the backup into that folder.

DATE=`date '+%Y-%m-%dT%H-%M-%S'`
echo $DATE 
mkdir -p /path/to/backup/directory/$DATE
mongodump --host host1 --port 27017 --db dabase1 --username u1 --password p1 --out /path/to/backup/directory/$DATE
mongodump --host host1 --port 27017 --db dabase2 --username u2 --password p2 --out /path/to/backup/directory/$DATE