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
Recent Comments