MongoDB backup and recovery

Source: Internet
Author: User
Tags mongodump mongorestore

Mongodb databases are also inseparable from necessary maintenance, such as backup, recovery, import, and export.

In fact, backup and recovery are easier to import and export than normal, so most of the time you can use backup and recovery operations.

1. Back up Mongodb

Export dump-h test.xxxx.com: 52000-d dataname-o/home/aa/dev/mongodb/data

Mongodump mongo: export the database command mongodump -- help to view all the help information under this command.

-H export source

-D name of the database to be exported

-O location of the database to be exported

After the terminal rolls over N rows, the database is exported. You can view the exported files in the/home/aa/dev/mongodb/data directory, bson format (the file is not immediately visible after I export it. It will only appear after a while, for unknown reasons)

2. Resume use: mongorestore command

Mongorestore-d cmsdev/home/xx/dev/mongodb/data/cmsdev

-D: database name used

Add the directory you just exported to directly restore all tables.

If-c is used to restore a table

3. Import

Export Import-d my_mongodb-c user. dat

Parameter description:

-D indicates the database to be used. In this example, it is "my_mongodb"

-C: Specify the table to be exported. In this example, it is "user"

We can see that the table structure is implicitly created during data import.

4. Export

Export export-d my_mongodb-c user-o user. dat

Parameter description:

-D indicates the database to be used. In this example, it is "my_mongodb"

-C: Specify the table to be exported. In this example, it is "user"

-O indicates the file name to be exported. In this example, it is "user. dat"

We can see from the above that the export method uses the JSON style.

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.