mongodb 备份和恢复
2012-03-08 21:08
387 查看
mongodb提供了两个命令用来备份(mongodump)和恢复(mongorestore)数据,数据dump出来的格式是BSON的
1.mongodump 备份
用法:bin/mongodump [options]
举例:将本机6666端口的数据库备份到本机的/data/6666目录下
bin/mongodump --port 6666 --directoryperdb -o /data/6666
connected to: 127.0.0.1:6666
all dbs
DATABASE: test to /data/6666/test
test.system.indexes to /data/6666/test/system.indexes.bson
1 objects
test.ints to /data/6666/test/ints.bson
4 objects
DATABASE: admin to /data/6666/admin
2.mongorestore 恢复
用法:bin/mongorestore [options] [directory or filename to restore from]
举例:将数据库test删除,然后从备份目录恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
> use test
switched to db test
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> show dbs
admin (empty)
local 4.201171875GB
使用mongorestore恢复
bin/mongorestore -host 127.0.0.1:6666 --directoryperdb /data/6666/
connected to: 127.0.0.1:6666
Wed Jul 6 16:37:33 /data/6666/test/ints.bson
Wed Jul 6 16:37:33 going into namespace [test.ints]
Wed Jul 6 16:37:33 4 objects found
Wed Jul 6 16:37:33 /data/6666/test/system.indexes.bson
Wed Jul 6 16:37:33 going into namespace [test.system.indexes]
Wed Jul 6 16:37:33 { name: "_id_", ns: "test.ints", key: { _id: 1 }, v: 0 }
Wed Jul 6 16:37:33 1 objects found
查看数据库是否恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
mongorestore有个参数--drop,使用此参数,会先将集合里的数据都删除了再恢复
就是说,如果你备份完数据后有新增数据,那么使用--drop,新增的数据会不见
不使用此参数,恢复备份的时候新增的数据依然存在本文出自 “lynnteng0” 博客,请务必保留此出处http://lynnteng0.blog.51cto.com/2145094/800729
1.mongodump 备份
用法:bin/mongodump [options]
举例:将本机6666端口的数据库备份到本机的/data/6666目录下
bin/mongodump --port 6666 --directoryperdb -o /data/6666
connected to: 127.0.0.1:6666
all dbs
DATABASE: test to /data/6666/test
test.system.indexes to /data/6666/test/system.indexes.bson
1 objects
test.ints to /data/6666/test/ints.bson
4 objects
DATABASE: admin to /data/6666/admin
2.mongorestore 恢复
用法:bin/mongorestore [options] [directory or filename to restore from]
举例:将数据库test删除,然后从备份目录恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
> use test
switched to db test
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> show dbs
admin (empty)
local 4.201171875GB
使用mongorestore恢复
bin/mongorestore -host 127.0.0.1:6666 --directoryperdb /data/6666/
connected to: 127.0.0.1:6666
Wed Jul 6 16:37:33 /data/6666/test/ints.bson
Wed Jul 6 16:37:33 going into namespace [test.ints]
Wed Jul 6 16:37:33 4 objects found
Wed Jul 6 16:37:33 /data/6666/test/system.indexes.bson
Wed Jul 6 16:37:33 going into namespace [test.system.indexes]
Wed Jul 6 16:37:33 { name: "_id_", ns: "test.ints", key: { _id: 1 }, v: 0 }
Wed Jul 6 16:37:33 1 objects found
查看数据库是否恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
mongorestore有个参数--drop,使用此参数,会先将集合里的数据都删除了再恢复
就是说,如果你备份完数据后有新增数据,那么使用--drop,新增的数据会不见
不使用此参数,恢复备份的时候新增的数据依然存在本文出自 “lynnteng0” 博客,请务必保留此出处http://lynnteng0.blog.51cto.com/2145094/800729
相关文章推荐
- 通过mongodump和mongorestore实现Mongodb备份和恢复
- mongodb 的数据备份与恢复
- mongodb备份与恢复
- mongodb 学习笔记 07 -- 数据备份、恢复
- MongoDB的备份(mongodump)与恢复(mongorestore)
- MongoDB的备份(mongodump)与恢复(mongorestore)
- MongoDB数据库的文件备份恢复以及文件导入导出
- mongodb备份与恢复
- MongoDB-备份和恢复
- MongoDB 备份(mongodump)与恢复(mongorestore)
- MongoDB的备份和恢复
- Windows 下 MongoDB的备份(mongodump)与恢复(mongorestore)
- mongodb的备份与恢复
- linux 下mongoDB备份与恢复
- MongoDB初试备份及恢复
- Windows或Linux系统中备份和恢复MongoDB数据的教程
- mongodb的备份与恢复
- mongoDB中备份和恢复数据库的命令
- 使用mongoDB必须要知道的备份和恢复数据库的命令
- mongodb备份恢复学习1