设为首页 加入收藏

TOP

MongoDB的日常维护管理(三)
2015-07-24 10:51:55 来源: 作者: 【 】 浏览:5
Tags:MongoDB 日常 维护 管理
是JSON方式,也可导出csv格式;

导出为CSV格式代码文件如下:

./mongoexport -d test -c t1 -csv -f num -o t1.dat
-csv:指明了要导出的是CSV格式
-f: 指明需要导出的是哪些例子

数据导入 mongoimport

现将ti删除:

> db.t1.drop()
true
> show collections
system.indexes
system.users
>

再导入数据,这里导入的是csv数据:

./mongoimport -d test -c t1 --type csv --headerline -file /home/t1.dat
connected to: 127.0.0.1

看看导入的数据是不是一样:

> db.t1.find()
{ "_id" : ObjectId("4f8ac746b2764d3c3e2cafbb"), "num" : 1 }
{ "_id" : ObjectId("4f8ac74cb2764d3c3e2cafbc"), "num" : 2 }
{ "_id" : ObjectId("4f8ac74eb2764d3c3e2cafbd"), "num" : 3 }
{ "_id" : ObjectId("4f8ac751b2764d3c3e2cafbe"), "num" : 4 }
{ "_id" : ObjectId("4f8ac755b2764d3c3e2cafbf"), "num" : 5 }
>
--type csv 导入的数据格式为CSV,为什么导入CSV格式:CSV对各大主流的数据库支持更良好,而JSON作为轻量级的数据格式,还有些弊端。
--file 指明导入的文件路径

数据备份和恢复

使用 数据备份 mongodump
./mongodump -d test -o /home/dump
-o:表示输出的备份路径,如果没有使用这个选项的话,MongoDB会自动创建dump文件夹并将备份文件放于其内。
使用数据恢复 mongorestore

mongorestore获取mongodump的输出结果,并将备份的数据插入到运行的MongoDB中。

./mongorestore -d test dump/*
connected to: 127.0.0.1
Thu Apr 19 18:16:12 dump/test/system.users.bson
Thu Apr 19 18:16:12      going into namespace [test.system.users]
2 objects found
Thu Apr 19 18:16:12 dump/test/t1.bson
Thu Apr 19 18:16:12      going into namespace [test.t1]
5 objects found
Thu Apr 19 18:16:12 dump/test/system.indexes.bson
Thu Apr 19 18:16:12      going into namespace [test.system.indexes]
Thu Apr 19 18:16:12 { key: { _id: 1 }, ns: "test.system.users", name: "_id_" }
Thu Apr 19 18:16:13 { key: { _id: 1 }, ns: "test.t1", name: "_id_" }
2 objects found
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇【翻译自mos文章】v$undostat视图.. 下一篇数据库编程--translate的使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Libevent C++ 高并发 (2025-12-26 00:49:30)
·C++ dll 设计接口时 (2025-12-26 00:49:28)
·透彻理解 C 语言指针 (2025-12-26 00:22:52)
·C语言指针详解 (经典 (2025-12-26 00:22:49)
·C 指针 | 菜鸟教程 (2025-12-26 00:22:46)