centos下mongodb3.2数据库的备份与恢复初步

数据库的备份

mongodump -h dbhost -d dbname -o dbdirectory

  • -h MongDB所在服务器地址,在本地操作时服务器默认地址是127.0.0.1。
    这里写图片描述

  • -d 需要备份的数据库实例。

  • -o 备份的数据存放位置,在该位置下会成与你实例为名的文件夹,在文件夹下有collection 的bson和json文件。
    这里写图片描述

完成后可以输入mongodump查看
这里写图片描述

数据库的恢复

mongorestore -h dbhost -d dbname –dir dbdirectory

  • -h mongodb所在服务器

  • -d 所需要备份的数据库实例

  • -dir 数据库备份的位置

  • – drop 先删除当前数据库的数据,然后恢复备份的数据

完成后输入mongorestore查看恢复信息
这里写图片描述

恢复的几点注意

  • mongorestore can create a new database or add data to an existing database. However, mongorestore performs inserts only and does not perform updates. That is, if restoring documents to an existing database and collection and existing documents have the same value _id field as the to-be-restored documents, mongorestore will not overwrite those documents.(mongorestore可以创建一个新的数据库或数据添加到现有的数据库。然而,mongorestore只执行插入和不执行更新。也就是说,如果恢复文件到现有的数据库,并收集和现有的文件具有相同的值_id字段作为要被恢复的文件,mongorestore不会覆盖那些文件。)

  • mongorestore recreates indexes recorded by mongodump.(mongorestore会创建mongodump录索引。)

  • The data format used by mongodump from version 2.2 or later is incompatible with earlier versions of mongod. Do not use recent versions of mongodump to back up older data stores.(从2.2版本使用mongodump或更高版本的数据格式是与早期版本的mongod不兼容。不要使用mongodump的最新版本的备份旧的数据存储。)

  • mongorestore does not restore the system.profile collection data; however, if the backup data includes system.profile collection data and the collection does not exist in the target database, mongorestore creates the collection but does not insert any data into the collection.(mongorestore不会恢复system.profile收集数据;然而,如果备份数据包括system.profile集合数据和集合未在目标数据库中存在,mongorestore创建集合,但不将任何数据插入到集合中。)
    -

参考:
MongoDB 备份(mongodump)与恢复(mongorerstore)
mongorestore

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值