MongoDB Backup and Recovery

Source: Internet
Author: User
Tags mongodb server mongodump

System environment

Server System: Windows Server2012 R2

mongodb:v3.4.4

You can view version information by command: mongo-version

Scenario: Back up the database smp_maint_2, and revert to the new database Smp_maint_2_restore.

MongoDB Database Backup

1. Syntax:
Mongodump-h dbhost-d Dbname-o dbdirectory
Parameter description:
-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: The data storage location of the backup, for example:/home/mongodump/, of course, the directory needs to be established in advance, this directory contains the database instance backup data.
2. Example:

Find the path to the service first through the MongoDB server installed on the server: C:\Program Files\mongodb\server\3.4\bin\mongod.exe

Create a file directory on the server first: E:\data\home\momgodump

Then open cmd as an administrator and jump to the path where MongoDB is located, executing the following command:

192.168. 1.18:27017 -D smp_maint_2-o E:\data\home\momgodump

The results of the operation are as follows:

After the backup is complete, we look at the backup directory and automatically create a directory with the same name as the database, the backup file under the directory

MongoDB Database Recovery

1. Syntax:
Mongorestore-h dbhost-d dbname--dir dbdirectory

Parameter or name:
-h:mongodb server Address
-D: The database instance that needs to be restored, for example: test, and of course the name can be different from the backup time, such as Test2
--dir: Where to back up your data, for example:/home/mongodump/itcast/
--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!
2. Example:

Create a new MongoDB database Smp_maint_2_restore, and then execute the following command:

192.168. 1.18:27017 -D smp_maint_2_restore--dir E:\data\home\momgodump\smp_maint_2

The results of the operation are as follows:


Restore success!

MongoDB Backup and Recovery

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.