If MongoDB is just a document-type database, there is no bright spot, however MongoDB's greatest advantage is read-extended, hot-backup, failback, and Auto-sharding (write extension). This section of the series to the end of the introduction of these features.Backup copy realizes the database backup simultaneously, realizes the reading and writing separation, and
It's written in front.
This article has already assumed that you have installed the MongoDB (2.6) and has opened the auth.
User
First we add the users needed to back up and recover the data, and this user needs to have ReadWrite and Useradmin permissions
Copy Code code as follows:
$ MONGO
$ use admin
$ db.auth ("admin", "youradminpasswd");
$ use backupdb
$ db.adduser ({User: "Backup
--fileUser_csv.datConnected to:127.0.0.1Imported 3 objects[Email protected] bin]#Parameter description:-type indicates the file format to import-headerline The first row is not imported because the first row is a column name-file indicates the file path to importAttention: The CSV format is good and the mainstream database supports the export to CSV format, so this format is very beneficial for heterogeneous data migration -------------------- MongoDB
use the header of the first row as the imported field--file: The file to import2、示例: sudo mongoimport -d mongotest -c users --file /home/mongodump/articles.json --type json-------------------MongoDB Backup and Recovery-------------------1. MongoDB Database backup1. Syntax:Mongodump-h dbhost-d Dbname-o dbdirectoryParameter description:-H:MONGDB the server addr
--Backup1. Back up to the default folderD:\mongodb\bin is the installation directory of MongoDBMONGODUMP-D is the BACKUP DATABASE commandTestDB database nameThe backed up database is in the Dump folder in the MongoDB installation directory2. Back up to the specified folderD:\mongodb\bin is the installation directory of
When dealing with databases, it is inevitable that data backup and recovery will occur. The following are the instructions used. I will leave them here for the time being. Data backup: E: mongodb-win32-x86_64-2.2.1binmongodump.exe -- dbCpsCommodityInfoE: mongo30329 data recovery: E: mongodb-win32-x86_64-2.2.1binmongore
Database backup –mongodump
Back up all local MongoDB databases:
Copy Code code as follows:
# mongodump-h 127.0.0.1--port 27017-o/root/db/alldb
To back up a remote specified database:
Copy Code code as follows:
# mongodump-h 192.168.1.233--port 27018-d yourdb-o/root/db/yourdb
More Mongodump Detailed
Database Restore-mongorestore
Restore all databases to
MongoDB provides backup and restore capabilities, Mongodump.exe and Mongorestore.exe files in the MongoDB download directory, respectively.1. Back up your data using the following command:>mongodump-h dbhost-d Dbname-o dbdirectory-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 th
Data backup:
Open a command prompt and go to the installed MongoDB Bin directory:
The location is as follows:
Input command:mongodump-h 127.0.0.1:27017-d runoob-o D:\mongo\data\dump
which
-H:MONGDB the server address, for example: 127.0.0.1, you can also specify a port number
-D: A database instance that needs to be backed up, for example: Runoob (database name, which can back up all collections under t
Note: In the backup file directory selection, there is a condition that the file directory, no matter how deep, can only have one file, (that is, except for the backup file can only exist folder, this condition constrains its entire directory tree)Data backup:/mongodump--host 127.0.0.1:27017-d lanzhoudb-o/data/mongodb/
1. Exporting datamongoexport-d my_mongodb-c Choice-o Choice.datParameter description:-d indicates which library to use, in this case "My_mongodb"-C indicates the table to be exported, in this case "choice"-O indicates the name of the file to be exported, in this case "choice. Dat"-H Server Address2. Import datamongoimport-d my_mongodb-c choice choice. datParameter description:-d indicates which library to use, in this case "My_mongodb"-C indicates the table to be imported, in this case "choice"3
MongoDB permissions, Backup, restore, de-weight
PermissionsData security is a critical part of a database, so here's a general procedure for setting up MongoDB user rights.First, create a new database administrator in unlicensed mode:Start the database service:mongodEnable the Named line tool:mongouse admindb.createUser({user:"gly",pwd:"[emailprotected]",role
Here, we use the LVM Logical Disk for speeding backup of Mongodb. mongodb has reached dozens of GB or more. The speed of using the mongodb tool for backup will make us feel quite slow, at this time, we can run the mongdb data directory.
Here, we use the LVM Logical Disk for
To use MongoDB, the natural use of data import and export, I learned a bit.In MONGO study (ii) there are some tools in the Bin directory, this is the use of these tools for data import and export and backup recovery.Note: The following commands are entered on the cmd command line, and are saved in the current operation directory if the export and backup are not i
MongoDB Standalone:To back up all libraries:Mongodump--host 10.10.7.33:27019--gzip--OUT/HOME/MONGODB/0415_BFTo back up the specified library:Mongodump--host 10.10.10.251:21100-d dbname--gzip-out/home/mongodb/bjdata2Restore recovery:Mongorestore--host Replica backup of the set cluster:Backup Data set:mongodump -h"ttlsa/
/mongorestore-d Test--directoryperdb dump/test/(backup directory at Mongodump)Binary backup that not only backs up data, but also backs up indexes,Backup data is relatively small.Example: Backup and recovery of single table1.dump Tea Table1 1234 -D test-c Tea2. View the dump file1 # ll dump/Test2831151 May 10 :panax n
Label:1. Data backup: Mongodump-h dbhost-d Dbname-o dbdirectory Parameter description: -H:mongdb server address, for example:127.0.0.1, of course, you can 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:c:\data\dump, of course, the directory needs to be established in advance, after the
options: -h, --host=hostname> mongodb host to connect to (setname/host1,host2 for replica sets) --port=port> server port (can also use --host hostname:port) authentication options: -u, --username=username> username for authentication -p, --password=password> password for authentication --authenticationDatabase=database-name> database that holds the user‘s credentials --authenticationMechanism= namespace options: -d, --db= -c, --collection=
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
Ex
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.