一、备份

和之前介绍的 mongoexport 的数据导出工具不同, mongodump 是将数据以二进制形式导出,而 mongoexport 导出的数据格式为 csv 或 json 格式; mongodump 可以导出一个数据库,或者整个 MongoDB 服务上的所有数据库,因此 mongodump 是更大范围的备份工具。

[root@mysql3 admin]# mongodump --help
Usage:
mongodump <options>

Export the content of a running server into .bson files.

Specify a database with -d and a collection with -c to only dump that database or collection.

See http://docs.mongodb.org/manual/reference/program/mongodump/ for more information.

general options:
--help print usage
--version print the tool version and exit

verbosity options:
-v, --verbose=<level> more detailed log output (include multiple times for more verbosity, e.g.
-vvvvv, or specify a numeric value, e.g. --verbose=N)
--quiet hide all log output

connection 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)

ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate
authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> the .pem file containing the certificate revocation list
--sslAllowInvalidCertificates bypass the validation for server certificates
--sslAllowInvalidHostnames bypass the validation for server name
--sslFIPSMode use FIPS mode of the installed openssl library

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=<mechanism> authentication mechanism to use

namespace options:
-d, --db=<database-name> database to use
-c, --collection=<collection-name> collection to use

query options:
-q, --query= query filter, as a JSON string, e.g., '{x:{$gt:1}}'
--queryFile= path to a file containing a query filter (JSON)
--readPreference=<string>|<json> specify either a preference name or a preference json object
--forceTableScan force a table scan

output options:
-o, --out=<directory-path> output directory, or '-' for stdout (defaults to 'dump')
--gzip compress archive our collection output with Gzip
--repair try to recover documents from damaged data files (not supported by all
storage engines)
--oplog use oplog for taking a point-in-time snapshot
--archive=<file-path> dump as an archive to the specified path. If flag is specified without a
value, archive is written to stdout
--dumpDbUsersAndRoles dump user and role definitions for the specified database
--excludeCollection=<collection-name> collection to exclude from the dump (may be specified multiple times to
exclude additional collections)
--excludeCollectionsWithPrefix=<collection-prefix> exclude all collections from the dump that have the given prefix (may be
specified multiple times to exclude additional prefixes)
-j, --numParallelCollections= number of collections to dump in parallel (4 by default) (default: 4)
--viewsAsCollections dump views as normal collections with their produced data, omitting
standard collections

# 备份指定数据库中的某个集合 
mongodump -d andy -h 10.100.25.42:27001 -o mongo_andy.dmp -c XX

# 备份指定数据库
mongodump -d andy -h 10.100.25.42 --port 27001 -o mongo_andy.dmp

说明:从日志看出,mongodump 的结果会生成一个目录,第一层目录为数据库名,再下一层为每个集合对应的备份文件。

# 备份实例所有数据库
mongodump -h 10.100.25.42 --port 27001 -o mongo_all.dmp

说明:mongodump 如果不指定 -d 参数,刚会备份整个 MongoDB 实例。

二、恢复

[root@mysql3 admin]# mongorestore --help
Usage:
mongorestore <options> <directory or file to restore>

Restore backups generated with mongodump to a running server.

Specify a database with -d to restore a single database from the target directory,
or use -d and -c to restore a single collection from a single .bson file.

See http://docs.mongodb.org/manual/reference/program/mongorestore/ for more information.

general options:
--help print usage
--version print the tool version and exit

verbosity options:
-v, --verbose=<level> more detailed log output (include multiple times for more verbosity, e.g.
-vvvvv, or specify a numeric value, e.g. --verbose=N)
--quiet hide all log output

connection 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)

ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate
authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> the .pem file containing the certificate revocation list
--sslAllowInvalidCertificates bypass the validation for server certificates
--sslAllowInvalidHostnames bypass the validation for server name
--sslFIPSMode use FIPS mode of the installed openssl library

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=<mechanism> authentication mechanism to use

namespace options:
-d, --db=<database-name> database to use when restoring from a BSON file
-c, --collection=<collection-name> collection to use when restoring from a BSON file
--excludeCollection=<collection-name> DEPRECATED; collection to skip over during restore (may be specified
multiple times to exclude additional collections)
--excludeCollectionsWithPrefix=<collection-prefix> DEPRECATED; collections to skip over during restore that have the given
prefix (may be specified multiple times to exclude additional prefixes)
--nsExclude=<namespace-pattern> exclude matching namespaces
--nsInclude=<namespace-pattern> include matching namespaces
--nsFrom=<namespace-pattern> rename matching namespaces, must have matching nsTo
--nsTo=<namespace-pattern> rename matched namespaces, must have matching nsFrom

input options:
--objcheck validate all objects before inserting
--oplogReplay replay oplog for point-in-time restore
--oplogLimit=<seconds>[:ordinal] only include oplog entries before the provided Timestamp
--oplogFile=<filename> oplog file to use for replay of oplog
--archive=<filename> restore dump from the specified archive file. If flag is specified
without a value, archive is read from stdin
--restoreDbUsersAndRoles restore user and role definitions for the given database
--dir=<directory-name> input directory, use '-' for stdin
--gzip decompress gzipped input

