MongoDB Backup and Recovery

Source: Internet
Author: User
Tags mongodb mongodump mongorestore

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.