Mongodb Backup and recovery
First, Create a library, and then insert the data
Then make a backup:
The first thing to do is to erase the database and the data.
Then recover the data:
The data has been restored back
Create a library again to insert data
Then back up
If you want to recover, delete the database first and then restore
If you want to restore a single collection and backup:
One, collection backup
Mongoexport-h collection where server address-D database-C collection-O Local file storage location
Note: File format is optional json, CVS, etc.
Official Number Description:mongoexport--help
Second, set restore
Mongoimport--host Destination IP--port destination port--db target database--collection Destination collection--file backup file location
Http://blog.sina.com.cn/s/blog_a51dfb960101jyo5.html
can refer to
#获取系统时间并转换成毫秒数
current= ' Date ' +%y-%m-%d%h:%m:%s "';
timestamp= ' date-d ' $current "+%s";
#当前时间的毫秒数
currenttimestamp=$ ((timestamp*1000));
#一个小时前这个时候的毫秒数
yestodaytimestamp=$ ((currenttimestamp-43*60*60*1000));
Echo $current;
Echo $timeStamp;
Echo $currentTimeStamp;
Echo $yestodayTimeStamp;
echo "File not Exist!dump ' date" +%y-%m-%d%h:%m:%s "' $currentTimeStamp $yestodayTimeStamp" >>/home/admin/ Testlog.log
#备份新产生表
/home/admin/mongodb305/mongodb305/bin/mongodump--port 47017-u admin-p admin-d admin-c alarm-q ' {" RecTime ": {$GT E: ' $yestodayTimeStamp ', $lt: ' $currentTimeStamp '} '-o/home/admin/dumptest;
/home/admin/mongodb305/mongodb305/bin/mongodump--port 47017-u admin-p admin-d admin-c filtering_alarm-q ' {" Rec Time ": {$gte: ' $yestodayTimeStamp ', $lt: ' $currentTimeStamp '}} '-o/home/admin/dumptest;
/home/admin/mongodb305/mongodb305/bin/mongodump--port 47017-u admin-p admin-d admin-c combine_alarm-q ' {" RecTi Me ": {$gte: ' $yestodayTimeStamp ', $lt: ' $currentTimeStamp '}} '-o/home/admin/dumptest;
/home/admin/mongodb305/mongodb305/bin/mongodump--port 47017-u admin-p admin-d admin-c processed_alarm-q ' {" Rec Time ": {$gte: ' $yestodayTimeStamp ', $lt: ' $currentTimeStamp '}} '-o/home/admin/dumptest
/home/admin/mongodb305/mongodb305/bin/mongorestore-h 192.168.0.213--port 27017-u admin-p admin-d admin-c Alarm --keepindexversion--maintaininsertionorder/home/admin/dumptest/admin/alarm.bson;
/home/admin/mongodb305/mongodb305/bin/mongorestore-h 192.168.0.213--port 27017-u admin-p admin-d admin-c filte Ring_alarm--keepindexversion--maintaininsertionorder/home/admin/dumptest/admin/filtering_alarm.bson;
/home/admin/mongodb305/mongodb305/bin/mongorestore-h 192.168.0.213--port 27017-u admin-p admin-d admin-c Combi Ne_alarm--keepindexversion--maintaininsertionorder/home/admin/dumptest/admin/combine_alarm.bson;
/home/admin/mongodb305/mongodb305/bin/mongorestore-h 192.168.0.213--port 27017-u admin-p admin-d admin-c processed_a Larm--keepindexversion--maintaininsertionorder/home/admin/dumptest/admin/processed_alarm.bson
MongoDB Backup and Recovery