MongoDB之整库备份还原单表collection备份还原
MongoDB之整库备份还原单表collection备份还原
cd D:\MongoDB\bin
1整库备份:
mongodump -h dbhost -d dbname -o dbdirectory
-h:MongDB所在服务器地址,例如:127.0.0.1:27017
-d:需要备份的数据库实例,例如:wlwdb
-o:备份的数据存放位置,例如:D:\MongoDB\data\dump,当然该目录需要提前建立,在备份完成后,系统自动在dump目录下建立一个wlwdb目录,这个目录里面存放该数据库实例的备份数据。
eg:
mongodump -h 127.0.0.1 -d wlwdb -o D:\MongoDB\data\dump
可以查看该备份目录:
mongodump --help
mongodump的官方说明:
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 ( /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
--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 if dbpath specified, each db is in a separate
directory
--journal enable journaling
-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)
2整库恢复:
mongorestore -h dbhost -d dbname –directoryperdb dbdirectory
-h:MongoDB所在服务器地址
-d:需要恢复的数据库实例,例如:wlwdb(可以和备份时候的不一样)
–directoryperdb:备份数据所在位置,例如:D:\MongoDB\data\dump\wlwdb
–drop:恢复的时候,先删除当前数据,然后恢复备份的数据。
eg:
mongorestore -h 127.0.0.1 -d wlwdb –directoryperdb D:\MongoDB\data\dump\wlwdb
mongorestore的官方说明(可通过mongorestore --help查看):
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 ( /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
--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 if dbpath specified, each db is in a separate
directory
--journal enable journaling
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
--objcheck validate object before inserting
--filter arg filter to apply before inserting
--drop drop each collection before import
--oplogReplay replay oplog for point-in-time restore
--oplogLimit arg exclude oplog entries newer than provided timestamp
(epoch[:ordinal])
--keepIndexVersion don't upgrade indexes to newest version
--noOptionsRestore don't restore collection options
--noIndexRestore don't restore indexes
--w arg (=1) minimum number of replicas per write
3单个collection备份:
mongoexport -h dbhost -d dbname -c collectionname -f collectionKey -o dbdirectory
-h: MongoDB所在服务器地址
-d: 需要恢复的数据库实例
-c: 需要恢复的集合
-f: 需要导出的字段(省略为所有字段)
-o: 表示导出的文件名
mongoexport的官方说明(可通过mongoexport --help查看):
--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 ( /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
--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 if dbpath specified, each db is in a separate
directory
--journal enable journaling
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-f [ --fields ] arg comma separated list of field names e.g. -f
name,age
--fieldFile arg file with fields names - 1 per line
-q [ --query ] arg query filter, as a JSON string
--csv export to csv instead of json
-o [ --out ] arg output file; if not specified, stdout is used
--jsonArray output to a json array rather than one object per
line
-k [ --slaveOk ] arg (=1) use secondaries for export if available, default
true
--forceTableScan force a table scan (do not use $snapshot)
4单个collection恢复:
mongoimport -d dbhost -c collectionname –type csv –headerline –file
-type: 指明要导入的文件格式
-headerline: 批明不导入第一行,因为第一行是列名
-file: 指明要导入的文件路径
mongoimport的官方说明(可通过mongoimport --help查看):
--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 ( /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
--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 if dbpath specified, each db is in a separate
directory
--journal enable journaling
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-f [ --fields ] arg comma separated list of field names e.g. -f name,age
--fieldFile arg file with fields names - 1 per line
--ignoreBlanks if given, empty fields in csv and tsv will be ignored
--type arg type of file to import. default: json (json,csv,tsv)
--file arg file to import from; if not specified stdin is used
--drop drop collection first
--headerline CSV,TSV only - use first line as headers
--upsert insert or update objects that already exist
--upsertFields arg comma-separated fields for the query part of the
upsert. You should make sure this is indexed
--stopOnError stop importing at first error rather than continuing
--jsonArray load a json array, not one item per line. Currently
limited to 16MB.
MongoDB之整库备份还原单表collection备份还原的更多相关文章
- MongoDB整库备份与还原以及单个collection备份、恢复方法
mongodb数据库维护离不开必要的备份.恢复操作,而且一般不会出错,所以我们在使用的时候大部分时候使用备份和恢复操作就可以了 mongodump.exe备份的原理是通过一次查询获取当前服务器快照 ...
- MongoDB整库备份+整库导入
备份前检查: [root@Load29 tmp]# mongo localhost: MongoDB shell version: connecting to: localhost:/test Ser ...
- MongoDB整库备份与还原以及单个collection备份、恢复
备份前的检查> show dbsMyDB 0.0625GBadmin (empty)bruce 0.0625GBlocal (empty)test 0.0625GB> use MyDBsw ...
- xtrabackup原理,整库,单表,部分备份恢复
物理备份xtrabackup原理 Percona XtraBackup(简称PXB)是 Percona 公司开发的一个用于 MySQL 数据库物理热备的备份工具,支持 MySQl(Oracle).Pe ...
- 从mysqldump整库备份文件中恢复单表
最近,系统更新出现了问题,比较紧急,需要对三张表进行回档.由于我们都是采用mysqldump进行每天全备整库,数据量比较大,一个备份文件大概有70G,需要从这个70G文件中恢复三张表,真是蛋疼至极啊, ...
- Oracle 整库备份还原
http://www.mamicode.com/info-detail-2481866.html sql语句 system用户登陆 查看表空间和存放位置 select t1.name,t2.name ...
- 从MySQL全库备份中恢复某个库和某张表【转】
从MySQL全库备份中恢复某个库和某张表 一.全库备份-A [root@mha2 backup]#mysqldump -uroot -p123456 --default-character-set=u ...
- mysql通过mysqldump工具,对某个库下的表进行备份
需求描述: 使用mysqldump工具对某个库下的表进行备份的方法. 操作过程: 1.通过mysqldump工具完成此目的 [mysql@redhat6 MysqlDb_Backup]$ mysqld ...
- mongodb表索引备份,索引的导出导入
背景 发现有两个mongodb环境的数据库表索引不一致,另一个数据库有索引缺失,需要将一个数据库里的所有表索引导入到另一个数据库 也可用于单独备份数据库所有表的索引 写mongo shell的js脚本 ...
随机推荐
- emysql add_poop() 超时出错
emysql add_poop() 超时出错(金庆的专栏)sample/a_hello.erl 连接本机更改为连接局域网内的MySql服务器: emysql:add_pool(hello_poo ...
- IMDG中的陷阱和问题
陷阱 使用cache API时,一个最重要的问题就是潜在的数据加载.因为IMDG提供的分布式集合也都是实现的JDK的Map.Set等接口,以JDK的Map为例,它接口规定put和remove返回被替换 ...
- 会声会影小成果分享(那段青春岁月)——校学习部宣传视频制作&生日祝福
大二的时候在校学习部当副部长,没有给干事们带去好的工作经验和管理方法,我净在折腾新媒体方面的东西,很惭愧的说,那时候申请了一个微信的公众号(HGXXB1314),我那时候以为自己很叼,最后是发现自己装 ...
- socket系列之socket服务端与客户端如何通信
上面已经分别介绍了ServerSocket跟Socket的工作步骤,并且从应用层往系统底层剖析其运作原理,我们清楚了他们各自的一块,现在我们将把他们结合起来,看看他们是如何通信的,并详细讨论一下他们之 ...
- 【安卓中的缓存策略系列】安卓缓存策略之磁盘缓存DiskLruCache
安卓中的缓存包括两种情况即内存缓存与磁盘缓存,其中内存缓存主要是使用LruCache这个类,其中内存缓存我在[安卓中的缓存策略系列]安卓缓存策略之内存缓存LruCache中已经进行过详细讲解,如看官还 ...
- 安装配置Kafka
1,下载kafka安装包,解压缩,tar -zxvf kafka_2.10-0.8.2.1.tgz 2,修改/etc/profile文件,增加KAFKA_HOME变量 3,进入KAFKA_HOME/c ...
- Dynamics crm2013 IFD部署后启用多组织
对CRM的多组织都不会陌生,在常规模式下新建组织后更改下url后面的组织名称即可访问新的组织了,而在部署IFD后就需要注意两点:1.域名的DNS解析:2.relying patry trust的更新 ...
- (NO.00002)iOS游戏精灵战争雏形(八)
子弹的初始化工作前2篇基本做好了,下面就是如何射出子弹. 通常来说,子弹射向目标对象,需要走一条直线.直线由2点定位,分别为发射点和目标点. 发射点就是开枪精灵自身的位置,目标点则为敌方精灵的位置,大 ...
- 主线程中也不绝对安全的 UI 操作
从最初开始学习 iOS 的时候,我们就被告知 UI 操作一定要放在主线程进行.这是因为 UIKit 的方法不是线程安全的,保证线程安全需要极大的开销.那么问题来了,在主线程中进行 UI 操作一定是安全 ...
- 自定义gradle的property
在android studio上运行项目,gradle的配置是必不可少的,但是随着项目的逐渐成长,迎面而来的就是.各种依赖包的添加,数不胜数的签名,渠道包等,整个gradle变得很乱,这样其实我们可以 ...