MongoDB Study Notes (6)-data backup and data recovery

Source: Internet
Author: User
Tags mongodump
Mongodump can be used for database or table-level backup of MongoDB. The following is an example:
Back up the my_mongodb database [root @ localhost bin] #./mongodump-D my_mongodb
Connected to: 127.0.0.1
Database: my_mongodb to dump/my_mongodb
My_mongodb.system.indexes to dump/my_mongodb/system. Indexes. bson
1 objects
My_mongodb.user to dump/my_mongodb/user. bson
2 objects
[Root @ localhost bin] # ll
Total 67648
-Rwxr-XR-x 1 Root 7508756 bsondump
Drwxr-XR-x 3 Root 4096 04-10 23:54 dump
-Rwxr-XR-x 1 Root 2978016 Mongo

 

At this time, a dump directory will be created under the current directory to store the backed up files. You can also specify the directory where the backup is stored,

[Root @ localhost bin] #./mongodump-D my_mongodb-O my_mongodb_dump

Connected to: 127.0.0.1
Database: my_mongodb to my_mongodb_dump/my_mongodb
My_mongodb.system.indexes
My_mongodb_dump/my_mongodb/system. Indexes. bson
1 objects
My_mongodb.user to my_mongodb_dump/my_mongodb/user. bson
2 objects
[Root @ localhost bin] #

 

Data Recovery

[Root @ localhost bin] #./mongorestore-D my_mongodb my_mongodb_dump /*
Connected to: 127.0.0.1
Wed Apr 11 00:03:03 my_mongodb_dump/my_mongodb/user. bson
Wed Apr 11 00:03:03 going into namespace [my_mongodb.user]
Wed Apr 11 00:03:03 2 objects found
Wed Apr 11 00:03:03 my_mongodb_dump/my_mongo/ system. Indexes. bson
Wed Apr 11 00:03:03 going into namespace [my_mongodb.system.indexes]
Wed Apr 11 00:03:03 {name: "_ id _", NS: "my_mongodb.user", key: {_ ID: 1}, V: 0}
Wed Apr 11 00:03:03 1 objects found
[Root @ localhost bin] #
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.