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

Source: Internet
Author: User
Tags mongodump

MongoDB Data Backup

In MongoDB we use the Mongodump command to back up MongoDB data.

The command is able to export all the data to the specified folder.

The Mongodump command is able to specify the server to which the exported data is transferred by using the number of parameters.

Grammar

The mongodump command script syntax is as follows:

 >---o dbdirectory
    • -H:

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

    • -D:

      Database instances that need to be backed up, such as: test

    • -O:

      The location where the backed up data is stored. For example: C:\data\dump. Of course, the folder needs to be established in advance, after the backup is complete, the system itself actively in the Dump folder to create a test folder. This folder contains the backup data for the database instance.



The optional list of MONGODUMP commands is as follows:

Grammar Descriptive narrative 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 Host Server address

    • -D:

      A database instance that needs to be restored, such as test, can also be a different name than the backup time, for example Test2

    • --directoryperdb:

      The location where the backup data resides. For example: C:\data\dump\test. Why do you add a test here instead of a dump at backup time? Read the tips for yourself!

    • --drop:

      When recovering, delete the current data and then restore the backed up data.

      That is, after the recovery, after the backup to add changes to the data will be deleted, use with caution oh.


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.