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