MongoDB 备份和还原数据库
首页 专栏 mongodb 文章详情
0

MongoDB 备份和还原数据库

小伍 发布于 5 月 12 日

备份

mongodump --host=mongodb.example.net --port=27017 --username=user --password="pass" --authenticationDatabase=test --db=test --collection=myCollection --oplog --out=/opt/backup/test-2013-10-24 --host:默认 localhost:27017 ,指定连接主机 --port:默认 27017 ,指定连接端口 --username:指定进行身份验证的用户名 --password:指定进行身份验证的密码 --authenticationDatabase:指定进行身份验证的数据库,如果未指定,则假设为导出的数据库 --db:指定要备份的数据库,默认为所有数据库 --collection:指定要备份的集合,默认为所有集合 --oplog:创建一个 oplog.bson 文件作为备份的内容,包含 mongodump 备份操作期间发生的操作日志。--oplog 不能与 --db 和 --collection 一起使用,必须创建完整的转储才可以使用。 --out:默认当前目录下的 dump 目录,指定备份保存的目录。使用" -"代替路径可以发送到标准输出。--out 不能与 --archive 一起使用。

还原

mongorestore --host=mongodb1.example.net --port=3017 --username=user --password="pass" --authenticationDatabase=test_bak --oplogReplay --drop /opt/backup/test-2013-10-24/ --host:默认 localhost:27017 ,指定连接主机 --port:默认 27017 ,指定连接端口 --username:指定进行身份验证的用户名 --password:指定进行身份验证的密码 --authenticationDatabase:指定进行身份验证的数据库 --oplogReplay:恢复数据库转储后,从bson文件重新执行oplog内容。--oplogReplay 不能与 --db --collection --nsInclude --nsExclude 一起使用,必须还原完整的转储才可以使用。 --drop:还原集合之前,从目标数据库中删除集合。
mongodb
阅读 45 发布于 5 月 12 日
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
avatar
小伍
34 声望
1 粉丝
关注作者
0 条评论
得票数 最新
提交评论
你知道吗?

注册登录
avatar
小伍
34 声望
1 粉丝
关注作者
宣传栏
目录

备份

mongodump --host=mongodb.example.net --port=27017 --username=user --password="pass" --authenticationDatabase=test --db=test --collection=myCollection --oplog --out=/opt/backup/test-2013-10-24 --host:默认 localhost:27017 ,指定连接主机 --port:默认 27017 ,指定连接端口 --username:指定进行身份验证的用户名 --password:指定进行身份验证的密码 --authenticationDatabase:指定进行身份验证的数据库,如果未指定,则假设为导出的数据库 --db:指定要备份的数据库,默认为所有数据库 --collection:指定要备份的集合,默认为所有集合 --oplog:创建一个 oplog.bson 文件作为备份的内容,包含 mongodump 备份操作期间发生的操作日志。--oplog 不能与 --db 和 --collection 一起使用,必须创建完整的转储才可以使用。 --out:默认当前目录下的 dump 目录,指定备份保存的目录。使用" -"代替路径可以发送到标准输出。--out 不能与 --archive 一起使用。

还原

mongorestore --host=mongodb1.example.net --port=3017 --username=user --password="pass" --authenticationDatabase=test_bak --oplogReplay --drop /opt/backup/test-2013-10-24/ --host:默认 localhost:27017 ,指定连接主机 --port:默认 27017 ,指定连接端口 --username:指定进行身份验证的用户名 --password:指定进行身份验证的密码 --authenticationDatabase:指定进行身份验证的数据库 --oplogReplay:恢复数据库转储后,从bson文件重新执行oplog内容。--oplogReplay 不能与 --db --collection --nsInclude --nsExclude 一起使用,必须还原完整的转储才可以使用。 --drop:还原集合之前,从目标数据库中删除集合。