restore options:
--drop drop each collection before import
--dryRun view summary without importing anything. recommended with verbosity
--writeConcern=<write-concern> write concern options e.g. --writeConcern majority, --writeConcern '{w:
3, wtimeout: 500, fsync: true, j: true}' (defaults to 'majority')
(default: majority)
--noIndexRestore don't restore indexes
--noOptionsRestore don't restore collection options
--keepIndexVersion don't update index version
--maintainInsertionOrder preserve order of documents during restoration
-j, --numParallelCollections= number of collections to restore in parallel (4 by default) (default: 4)
--numInsertionWorkersPerCollection= number of insert operations to run concurrently per collection (1 by
default) (default: 1)
--stopOnError stop restoring if an error is encountered on insert (off by default)
--bypassDocumentValidation bypass document validation

# 追加恢复
mongorestore -h 10.100.25.42:27001 /tmp/mongo_andy.dmp

# 恢复前先删除数据库中与备份集相同对象
mongorestore -h 10.100.25.42:27001 --drop /tmp/mongo_andy.dmp

mongodb之 mongodump 与 mongorestore相关推荐

  1. MongoDB入门---备份(mongodump)恢复(mongorestore)监控

        今天工作上的事情不是太多,就索性吧后续的MongoDB的知识点整理一下,与诸君共享.废话就不多说了哈,咱们直接看一下MongoDB中的备份.在Mongodb中我们使用mongodump命令来备 ...

  2. MongoDB 备份与还原 mongodump、mongorestore

    一. MongoDB 备份 1.mongodump mongodump 是 MongoDB 官方提供的备份工具,它可以从 MongoDB 数据库读取数据,并生成 BSON 文件,mongodump 适 ...

  3. Linux系统mongdb还原数据库,linux - mongodb备份mongodump、恢复mongorestore

    前言 服务器都会涉及到服务迁移或者备份恢复的时候,今天简单总结mongodb的备份与恢复. mongodump和mongorestore --备份单个表 mongodump -u superuser ...

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

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

  5. mongodb 通过mongodump来备份Sharded Cluste分片集群

    1,mongodb所有组件 官方文档地址:https://docs.mongodb.com/manual/reference/command/,所有的基础组件都在里面,包括备份恢复的mongodump ...

  6. MongoDB 备份(mongodump)与恢复(mongorerstore)

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

  7. mongoDB4.4版本没有mongodump和mongorestore命令

    今天学习MongoDB的过程中,下载了最新4.4版本,在数据库备份和回复过程中发现没有mongodump和mongorestore命令,检查了环境变量配置和安装目录下的bin目录,发现bin目录中并没 ...

  8. linux下mongo工具,linux – 从另一台机器上使用mongodb工具(mongodump,mongorestore)

    我知道这是一个很老的问题,但谷歌搜索带我到那里.在ubuntu 14.04上,我在/etc/sources.list.d/mongo.list中有一个以下行,在那里有3.2版本: deb http:/ ...

  9. 《Linux运维实战:使用mongodump和mongorestore备份与恢复Mongodb数据》

    一.备份与恢复方案 mongodump是MongoDB官方提供的备份工具,它可以从MongoDB数据库读取数据,并生成BSON文件,mongodump适合用于备份和恢复数据量较小的MongoDB数据库 ...

最新文章

  1. android ORM框架LitePal 封装SQLite
  2. JAVA配置注解方式搭建简单的SpringMVC前后台交互系统
  3. 谈mvc开发中gzip压缩的应用
  4. 全球及中国牵引螺丝行业规模现状与“十四五”发展前景预测报告2021-2027年版
  5. 迁移学习--Xception
  6. 上传失败 已保存至草稿_学霸的草稿纸火了,卷面整洁,网友调侃:作业都比不上这草稿本...
  7. 【渝粤教育】21秋期末考试建设工程法规10221k1
  8. Mask R-CNN
  9. 第一届LCI workshop @ ICCV 2019, 欢迎投稿
  10. C#中各种数组的性能比较
  11. Hexo + github 打造个人博客
  12. vue-13-swiper组件的使用
  13. Python基础知识笔记(二)
  14. unix文件中i节点
  15. 第七章·【第一次上岗:核桃编程】
  16. Qt之Windows下禁用中文输入法
  17. Dubious Document
  18. win10修改hosts,总是提示另存为
  19. 机器学习平台系列——XGB feature_names mismatch 问题解决方案
  20. 应急照明和疏散指示系统在化工厂房中的设计与产品选型

热门文章

  1. Excel导入文本文件
  2. iPhone开发入门(10)— 设备上运行程序
  3. 小程序wxParse的使用
  4. 【MindStudio训练营第一期】大作业:cartoonGAN_picture卡通生成案例
  5. 07.linux上课复习
  6. 什么是mock数据、mock数据使用步骤
  7. 域控服务器无法降级,Windows Server 2016 辅助域控制器降级
  8. 智安网络丨云安全:浅谈态势感知
  9. java 字符串 转 文件路径_连接用户输入字符串转换为完整的文件路径(Java)
  10. 将中国经验带到菲律宾 金融壹账通科技赋能出海再下一城