Novice MongoDB Learning---(vii) MongoDB Backup (mongodump) and recovery (Mongorerstore)

Source: Internet
Author: User
Tags mongodb server mongodump

MongoDB Data Backup

In MongoDB we use the Mongodump command to back up MongoDB data. The command can export all data to the specified directory.

The Mongodump command allows you to specify the server to which the exported data can be dumped by parameter.

Grammar

The mongodump command script syntax is as follows:

 >---o dbdirectory
    • -H:

      MONGDB the server address, for example: 127.0.0.1, you can also specify the port number: 127.0.0.1:27017

    • -D:

      The database instance that needs to be backed up, for example: test

    • -O:

      Backup data storage location, for example: C:\data\dump, of course, the directory needs to be established in advance, after the backup is completed, the system automatically establishes a test directory under the Dump directory, which holds the backup data of the database instance.



The list of optional parameters for the Mongodump command is as follows:

Grammar Description Example
Mongodump--host host_name--port port_number This command will back up all MONGODB data Mongodump--host w3cschool.cc--port 27017
Mongodump--dbpath Db_path--out backup_directory Mongodump--dbpath/data/db/--out/data/backup/
Mongodump--collection Collection--db db_name The command backs up a collection of the specified databases. Mongodump--collection mycol--db test
MongoDB Data Recovery

MongoDB uses the Mongorerstore command to restore the backed up data.

Grammar

The mongorestore command script syntax is as follows:

 >----Directoryperdb dbdirectory
    • -H:

      MongoDB server Address

    • -D:

      A database instance that needs to be recovered, for example: test, and of course the name can be different from the backup time, such as Test2

    • --directoryperdb:

      Where to back up your data, for example: C:\data\dump\test, why add a test here instead of a dump at backup time, and read the tips yourself!

    • --drop:

      When recovering, delete the current data and then restore the backed up data. That is, after the recovery, add the modified data after the backup will be deleted, use with caution Oh!


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Novice MongoDB Learning---(vii) MongoDB Backup (mongodump) and recovery (Mongorerstore)

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.