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.
The mongodump command script syntax is as follows:
>mongodump-h dbhost-d Dbname-o dbdirectory
- - H :mongdb
- -d : DB instance that needs to be backed up, for example: test
- -o : The data storage location of the backup, for example: c:\data\dump, of course, the directory needs to be established in advance, after the backup is completed, the system automatically in dump directory to establish a test directory, which contains the backup data of the database instance.
Action : Use 27017 locally to start your mongod service. Open a Command Prompt window and go to the bin directory of the MongoDB installation directory to enter the command mongodump:
>mongodump
After executing the above command, the client connects to the mongodb service with IP 127.0.0.1 port number 27017 and backs up all data to the bin/dump/directory. The command output is as follows
The list of optional parameters for the Mongodump command is as follows:
Syntax description instance
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_directorymongodump--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 Mongorestore command to restore the backed up data
Mongorestore-h
--host <:p ort> ,- h <:p ort>:
MongoDB server address, default is: localhost:27017
--db ,- 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
<path> :
Mongorestore The last parameter, set the location of the backup data, for example: C:\data\dump\test.
You cannot specify both the <path> and --dir options,--dir can also set up a backup directory.
-dir :
Specify the directory to be backed up
You cannot specify both the <path> and--dir options.
MONGODB7 Data Backup Data recovery