码迷,mamicode.com
首页 > 其他好文 > 详细

mongo数据备份及恢复脚本

时间:2016-12-15 00:37:48      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:.gz   src   6.2   int   local   备份   res   bsp   oca   

#!/bin/bash
time="$(date +"%Y.%m.%d")"

id=`echo "show dbs;"|/usr/local/mongod3.2/bin/mongo 10.124.156.251:27018 --shell|grep ‘A[0-9]\{13\}‘|awk -F ‘ ‘ ‘{print $1}‘`
for i in $id
do
/usr/local/mongod3.2/bin/mongodump --host="10.124.156.251" --port=27018 -d $i -o /home/mongodb.bak/mongoM1/tmp/$i.dump &> /dev/null
done
cd /home/mongodb.bak/mongoM1
tar zcf $time.mongodbM1_27018.dump.tar.gz tmp/ 2> /tmp/mongo.error.log && mv $time.mongodbM1_27018.dump.tar.gz tar && rm -rf tmp/* &> /dev/null

 

id=`echo "show dbs;"|/usr/local/mongod3.2/bin/mongo 10.124.156.243:30001 --shell|grep ‘A[0-9]\{13\}‘|awk -F ‘ ‘ ‘{print $1}‘`
for i in $id
do
/usr/local/mongod3.2/bin/mongodump --host="10.124.156.243" --port=30001 -d $i -o /home/mongodb.bak/mongoM2/tmp/$i.dump &> /dev/null
done
cd /home/mongodb.bak/mongoM2
tar zcf $time.mongodbM2_30001.dump.tar.gz tmp/ 2> /tmp/mongo.error.log && mv $time.mongodbM2_30001.dump.tar.gz tar && rm -rf tmp/* &> /dev/null

 

id=`echo "show dbs;"|/usr/local/mongod3.2/bin/mongo 10.124.156.224:27019 --shell|grep ‘A[0-9]\{13\}‘|awk -F ‘ ‘ ‘{print $1}‘`
for i in $id
do
/usr/local/mongod3.2/bin/mongodump --host="10.124.156.224" --port=27019 -d $i -o /home/mongodb.bak/mongoM3/tmp/$i.dump &> /dev/null
done
cd /home/mongodb.bak/mongoM3
tar zcf $time.mongodbM3_27019.dump.tar.gz tmp/ 2> /tmp/mongo.error.log && mv $time.mongodbM3_27019.dump.tar.gz tar && rm -rf tmp/* &> /dev/null

 

id=`echo "show dbs;"|/usr/local/mongod3.2/bin/mongo 10.124.156.217:30000 --shell|grep ‘A[0-9]\{13\}‘|awk -F ‘ ‘ ‘{print $1}‘`
for i in $id
do
/usr/local/mongod3.2/bin/mongodump --host="10.124.156.217" --port=30000 -d $i -o /home/mongodb.bak/mongoM4/tmp/$i.dump &> /dev/null
done
cd /home/mongodb.bak/mongoM4
tar zcf $time.mongodbM4_30000.dump.tar.gz tmp/ 2> /tmp/mongo.error.log && mv $time.mongodbM4_30000.dump.tar.gz tar && rm -rf tmp/* &> /dev/null

 

恢复:

#!/bin/bash
dir=/usr/local/src/mongodbM4_30000_HW_dump
for i in $dir/*; do
mongorestore -h 192.168.131.133 --port 27018 --drop $i
done

 

mongo数据备份及恢复脚本

标签:.gz   src   6.2   int   local   备份   res   bsp   oca   

原文地址:http://www.cnblogs.com/zhao-pan/p/6181422.html

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