In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Mongodb is similar to mysql, so can it back up and restore databases as well as mysql? Of course, the backup and recovery of mongodb will be briefly introduced below.
1.MongoDB backup
Back up the specified library:
Mongodump-h ip-d dbname-o dir
-h is followed by server ip,-d followed by database name. If not added, all libraries are backed up.-o specifies where to backup. It is a directory.
For example: mongodump-d admin-o / tmp/mongobackup/ # back up the admin library to the / tmp/mongobackup directory
Back up all libraries:
Mongodump-h ip-o dir
Back up the specified collection:
Mongodump-d mydb-c test-o / tmp/test
-c specify the name of the collection
Export the collection as a json file:
Mongoexport-d mydb-c test-o / tmp/test.json
-o followed by a file name, not a directory
Description: mongodump backup test collection will generate test.bson and test.metadata.json files, you cannot view the document contents of the test collection by viewing these two files. The mongoexport backup test collection is a self-named .json file, and the contents of this file are the document contents of the test collection. You can see all the document contents of the test collection by looking at the .json file.
2.MongoDB recovery
Restore all libraries:
Mongorestore-drop dir/
Where dir is the directory name of the backup of all libraries, where-- drop is optional, which means that the previous data is deleted before recovery. It is not recommended to use it.
Restore the specified library:
Mongorestore-d mydbdir/
-d and the name of the library to be restored. Dir is the directory where the library was backed up.
For example: mongorestore-d / tmp/mongobackup/admin/ # restore admin database
Restore the collection:
Mongorestore-d mydb-c test dir/mydb/test.bson
-c is followed by the name of the collection to be restored. Dir is the path where the file was generated when backing up the mydb library. You need the path to the collection bson file instead of the directory.
Import the collection:
Mongoimport-d mydb-c test-- file / tmp/test.json
Mongoimport and mongoexport are relative.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.