Introduction to MongoDB Cluster Backup:
A full-library backup based on a MongoDB replica + shard architecture.
[email protected] 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
Restore the entire library:
You need to specify the top level directory and delete the Config directory
/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
Introduction to MongoDB Cluster full backup