November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

MongoDB DB backup

MongoDB DB backup

[root@rmohan scripts]# cat mongodb_backup.sh
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/usr/local/mongodb/bin:/usr/local/mongodb/bin
export PATH
export LANG=en_US.utf8

Dbip=”192.168.1.10″
Dport=”30000″
Datetime=$(date +%Y-%m-%d_%H_%M_%S)
Logfile=”/backup/mongodb/mongodbbak_10010/backmongo.log”
Dblist=”$(echo ‘show dbs’|/usr/local/mongodb/bin/mongo –host ${Dbip} –port ${Dport} |egrep -v “MongoDB|connecting|bye”|awk ‘{print$1}’)”

echo -e “=======start for database backup `date +%F’ ‘%T’ ‘%u`=======\n” >>$Logfile
backdbcmd(){
echo “$(date) backup $dbname”
/usr/local/mongodb/bin/mongodump –host ${Dbip} –port ${Dport} –db ${dbname} –out /backup/mongodb/mongodbbak_10010/${Datetime}
echo -e “$(date) Done.\n”
}

for dbname in $Dblist
do
echo -e “——–$dbname——–\n” >>$Logfile
backdbcmd >>$Logfile 2>&1
done

/usr/local/mongodb/bin/mongorestore –port=30000 –dir=/home/mongodb/2016-07-28_00_12_05 –writeConcern='{w:0,wtimeout:200}’ –numParallelCollections=8 –numInsertionWorkersPerCollection=10 –stopOnError -v –drop

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>