mongodb 的备份和还原

 

1.使用

导出:mongodump -h 10.0.0.12:10006 -d test
导入:mongorestore -h 10.0.0.11:10006 -d test  dump/test/

2.命令的手册

NAME
       mongodump - the Mongo dump tool
                            mongo转存工具
SYNOPSIS
       mongodump [OPTIONS]
DESCRIPTION
       mongodump is a tool to output a binary representation of a database.  It is mostly used for doing hot backups of a database.
       mongodump是一个把数据库以二进制形式导出的工具。它主要用来热备数据库。
OPTIONS
       --help show usage information
              使用帮助
       -h, --host HOST
              server to connect to (default HOST=localhost)
              连接的服务器
       -d, --db DATABASE
              database to use
              使用的数据库
       -c, --c COLLECTION
              collection to use
              使用的表
       -o, --out FILE
              output file, if not specified, stdout is used
              输出文件,如果不指定,就使用标准输出
       --dbpath PATH
              directly access mongod data files in this path, instead of connecting to a mongod instance
              取代连接mongo的实现,直接访问数据库文件。
COPYRIGHT
       Copyright 2007-2009 10gen
SEE ALSO
       For more information, please refer to the MongoDB wiki, available at http://www.mongodb.org.
       更多信息看mongodb的wiki,http://www.mongodb.org.
AUTHOR
       Kristina Chodorow
NAME
       mongorestore - the Mongo restoration tool
                               Mongo恢复工具
DESCRIPTION
       mongorestore is a tool to use the output from mongodump to restore a database.
       mongorestore 是使用mongodump导出的内容来恢复一个数据库
OPTIONS
       --help show usage information
              展示使用的帮助信息
       --version
              show version information
              展示版本信息,(-v不能用)
       -h, --host HOST
              server to connect to (default HOST=localhost)
              要连接的服务器(默认 HOST=localhost),
       -port arg
              server port. Can also use --host hostname:port
              服务器端口,也能使用 --host hostname:port(也能是 -h)
       --ipv6 enable IPv6 support (disabled by default)
              支持IPv6功能(默认不开启)
       -u|--username USERNAME
              specify user to log in as
              登录用户名
       -p|--password PASSWORD
              specify password of user (notice there is no space)
              登录密码(没有空格)
       -d, --db DATABASE
              database to use
              要使用的数据库
       -c, --c COLLECTION
              collection to use
              使用的表
       --dbpath PATH
              directly access mongod data files in this path, instead of connecting to a mongod instance
              访问mongod数据文件的目录,取代连接mongod的方式
       --directoryperdb
              if dbpath specified, each db is in a separate directory
              如果dbpath设置了,每个数据库都在一个独立的目录
       --objcheck
              validate object before inserting
              插入数据之前先验证对象
       --filter arg
              filter to apply before inserting
              插入数据之前先过滤
       --drop drop each collection before import
              引入之前先删除每个表。
       --oplogReplay
              Replays the oplog after restoring the dump to ensure that the current state of the database reflects the point-in-time backup captured with the “mongodump --oplog” command.
              恢复导出日志的录制操作日志,确保当前的数据库的状态,还原从某个点使用“mongodump --oplog”命令抓获的数据。
COPYRIGHT
       Copyright 2007-2011 10gen
SEE ALSO
       For more information, please refer to the MongoDB wiki, available at http://www.mongodb.org
AUTHOR
       Kristina Chodorow

3.命令的介绍

mongodump is a utility for creating a binary export of the contents of a database. Consider using this utility as part an effective backup strategy. Use in conjunction with mongorestore to provide restore functionality.
mongodump是将数据库内容导出二进制的输出,是一个有效的备份策略。结合 mongostore得到一个功能。

If you use the mongodump tool from the 2.2 distribution to create a dump of a database, you can restore that dump only to a 2.2 database.
如果使用mongodump工具的操作的数据库是2.2,那么只能导入2.2的数据库。

To connect to a replica set, use the --host argument with a setname, followed by a slash and a comma separated list of host names and port numbers.
如果连接到一个复制集,使用 --host 参数+主机集合,使用斜杠和一个逗号分隔主机。举例:
mongodump --host repl0/mongo0.example.net,mongo0.example.net:27018,mongo1.example.net,mongo2.example.net       


posted on 2012-11-13 13:09  DON'T PANIC  阅读(587)  评论(0编辑  收藏  举报

导航