#!/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