mongodb 备份和恢复
2.mongorestore 恢复用法:bin/mongorestore
举例:将数据库test删除,然后从备份目录恢复
> show dbs
admin(empty)
local4.201171875GB
test0.203125GB
> use test
switched to db test
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> show dbs
admin(empty)
local4.201171875GB
使用mongorestore恢复
bin/mongorestore -host 127.0.0.1:6666 --directoryperdb/data/6666/
connected to: 127.0.0.1:6666
Wed Jul6 16:37:33 /data/6666/test/ints.bson
Wed Jul6 16:37:33going into namespace
Wed Jul6 16:37:334 objects found
Wed Jul6 16:37:33 /data/6666/test/system.indexes.bson
Wed Jul6 16:37:33going into namespace
Wed Jul6 16:37:33 { name: "_id_", ns: "test.ints", key: { _id: 1 }, v: 0 }
Wed Jul6 16:37:331 objects found
查看数据库是否恢复
> show dbs
admin(empty)
local4.201171875GB
test0.203125GB
mongorestore有个参数--drop,使用此参数,会先将集合里的数据都删除了再恢复
就是说,如果你备份完数据后有新增数据,那么使用--drop,新增的数据会不见
不使用此参数,恢复备份的时候新增的数据依然存在
页:
[1]