文章借鉴(稍有修改):http://www.jb51.net/article/40285.htm
mongodump.exe备份的原理是通过一次查询获取当前服务器快照,并将快照写入磁盘中,因此这种方式保存的也不是实时的,因为在获取快照后,服务器还会有数据写入,为了保证备份的安全,同样我们还是可以利用fsync锁使服务器数据暂时写入缓存中。
高效开源数据库(mongodb)下载地址请见我的另一篇文章:http://ysj5125094.iteye.com/blog/2118168
整库备份:
经过测试的方法(导出15服务器上的dbtest库):D:\yusj\mongodb\bin>mongodump -h 192.168.1.15 -d dbtest -o D:/yusj/dump20150213
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目录,这个目录里面存放该数据库实例的备份数据。
mongodump的官方说明(可通过mongodump --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) -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)
整库恢复:
经过测试的方法(将导出的dbtest库,整库导出到139服务器上并修改库名为dbtest2015):D:\mongodb\bin>mongorestore -h 192.168.1.139 -d dbtest2015 C:/dump20150213/dbtest
mongorestore -h dbhost -d dbname –directoryperdb dbdirectory
-h:MongoDB所在服务器地址
-d:需要恢复的数据库实例,例如:test,当然这个名称也可以和备份时候的不一样,比如test2
–directoryperdb:备份数据所在位置,例如:c:\data\dump\test,这里为什么要多加一个test,而不是备份时候的dump,读者自己查看提示吧!
–drop:恢复的时候,先删除当前数据,然后恢复备份的数据。就是说,恢复后,备份后添加修改的数据都会被删除,慎用哦!
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
单个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)
单个collection恢复:
mongoimport -h dbhost -d dbname -c collectionname –type csv –headerline –file
-h: MongoDB所在服务器地址
-d: 需要恢复的数据库实例
-c: 需要恢复的集合
-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.
其他导入与导出操作:
1. mongoimport -d my_mongodb -c user user.dat
参数说明:
-d 指明使用的库, 本例中为” my_mongodb”
-c 指明要导出的表, 本例中为”user”
可以看到导入数据的时候会隐式创建表结构
2. mongoexport -d my_mongodb -c user -o user.dat
参数说明:
-d 指明使用的库, 本例中为” my_mongodb”
-c 指明要导出的表, 本例中为”user”
-o 指明要导出的文件名, 本例中为”user.dat”
从上面可以看到导出的方式使用的是JSON 的样式.
相关推荐
技术关键词: SQL、关系数据库、NoSQL 内容关键词: 数据建模、查询优化、事务处理 用途: 理解数据存储和管理的基本原理,确保数据的有效性和安全性 资源描述: "MySQL官方文档"提供了MySQL数据库的详尽文档和教程,...
深入NoSQL 原作名: Professional NoSQL 作者: Shashank Tiwari 译者: 巨成 出版社: 人民邮电出版社 出版年: 2012 11 页数: 294 定价: 69 00元 装帧: 平装 ISBN: 9787115296382《深入NoSQL》是一本全面的NoSQL实践...
nosql实验五-HBase数据迁移与数据备份&恢复
CHAPTER 1: NOSQL: WHAT IT IS AND WHY YOU NEED IT 3 CHAPTER 2: HELLO NOSQL: GETTING INITIAL HANDS-ON EXPERIENCE 21 CHAPTER 3: INTERFACING AND INTERACTING WITH NOSQL 43 PART II: LEARNING THE NOSQL ...
本书在紧贴实用的示例的引导下,介绍Oracle NoSQL数据库的安装、配置、应用程序开发、容量规划、容量调节以及与其他企业级数据中心产品的集成等主题。 本书主要内容 ● 了解Oracle NoSQL数据库架构及其底层数据...
我创建此对象是为了减少重新创建与NoSQL数据库的连接实例的需要。 基本上,每个NoSQL的所有python依赖关系都将由该库处理。 版: Python 3 资料库 支持的: MongoDB 去做: 卡桑德拉 雷迪斯 里亚克 DynamoDB...
TJ会通过若干互动的演示,而不是干巴巴的宣讲的方式来为大家介绍MongoDB风靡全球,成为NoSQL王者的关键原因。如果您已经是Mongo老司机,不用担心,你也可以从TJ的文档模式设计精粹及一分钟关系型到MongoDB的迁移演示...
3. 备份与恢复:包括数据备份和恢复的方法、备份数据的类型、备份与恢复的策略、日志文件管理等。 4. 数据库设计:包括数据库设计范式、数据库结构设计、关系模型等。 5. 数据库管理:包括用户管理、权限管理、事务...
NoSQL 关系数据库 NoSQL CAP定理,AXP 2015,JWN 2016 C CAP中的一致性实际上意味着线性化,这是一个非常具体(非常强烈)的一致性概念。 特别地,即使C也代表“一致性”,它与ACID中的C无关。 线性化的含义如下...
##README 这是我们 DBMS 课程项目的存储库,我们在其中构建了一个名为 noPandaDB 的 NoSQL 数据库。 我们将构建查询语言以及数据库结构。 我们将主要使用Python进行编码。 ###Description ####查询语言查询语言称为...
FISE3-NoSQL-Project:建立定制的No-SQL数据库
nosql 基准测试符合 ACID 的 NoSQL 数据库的基准进度:阿尔法
oSQL Data Models: Trends and Challenges ISBN 10: 1786303647 ISBN 13: 9781786303646 Edition: 1 Released: 2018-08-14 pages: 278 List Price: $145
这个库是一个小巧而简单的 ODM,它将帮助您轻松构建业务模型层,而无需处理任何 NoSQL 引擎(支持 Couchbase、Redis 和 Sphinx)的技术方面。 CRUD 操作 记录属性上的 Getter 和 Setter 保存前验证数据 过滤和...
awesome-nosql-guides:精选资源和有关使用NoSQL数据库的链接的精选列表
视觉中国的NoSQL之路:从MySQL到MongoDB
用于IntelliJ IDEA版本0.1.0-SNAPSHOT的NoSql插件 描述 这个插件是一个分支,旨在集成Redis和Couchbase数据库。 请注意,Couchbase集成是实验性的,因为我不是该数据库的坚决用户。 当前状态:EAP 插件兼容性 该插件...
NOSQL工具 一组用于管理NOSQL数据库的工具。 可用工具 java org.dew.dbsql.CommandNoSQL 数据源配置(CLASSPATH中的nosql.cfg) nosqldb.uri = mongodb://user:password@localhost:27017/database 建立 git clone ...
Sql-NoSql-比较 该存储库托管事件项目。 在本次演讲中,我将介绍NoSQL后端的一些特性,并将其与传统的RDBMS进行比较。 在此资源库中,有以下项目: Benckmark:该项目执行一些基准测试,以测试通用操作(插入,批量...
NoSql基础 创建项目以了解有关NoSQL的更多信息