一、备份

  在Mongodb中我们使用mongodump命令来备份MongoDB数据。该命令可以导出所有数据到指定目录中。

  mongodump命令可以通过参数指定导出的数据量级转存的服务器。

    

  mongodump命令脚本语法如下:

  >mongodump -h dbhost -d dbname -o dbdirectory
  • -h:

    MongDB所在服务器地址,例如:127.0.0.1,当然也可以指定端口号:127.0.0.1:27017

  • -d:

    需要备份的数据库实例,例如:test

  • -o:

    备份的数据存放位置,例如:c:\data\dump,当然该目录需要提前建立,在备份完成后,系统自动在dump目录下建立一个test目录,这个目录里面存放该数据库实例的备份数据。

  示例:在本地使用 27017 启动你的mongod服务。打开命令提示符窗口,进入MongoDB安装目录的bin目录输入命令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)

备份指定的数据库集合。

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)

二、恢复

  示例:在本地使用 27017 启动你的mongod服务。打开命令提示符窗口,进入MongoDB安装目录的bin目录输入命令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 to do 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') }
- E11000 duplicate key error collection: maxh.user index: _id_ dup key: { : Ob
jectId('5694ce6685cf2632ea951c05') }
- E11000 duplicate key error collection: maxh.user index: _id_ dup key: { : Ob
jectId('5694d84c85cf2632ea951c06') }
- E11000 duplicate key error collection: maxh.user index: _id_ dup key: { : Ob
jectId('5694dab385cf2632ea951c07') }
- E11000 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>

三、监控

  MongoDB中提供了mongostat 和 mongotop 两个命令来监控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也是mongodb下的一个内置工具,mongotop提供了一个方法,用来跟踪一个MongoDB的实例,查看哪些大量的时间花费在读取和写入数据。 mongotop提供每个集合的水平的统计数据。默认情况下,mongotop返回值的每一秒。

  后面的10是<sleeptime>参数 ,可以不使用,等待的时间长度,以秒为单位,mongotop等待调用之间。通过的默认mongotop返回数据的每一秒。

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

报告每个数据库的锁的使用中,使用mongotop - 锁,:

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

抛出一个问题--------------------------------------------------------------

学习mongo系列(十)MongoDB 备份(mongodump)与恢复(mongorerstore) 监控(mongostat mongotop)的更多相关文章

  1. 菜鸟的mongoDB学习---(七)MongoDB 备份(mongodump)与恢复(mongorerstore)

    MongoDB数据备份 在Mongodb中我们使用mongodump命令来备份MongoDB数据. 该命令能够导出全部数据到指定文件夹中. mongodump命令能够通过參数指定导出的数据量级转存的s ...

  2. MongoDB备份(mongodump)与恢复(mongorestore)工具实践

    mongodump和mongorestore实践 1.mongodump备份工具 mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档 ...

  3. MongoDB 备份(mongodump)与恢复(mongorestore)

    MongoDB数据备份 在Mongodb中我们使用mongodump命令来备份MongoDB数据.该命令可以导出所有数据到指定目录中. mongodump命令可以通过参数指定导出的数据量级转存的服务器 ...

  4. MongoDB备份(mongodump)和恢复(mongorestore)

    MongoDB提供了备份和恢复的功能,分别是MongoDB下载目录下的mongodump.exe和mongorestore.exe文件 1.备份数据使用下面的命令: >mongodump -h ...

  5. MongoDB 备份(mongodump)恢复(mongorerstore) 导出 (Mongoexport) 导入( Mongoimport)

    MongoDB 备份(mongodump) 在Mongodb中我们使用mongodump命令来备份MongoDB数据.该命令可以导出所有数据到指定目录中. mongodump命令可以通过参数指定导出的 ...

  6. NOSQL学习笔记系列之MongoDB 一 基础

    主题:MongoDB 学习资料参考网址: 1.http://www.w3cschool.cc/mongodb/mongodb-tutorial.html 2.http://www.icoolxue.c ...

  7. 学习mongo系列(八)密码与权限

    一.设置密码及用户角色[1] > db.createUser(... {... user: "maxh",... pwd: "123",... roles ...

  8. 学习mongo系列(六)limit(munber),skip(number)

    > db.user.find().pretty(){ "_id" : ObjectId("56946fba3a18f4867aecbcd1"), &quo ...

  9. 学习mongo系列(一) win/mac安装 解析 连接

    一.安装mongo数据库 下载链接https://www.mongodb.org/downloads, 在执行如下命令的时候事先按照目录新建如下的目录:(如果数据库安装在D盘就在D盘的根目录下建)&q ...

随机推荐

  1. 请求量限制方法-使用本地Cache记录当前请求量[坑]

    有个需求:需要限制每个账户请求服务器的次数(该次数可以配置在DB,xml文件或其他).单位:X次/分钟.若1分钟内次数<=X 则允许访问,1分钟内次数>X则不再允许访问.   这类需求很常 ...

  2. Vim ide for shell development

    Source : This article is part of the ongoing Vi / Vim Tips and Tricks Series. As a Linux sysadmin or ...

  3. discuz安装

    1.upload文件复制到根目录下,访问,安装 2.数据库需要提前建好 3.数据库地址默认是localhost,我安装时是127.0.0.1 4.最好在本地安装时,配置本地域名和线上域名一样,不然迁移 ...

  4. HandlerThread 用法

    HandlerThread最大的优势在于引入MessageQueue概念,可以进行多任务队列管理. HandlerThread背后只有一个线程,所以任务是串行依次执行的.串行相对于并行来说更安全,各任 ...

  5. [PCL]FPFH描述子

    fpfh_est.setSearchSurface(data); 如果没有设置SearchSurface,使用input数据集作为查找的表面 // If no search surface has b ...

  6. luaprofiler探索

    什么是luaprofiler? http://luaprofiler.luaforge.net/manual.html LuaProfiler is a time profiler designed ...

  7. HTTP协议 keep-alive连接 与 BS(firefox-thttpd)实验

    什么是 keep-alive 连接 https://en.wikipedia.org/wiki/HTTP_persistent_connection HTTP persistent connectio ...

  8. sdutoj 2608 Alice and Bob

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...

  9. Android -- 自定义View小Demo,绘制四位数随机码(一)

    1,现在有这样一个需求,实现显示随机随机数可能在代码中直接很简单的就实现了,但是现在我们直接自定义View来实现这个效果,那么我们来分析一波吧,我们允许开发者自己设置这个textview的大小,颜色, ...

  10. string.Format出现异常"输入的字符串格式有误"的解决方法

    string.Format出现异常"输入的字符串格式有误"的解决方法 今天在做项目时,碰到一个很奇怪的问题,我使用string.Format居然报“输入的字符串格式有误”的错误,我 ...