The importance of database backup and data recovery, I think you know, here is an example of how to manipulate data backups, examples of data recovery:
Creating test data
Create Db:testdb,collection:user, insert 10 records
MONGO MongoDB Shell version:3.0.2 connecting to:test > Use TestDB switched to DB TestDB > Db.user.insert ({id:1,na
Me: "User 1"});
Writeresult ({"ninserted": 1}) > Db.user.insert (
Tag: OOB file Data cal Objectid Error:god exists backup fileBackup:Mongodump-h localhost:27017-d test-o "D:\DATA\DB1"To restore a backup:D:\mongodb\bin>mongorestore-h localhost:27017-d test--drop "D:\data\db1\test"If you do not add--drop you will be prompted with errorserror:e11000 duplicate key error index:test.runoob.$_id_ dup key: {: ObjectId (' 5b076926d2476498526a9d3b ')}Hint that there is data in the
= = = Installation, Configuration = = =
The code is as follows
Copy Code
#下载源码包Cd/usr/local/src/mongodbWget-c http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.2.7.tgz #解压, copy the bin folder to the specified directory/usr/local/mongodbTAR-XZVF./mongodb-linux-x86_64-2.2.7.tgzCD./mongodb-linux-x86_64-2.2.7Mkdir/usr/local/mongodbC
Tags: mongod database BSP backup file export save files--useExport of databasesmongoexport-d database name-C collection name----Save address of export file and save file name. JSON--type JSONImport of databasesmongoimport-d database name-C collection name--file the file address and filename to prepare for import. JSON--type JSONPS: The Chinese in the command is commented do not directly ctrl+c,ctrl+v enter ... (Summary not exhaustive, only for persona
Mongodump-h dbhost-d Dbname-o dbdirectory backing up the MongoDB databaseReopen DOS Command boxMongodump-h 127.0.0.1:27017-d Test-o c:/test back up the database test to C:/test backup is Bson format, binary JSONUse test; Enter database testDb.dropdatabase (); Deleting a databaseRecovering a database fileMongorestore-h dbhost-d Dbname-directoryperdb dbdirectoryMongorestore-h 127.0.0.1:27017-d Test-directoryp
Back up the specified library mongodump-h ip-d dbname-o dir//-h back with server ip-d followed by database name No then backup all libraries-o after specifying where to back up it is a directoryBack up all libraries mongodump-h Ip-o dirBack up the specified collection mongodump-d mydb-c testc-o/TMP/TESTC//-c Specify the collection nameExport collection to JSON file mongoexport-d mydb-c testc-o/tmp/testc.json//-O followed by a file nameRecover all Libr
; Db.printreplicationinfo ();This is a slave, printing slave replication info.source:127.0.0.1:10000Syncedto:sun Feb 19:44:18 gmt+0800 (CST)4 secs (0 hrs) behind the freshest member (no primary available at the moment)Three. Deployment of the backup set:1. Create a configuration file for each node:[Email protected] tmp]# cat/etc/mongod_node1.confLogpath=/usr/local/mongodb/data/log/mongod_node1.logLogappend=
Backup and recovery are important technologies for data storage. This is only a single machine learning record operation.MongoDB supports backup and recovery. The backup format is bson and the backup format is JSON and CSV.
A) export bson formatIt is mainly used for backup a
Label:First, 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: >---o dbdirectory
- H:MONGDB the server
Perform backup operations with CentOS Footstep, use crontab to implement timing functions, and delete backups up to a specified number of daysSpecific operation:1. Creating a MongoDB Database backup directoryMkdir-p/home/backup/mongod_bak/-p/home/backup/mongod_bak/mongod_bak
Master-slave synchronization:
1. Create a database directory
Mkdir/mongodb/masterdb
Mkdir/mongodb/slavedb_1
Mkdir/mongodb/slavedb2.
2. Start the Master/Slave servers respectively.Start the master server to listen to port 10000
./Bin/mongod-dbpath/mongodb/masterdb/-- port10000 -- masterYou can also use master-> slave se
Tags: deleting databases ffffff version mil color mongod file Ping shaMongodb Backup and recovery First, Create a library, and then insert the dataThen make a backup:The first thing to do is to erase the database and the data.Then recover the data:The data has been restored backCreate a library again to insert dataThen back upIf you want to recover, delete the database first and then restoreIf you want to restore a single collection and backup:One, c
Backup
Grammar
mongodump -h dbhost -d dbname -o dbdirectory
-H: Server address, or port number can be specified
-D: The name of the database that needs to be backed up
-O: The data storage location of the backup, which contains the data backed up
Example 1
sudo mkdir test1baksudo mongodump -h 192.168.196.128:27017 -d test1 -o ~/Desktop/test1bakRecovery
Grammar
mongorestore -h
Label:This article describes how to use the client tool to make a remote server data backup locally.Take the client tool Mongovue as an example to explain:1. Connect the local server and the remote server database first2. In the local server (127.0.0.1), right-click Add Database, and enter the name of the databases in the popup box, for example:Note: To add a database to the local server first, use it for export.3. Select the database (Iflashbuy-log)
(1) MongoDB Export (Mongoexport).
You can run the command by running:./mongoexport--help
./mongoexport--help Options:--help produce help message-v [--verbose] being more verbose (include multiple times for more verbosity e.g.-vvvvv)--version print th
E program's version and Exit-h [--host] arg MONGO host to connect to (Parameter description.
For example, I export a table in a database.
./mongoexport-h 127.0.0.1--port 27
Five: MongoDB import, export, backup, restore, user authorizationOne: Data export, data importAs a DBA (administrator), you often encounter the need to import and export data, as described in the following utilities (bring-your-own):1: Data import MongoexportExport files in CSV format./mongoexport-d test-c User1-o/tmp/user1.out--Specify the location and filename of the export fileDatabase collection (table)
MongoDB Data Backup
In MongoDB we use the Monogodump command to back up MongoDB data. The command can export all data to the specified directory. The Monogodump command allows you to specify the server to which the exported data can be dumped by parameter.
Grammar
>mongodump-h dbhost-d Dbname-o dbdirectory
-H:MONGDB
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.