Learn MONGO series (10) MongoDB Backup (mongodump) and recovery (mongorerstore) monitoring (Mongostat mongotop)

Source: Internet
Author: User
Tags mongodump mongorestore

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 address, for example: 127.0.0.1, you can also specify the port number: 127.0.0.1:27017

    • -D:

      The database instance that needs to be backed up, for example: test

    • -O:

      Backup data storage location, for example: C:\data\dump, of course, the directory needs to be established in advance, after the backup is completed, the system automatically establishes a test directory under the Dump directory, which holds the backup data of the database instance.

Example: Start your Mongod service locally using 27017. Open a Command Prompt window and go to the bin directory of the MongoDB installation directory to enter the command mongodump:

C:\Program Files\mongodb\server\3.2\bin>mongodump
2016-01-13t10:27:25.076+0800 writing Admin.system.users to
2016-01-13t10:27:25.078+0800 done Dumping Admin.system.users (1 document)
2016-01-13t10:27:25.078+0800 writing admin.system.version to
2016-01-13t10:27:25.080+0800 done Dumping admin.system.version (1 document)
2016-01-13t10:27:25.082+0800 writing Admin.col to
2016-01-13t10:27:25.084+0800 writing Maxh.maxh to
2016-01-13t10:27:25.085+0800 writing Maxh.user to
2016-01-13t10:27:25.087+0800 done Dumping Admin.col (2 documents)
2016-01-13t10:27:25.088+0800 done Dumping Maxh.maxh (1 document)
2016-01-13t10:27:25.090+0800 Done Dumping Maxh.user (6 documents)

Backs up the specified database collection.

C:\Program files\mongodb\server\3.2\bin>mongodump--collection User--db Maxh
2016-01-13t10:41:55.955+0800 writing Maxh.user to
2016-01-13t10:41:55.957+0800 Done Dumping Maxh.user (6 documents)

Second, recovery

Example: Start your Mongod service locally using 27017. Open a Command Prompt window and go to the bin directory of the MongoDB installation directory to enter the command mongorestore:

C:\Program Files\mongodb\server\3.2\bin>mongorestore
2016-01-13t10:50:51.787+0800 using default ' dump ' directory
2016-01-13t10:50:51.790+0800 Building a list of DBS and collections to Restor
E from Dump dir
2016-01-13t10:50:51.793+0800 don ' t know what does with subdirectory "Test\ma
XH ", skipping ...
2016-01-13t10:50:51.796+0800 reading metadata for Maxh.user from Dump\maxh\us
Er.metadata.json
2016-01-13t10:50:51.799+0800 reading metadata for Admin.col from dump\admin\c
Ol.metadata.json
2016-01-13t10:50:51.801+0800 restoring Maxh.user from Dump\maxh\user.bson
2016-01-13t10:50:51.803+0800 reading metadata for maxh.maxh from Dump\maxh\ma
Xh.metadata.json
2016-01-13t10:50:51.805+0800 restoring Admin.col from Dump\admin\col.bson
2016-01-13t10:50:51.807+0800 restoring Maxh.maxh from Dump\maxh\maxh.bson
2016-01-13t10:50:51.818+0800 error:multiple errors in bulk operation:
-E11000 Duplicate key error Collection:admin.col index: _id_ dup key: {: Ob
Jectid (' 5694f184617e63523cfdefe1 ')}
-E11000 Duplicate key error Collection:admin.col index: _id_ dup key: {: Ob
Jectid (' 5695b2574fe3fe853bfe7c3a ')}

