MongoDB 数据库操作(八)-数据备份和恢复
2013-04-09 15:34
513 查看
1. 备份
可以用mongodump 来做MongoDB 的库或表级别的备份。
备份数据库:
还可以加入-o参数来指定备份位置:
2.数据恢复
先将数据库删掉:
进行恢复:
查看结果:
可以用mongodump 来做MongoDB 的库或表级别的备份。
备份数据库:
./mongodump -d my_mongodb这个操作默认将会保持数据到当前目录下的dump文件夹内。使用这个命令会有相应的提示信息:
./mongodump -d test connected to: 127.0.0.1 Tue Apr 2 09:11:45 DATABASE: test to dump/test Tue Apr 2 09:11:45 test.system.js to dump/test/system.js.bson Tue Apr 2 09:11:45 3 objects Tue Apr 2 09:11:45 Metadata for test.system.js to dump/test/system.js.metadata.json Tue Apr 2 09:11:45 test.fs.files to dump/test/fs.files.bson Tue Apr 2 09:11:45 1 objects Tue Apr 2 09:11:45 Metadata for test.fs.files to dump/test/fs.files.metadata.json Tue Apr 2 09:11:45 test.fs.chunks to dump/test/fs.chunks.bson Tue Apr 2 09:11:45 1 objects Tue Apr 2 09:11:45 Metadata for test.fs.chunks to dump/test/fs.chunks.metadata.json Tue Apr 2 09:11:45 test.result to dump/test/result.bson Tue Apr 2 09:11:45 4 objects Tue Apr 2 09:11:45 Metadata for test.result to dump/test/result.metadata.json Tue Apr 2 09:11:45 test.things to dump/test/things.bson Tue Apr 2 09:11:45 14 objects Tue Apr 2 09:11:45 Metadata for test.things to dump/test/things.metadata.json Tue Apr 2 09:11:45 test.things2 to dump/test/things2.bson Tue Apr 2 09:11:45 14 objects Tue Apr 2 09:11:45 Metadata for test.things2 to dump/test/things2.metadata.json一般备份会产生两个文件:一个是元数据的json文件,存储格式信息,另一个事Bson文件,存储数据内容。
还可以加入-o参数来指定备份位置:
./mongodump -d my_mongodb -o my_mongodb_dump
2.数据恢复
先将数据库删掉:
> db.getName(); test > db.dropDatabase(); { "dropped" : "test", "ok" : 1 }
进行恢复:
./mongorestore -d t est dump/* connected to: 127.0.0.1 Tue Apr 2 09:20:12 dump/test/system.js.bson Tue Apr 2 09:20:12 going into namespace [test.system.js] 3 objects found Tue Apr 2 09:20:12 Creating index: { key: { _id: 1 }, ns: "test.system.js", name: "_id_" } Tue Apr 2 09:20:12 dump/test/things2.bson Tue Apr 2 09:20:12 going into namespace [test.things2] 14 objects found Tue Apr 2 09:20:12 Creating index: { key: { _id: 1 }, ns: "test.things2", n ame: "_id_" } Tue Apr 2 09:20:12 dump/test/fs.files.bson Tue Apr 2 09:20:12 going into namespace [test.fs.files] 1 objects found Tue Apr 2 09:20:12 Creating index: { key: { _id: 1 }, ns: "test.fs.files", name: "_id_" } Tue Apr 2 09:20:12 Creating index: { key: { filename: 1 }, ns: "test.fs.fil es", name: "filename_1" } Tue Apr 2 09:20:12 dump/test/result.bson Tue Apr 2 09:20:12 going into namespace [test.result] 4 objects found Tue Apr 2 09:20:12 Creating index: { key: { _id: 1 }, ns: "test.result", na me: "_id_" } Tue Apr 2 09:20:12 dump/test/things.bson Tue Apr 2 09:20:12 going into namespace [test.things] 14 objects found Tue Apr 2 09:20:12 Creating index: { key: { _id: 1 }, ns: "test.things", na me: "_id_" } Tue Apr 2 09:20:12 dump/test/fs.chunks.bson Tue Apr 2 09:20:12 going into namespace [test.fs.chunks] 1 objects found Tue Apr 2 09:20:12 Creating index: { key: { _id: 1 }, ns: "test.fs.chunks", name: "_id_" } Tue Apr 2 09:20:12 Creating index: { key: { files_id: 1, n: 1 }, ns: "test. fs.chunks", name: "files_id_1_n_1" }
查看结果:
> show dbs Cache 6.0126953125GB admin (empty) local (empty) test 0.203125GB > db.getName(); test > show collections; fs.chunks fs.files result system.indexes system.js things things2
相关文章推荐
- MongoDB数据库管理数据备份恢复
- 5.非关系数据库(Nosql)它mongodb:创建一个集合,导出和导入备份, 数据恢复,进出口
- mongoDB的基本操作以及数据的导入导出,备份和恢复
- mongoDB的基本操作以及数据的导入导出,备份和恢复
- MySQL(用户管理,常用sql语句,数据库备份恢复,MySQL调优,恢复误操作数据)
- Mysql命令行下备份恢复数据库数据操作
- mongoDB的基本操作以及数据的导入导出,备份和恢复
- SQLServer 2008以上误操作数据库恢复方法——日志尾部备份
- 数据库出现问号,界面能正常显示,如果数据的数据需要备份或者导出的操作
- MYSQL常用操作(二),MYSQL用户管理,数据备份恢复
- mongodb 学习笔记 07 -- 数据备份、恢复
- 5.非关系型数据库(Nosql)之mongodb:创建集合,备份与导入导出, 数据还原,导入导出
- 一个通过数据库镜像实现SPS 2003门户快速备份与恢复的操作手册
- 数据库的自我修炼——阿里云MongoDB备份恢复功能说明和原理介绍
- MongoDB数据库的文件备份恢复以及文件导入导出
- MongoDB数据库的文件备份恢复以及文件导入导出
- Oracle-->数据库备份与恢复-->数据库库归档模式
- MySQL数据库的数据备份和恢复(导入和导出)命令操作语法【转】
- Oracle如何实现创建数据库、备份数据库及数据导出导入的一条龙操作
- 数据库数据文件没有备份的恢复 ORA-01157 【续+2】