MongoDB Database Operations--Backup restore Export Import

Source: Internet
Author: User
Tags mongodump

    • First database backup: Mongodump-h IP--port Port-u user name-p password-d database-o file exists path
127.0. 0.1 -u admin-p xxx  '/home/timeless/desktop/mongodump' --authenticationdatabase Admin

Note The--authenticationdatabase parameter makes an authentication database otherwise prompts for an error:

Failed:error connecting to DB Server:server returned error on SASL authentication step:authentication Failed.   Prompt for authentication failure

You can also specify an exported collection -collection

    • Restoring a DB instance
$ mongorestore-h xxx-u admin-p xxx-d blog/home/timeless/Desktop/mongodump/blog--authenticationdatabase Admin .- the-25T15: the:40.481+0800Building a list of collections to restore from/home/timeless/Desktop/mongodump/Blog dir .- the-25T15: the:40.491+0800Reading metadata forBlog.post from/home/timeless/Desktop/mongodump/blog/Post.metadata.json .- the-25T15: the:40.499+0800Reading metadata forBlog.user from/home/timeless/Desktop/mongodump/blog/User.metadata.json .- the-25T15: the:40.510+0800Reading metadata forBlog.meta from/home/timeless/Desktop/mongodump/blog/Meta.metadata.json .- the-25T15: the:40.555+0800Restoring Blog.meta from/home/timeless/Desktop/mongodump/blog/Meta.bson .- the-25T15: the:40.568+0800restoring indexes forCollection Blog.meta frommetadata .- the-25T15: the:40.602+0800Restoring Blog.post from/home/timeless/Desktop/mongodump/blog/Post.bson .- the-25T15: the:40.635+0800Restoring Blog.user from/home/timeless/Desktop/mongodump/blog/User.bson .- the-25T15: the:40.637+0800Finished restoring Blog.meta (3documents) .- the-25T15: the:40.637+0800restoring indexes forCollection Blog.post frommetadata .- the-25T15: the:40.645+0800Reading metadata forBlog.page from/home/timeless/Desktop/mongodump/blog/Page.metadata.json .- the-25T15: the:40.646+0800Reading metadata forBlog.content from/home/timeless/Desktop/mongodump/blog/Content.metadata.json .- the-25T15: the:40.646+0800Finished restoring Blog.post (1document) .- the-25T15: the:40.646+0800Reading metadata forBlog.option from/home/timeless/Desktop/mongodump/blog/Option.metadata.json .- the-25T15: the:40.646+0800restoring indexes forCollection Blog.user frommetadata .- the-25T15: the:40.679+0800Finished restoring Blog.user (2documents) .- the-25T15: the:40.680+0800Reading metadata forBlog.counters from/home/timeless/Desktop/mongodump/blog/Counters.metadata.json .- the-25T15: the:40.680+0800Restoring Blog.page from/home/timeless/Desktop/mongodump/blog/Page.bson .- the-25T15: the:40.707+0800Restoring Blog.option from/home/timeless/Desktop/mongodump/blog/Option.bson .- the-25T15: the:40.741+0800Restoring Blog.content from/home/timeless/Desktop/mongodump/blog/Content.bson .- the-25T15: the:40.785+0800Restoring Blog.counters from/home/timeless/Desktop/mongodump/blog/Counters.bson .- the-25T15: the:40.836+0800restoring indexes forCollection Blog.option frommetadata .- the-25T15: the:40.837+0800restoring indexes forCollection Blog.page frommetadata .- the-25T15: the:40.838+0800restoring indexes forCollection Blog.content frommetadata .- the-25T15: the:40.847+0800Finished restoring Blog.page (1document) .- the-25T15: the:40.847+0800Reading metadata forBlog.system.users from/home/timeless/Desktop/mongodump/blog/System.users.metadata.json .- the-25T15: the:40.847+0800Finished restoring Blog.content (1document) .- the-25T15: the:40.848+0800Reading metadata forBlog.webinfo from/home/timeless/Desktop/mongodump/blog/Webinfo.metadata.json .- the-25T15: the:40.848+0800restoring indexes forCollection Blog.counters frommetadata .- the-25T15: the:40.848+0800Finished restoring Blog.option (1document) .- the-25T15: the:40.884+0800Restoring Blog.webinfo from/home/timeless/Desktop/mongodump/blog/Webinfo.bson .- the-25T15: the:40.884+0800restoring indexes forCollection Blog.webinfo frommetadata .- the-25T15: the:40.916+0800Finished restoring Blog.counters (4documents) .- the-25T15: the:40.916+0800Restoring Blog.system.users from/home/timeless/Desktop/mongodump/blog/System.users.bson .- the-25T15: the:40.916+0800Finished restoring Blog.webinfo (0documents) .- the-25T15: the:40.917+0800restoring indexes forCollection Blog.system.users frommetadata .- the-25T15: the:40.928+0800Finished restoring Blog.system.users (0documents) .- the-25T15: the:40.928+0800Done

It is also possible to specify the collection to be recovered -collection

Note the place
    • Mongoimport before the import, the new database does not have the same XX table can be imported successfully;
    • Mongoexport and Mongoimport The order of each parameter input is not strict;
    • For a replica set, the data export of Mongoexport can be a primary node in a replica set, or it can be a secondary node;
    • For a replica set, the data import of Mongoimport must be a primary node;
    • For the export of large data volume, there is no production problem with mongoexport operation;
    • For large data imports (more than a few megabytes), it is easy to drag the primary node down with Mongoimport because it causes the master node to crash due to full synchronization, so avoid importing large amounts of data in the production environment. The correct approach is to establish a single point, import, and then set up a replica set.

MongoDB Database Operations--Backup restore Export Import

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.