2016-01-13t10:50:51.825+0800 error:multiple errors in bulk operation:
-E11000 Duplicate key error Collection:maxh.user index: _id_ dup key: {: Ob
Jectid (' 56946FBA3A18F4867AECBCD1 ')}
-E11000 Duplicate key error Collection:maxh.user index: _id_ dup key: {: Ob
Jectid (' 5694714a3a18f4867aecbcd2 ')}
-E1100 0 Duplicate key Error Collection:maxh.user index: _id_ dup key: {: Ob
Jectid (' 5694ce6685cf2632ea951c05 ')}
-E110 XX duplicate key error Collection:maxh.user index: _id_ dup key: {: Ob
Jectid (' 5694d84c85cf2632ea951c06 ')}
-E11 Duplicate key error Collection:maxh.user index: _id_ dup key: {: Ob
Jectid (' 5694dab385cf2632ea951c07 ')}
-E1 Duplicate key error Collection:maxh.user index: _id_ dup key: {: Ob
Jectid (' 5694DAE885CF2632EA951C08 ')}

2016-01-13t10:50:51.838+0800 restoring indexes for collection Admin.col from
Metadata
2016-01-13t10:50:51.841+0800 error:e11000 Duplicate key error Collection:ma
Xh.maxh index: _id_ dup key: {: ObjectId (' 569467e73a18f4867aecbcd0 ')}
2016-01-13t10:50:51.844+0800 restoring indexes for collection Maxh.user from
Metadata
2016-01-13t10:50:51.847+0800 finished restoring Admin.col (2 documents)
2016-01-13t10:50:51.849+0800 restoring indexes for collection maxh.maxh from
Metadata
2016-01-13t10:50:51.851+0800 finished restoring Maxh.user (6 documents)
2016-01-13t10:50:51.855+0800 finished restoring maxh.maxh (1 document)
2016-01-13t10:50:51.857+0800 restoring users from DUMP\ADMIN\SYSTEM.USERS.BSO
N
2016-01-13t10:50:52.163+0800 Done

C:\Program files\mongodb\server\3.2\bin>

Third, monitoring

MongoDB provides the Mongostat and mongotop two commands to monitor the operation of MongoDB.

C:\Program Files\mongodb\server\3.2\bin>mongostat
Insert Query update delete getmore command% dirty% used flushes vsize Res q
R|QW Ar|aw Netin Netout conn Time
*0 *0 *0 *0 0 1|0 0.0 0.0 0 141.0M 77.0M
0|0 0|0 79b 18k 1 2016-01-13t11:14:37+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 141.0M 77.0M
0|0 0|0 79b 18k 1 2016-01-13t11:14:38+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 141.0M 77.0M
0|0 0|0 79b 18k 1 2016-01-13t11:14:39+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 141.0M 77.0M
0|0 0|0 79b 18k 1 2016-01-13t11:14:40+08:00
*0 *0 *0 *0 0 1|0 0.0 0.0 0 141.0M 77.0M
0|0 0|0 79b 18k 1 2016-01-13t11:14:41+08:00

Mongotop is also a built-in tool under MongoDB, Mongotop provides a way to track an instance of MongoDB to see which amount of time is spent reading and writing data. Mongotop provides the level of statistical data for each collection. By default, Mongotop returns every second of a value.

The following 10 is the <sleeptime> parameter, which can be used without, waiting for the length of time, in seconds, between Mongotop waits to be called. The default mongotop passed returns the data every second.

C:\Program Files\mongodb\server\3.2\bin>mongotop 10
2016-01-13t11:12:18.752+0800 Connected to:127.0.0.1

NS Total Read Write 2016-01-13t11:12:28+08:00
Admin.col 0ms 0ms 0ms
Admin.system.roles 0ms 0ms 0ms
Admin.system.users 0ms 0ms 0ms
Admin.system.version 0ms 0ms 0ms
Local.startup_log 0ms 0ms 0ms
Local.system.replset 0ms 0ms 0ms
Maxh.maxh 0ms 0ms 0ms
Maxh.user 0ms 0ms 0ms

C:\Program Files\mongodb\server\3.2\bin>mongotop--locks

To report the use of locks for each database, use Mongotop-Lock:

C:\Program Files\mongodb\server\3.2\bin>mongotop--locks
2016-01-13t11:17:15.224+0800 Failed:server does not support reporting lock I
nformation

Throw a question--------------------------------------------------------------

Learn MONGO series (10) MongoDB Backup (mongodump) and recovery (mongorerstore) monitoring (Mongostat mongotop)

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.