#!/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 '} '
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 '} '
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 '} '
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 '} '
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
Recovery:
#!/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 data backup and recovery scripts