Mongodb databases are also inseparable from necessary maintenance, such as backup, recovery, import, and export.
In fact, backup and recovery are easier to import and export than normal, so most of the time you can use backup and recovery operations.
1. Back up Mongodb
Export dump-h test.xxxx.com: 52000-d dataname-o/home/aa/dev/mongodb/data
Mongodump mongo: export the database command mongodump -- help to view all the help information under this command.
-H export source
-D name of the database to be exported
-O location of the database to be exported
After the terminal rolls over N rows, the database is exported. You can view the exported files in the/home/aa/dev/mongodb/data directory, bson format (the file is not immediately visible after I export it. It will only appear after a while, for unknown reasons)
2. Resume use: mongorestore command
Mongorestore-d cmsdev/home/xx/dev/mongodb/data/cmsdev
-D: database name used
Add the directory you just exported to directly restore all tables.
If-c is used to restore a table
3. Import
Export Import-d my_mongodb-c user. dat
Parameter description:
-D indicates the database to be used. In this example, it is "my_mongodb"
-C: Specify the table to be exported. In this example, it is "user"
We can see that the table structure is implicitly created during data import.
4. Export
Export export-d my_mongodb-c user-o user. dat
Parameter description:
-D indicates the database to be used. In this example, it is "my_mongodb"
-C: Specify the table to be exported. In this example, it is "user"
-O indicates the file name to be exported. In this example, it is "user. dat"
We can see from the above that the export method uses the JSON style.