码迷,mamicode.com
首页 > 数据库 > 详细

MongoDB集群全备份简介

时间:2016-12-27 16:13:38      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:mongodb集群 备份


MongoDB集群备份简介:

      基于mongodb 副本机+分片的架构进行全库备份。 

[root@bj02-ops-sto01 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.100.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


恢复整个库:

需要指定上一级目录,并且删除config目录

/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

MongoDB集群全备份简介

标签:mongodb集群 备份

原文地址:http://lww2016.blog.51cto.com/3560553/1886473

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!