mongodb 数据库备份不成功的问题
2014-02-21 11:06
429 查看
Mongodb自带了mongodump和mongorestore这两个工具来实现对数据的备份和恢复。
mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档写入磁盘
mongodump用法:
参数说明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-o:指明到要导出的文件名
-q:指明导出数据的过滤条件
备份的命令:
mongodump -h dbhost
-d dbname
-o dbdirectory
如果mongodb设置了登录验证,则不能备份成功,报错如下:
assertion: 18 { code: 18, ok: 0.0, errmsg: "auth fails" }
则需要登录,命令如下:
C:\Users\Administrator>D:\tool\mongo\bin\mongodump -username root -password 12345
6 -d test -o d:\tool\mongo\backup
或
C:\Users\Administrator>D:\tool\mongo\bin\mongodump -username=root -password=12345
6 -d test -o d:\tool\mongo\backup
或
C:\Users\Administrator>D:\tool\mongo\bin\mongodump
-u root -p 12345
6 -d test -o d:\tool\mongo\backup
一个初学者容易出错的地方需要注意的是:
-username 和 -password后面可以接等号,也可以不接等号。
而-u 与 -p 后面不能使用等号,只能用空格隔开。
另一个需要注意的是:
用户名和密码需要与要备份的数据库对应。例如:在admin库中的设置的“用户”不能操作test库进行备份
PS:
如果只是输入如下指令:
C:\Users\Administrator>D:\tool\mongo\bin\mongodump
-u root -p 12345
6
则将备份mongo的全部数据库及全部数据表
mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档写入磁盘
mongodump用法:
C:\Users\Administrator>D:\tool\mongo\bin\mongodump --help Export MongoDB data to BSON files. options: --help produce help message -v [ --verbose ] be more verbose (include multiple times for more verbosity e.g. -vvvvv) --version print the program's version and exit -h [ --host ] arg mongo host to connect to ( <set name>/s1,s2 for sets) --port arg server port. Can also use --host hostname:port --ipv6 enable IPv6 support (disabled by default) -u [ --username ] arg username -p [ --password ] arg password --authenticationDatabase arg user source (defaults to dbname) --authenticationMechanism arg (=MONGODB-CR) authentication mechanism --dbpath arg directly access mongod database files in the given path, instead of connecting to a mongod server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path --directoryperdb each db is in a separate directly (relevant only if dbpath specified) --journal enable journaling (relevant only if dbpath specified) -d [ --db ] arg database to use -c [ --collection ] arg collection to use (some commands) -o [ --out ] arg (=dump) output directory or "-" for stdout -q [ --query ] arg json query --oplog Use oplog for point-in-time snapshotting --repair try to recover a crashed database --forceTableScan force a table scan (do not use $snapshot)
参数说明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-o:指明到要导出的文件名
-q:指明导出数据的过滤条件
备份的命令:
mongodump -h dbhost
-d dbname
-o dbdirectory
如果mongodb设置了登录验证,则不能备份成功,报错如下:
assertion: 18 { code: 18, ok: 0.0, errmsg: "auth fails" }
则需要登录,命令如下:
C:\Users\Administrator>D:\tool\mongo\bin\mongodump -username root -password 12345
6 -d test -o d:\tool\mongo\backup
或
C:\Users\Administrator>D:\tool\mongo\bin\mongodump -username=root -password=12345
6 -d test -o d:\tool\mongo\backup
或
C:\Users\Administrator>D:\tool\mongo\bin\mongodump
-u root -p 12345
6 -d test -o d:\tool\mongo\backup
一个初学者容易出错的地方需要注意的是:
-username 和 -password后面可以接等号,也可以不接等号。
而-u 与 -p 后面不能使用等号,只能用空格隔开。
另一个需要注意的是:
用户名和密码需要与要备份的数据库对应。例如:在admin库中的设置的“用户”不能操作test库进行备份
PS:
如果只是输入如下指令:
C:\Users\Administrator>D:\tool\mongo\bin\mongodump
-u root -p 12345
6
则将备份mongo的全部数据库及全部数据表
相关文章推荐
- MongoDB for Java
- mongoDB 介绍(特点、优点、原理)
- mongoDB 入门指南、示例
- MongoDB与MySQL的插入、查询性能测试
- MongoDB 基本操作
- MongoDB C#驱动中Query几个方法
- Mongodb 与sql 语句对照
- windows下安装MongoDB
- MongoDB 副本集的搭建、应用
- 用dex分析mongodb
- MongoDB入门简介
- mongodb,数值类型查找不到数据的问题
- 关于mongodb查询数据,数值类型查找不到数据的问题
- MongoDB在PHP中操作实例
- 把MongoDB当成纯内存数据库使用
- spring-data-mongodb 使用笔记
- MongoDB学习笔记(一)--基础
- 《MongoDB权威指南》学习整理----MongoDB文档增加、删除及更新
- Mongodb源代码阅读笔记:Journal机制
- MongoDB 副本集的原理、搭建、应用