资讯专栏INFORMATION COLUMN

MongoDB备份和恢复命令

PingCAP / 1760人阅读

摘要:备份备份到文件名为的文件尝试重复执行备份会覆盖第一次的备份文件立即恢复中删除了一条记录后执行,删除的行又出来了,已经存在的行报错删除后恢复没有任何异常恢复成功

备份
mongodump --archive=gt_ut.archive --db gt_ut
2018-03-22T18:11:33.555+0800    writing gt_ut.gt_counting_data to archive "gt_ut.archive"
2018-03-22T18:11:33.558+0800    done dumping gt_ut.gt_counting_data (2 documents)

备份到文件名为gt_ut.archive的文件

尝试重复执行备份

会覆盖第一次的备份文件

mongodump --archive=gt_ut.archive --db gt_ut
2018-03-22T18:11:59.565+0800    writing gt_ut.gt_counting_data to archive "gt_ut.archive"
2018-03-22T18:11:59.567+0800    done dumping gt_ut.gt_counting_data (2 documents)
立即恢复

collection中删除了一条记录后执行mongorestore,删除的行又出来了,已经存在的行报错E11000 duplicate key error

mongorestore --archive=gt_ut.archive
2018-03-22T18:13:28.986+0800    preparing collections to restore from
2018-03-22T18:13:29.019+0800    reading metadata for gt_ut.gt_counting_data from archive "gt_ut.archive"
2018-03-22T18:13:29.019+0800    restoring gt_ut.gt_counting_data from archive "gt_ut.archive"
2018-03-22T18:13:29.035+0800    error: E11000 duplicate key error collection: gt_ut.gt_counting_data index: _id_ dup key: { : "concurrent_test" }
2018-03-22T18:13:29.035+0800    no indexes to restore
2018-03-22T18:13:29.035+0800    finished restoring gt_ut.gt_counting_data (2 documents)
2018-03-22T18:13:29.035+0800    done
删除DB后恢复

没有任何异常恢复成功

mongorestore --archive=gt_ut.archive
2018-03-22T18:15:19.419+0800    preparing collections to restore from
2018-03-22T18:15:19.439+0800    reading metadata for gt_ut.gt_counting_data from archive "gt_ut.archive"
2018-03-22T18:15:19.504+0800    restoring gt_ut.gt_counting_data from archive "gt_ut.archive"
2018-03-22T18:15:19.517+0800    no indexes to restore
2018-03-22T18:15:19.517+0800    finished restoring gt_ut.gt_counting_data (2 documents)
2018-03-22T18:15:19.517+0800    done

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/19224.html

相关文章

  • Mongodb 定时备份恢复

    摘要:就是说,恢复后,备份后添加修改的数据都会被删除,慎用哦最后的一个参数,设置备份数据所在位置,例如。指定备份的目录你不能同时指定和选项。 定时对数据库进行备份可以有效地保护数据 MongoDB 数据备份 在 MongoDB 中我们使用 mongodump 命令来备份 MongoDB 数据 语法如下: > mongodump -h dbhost -d dbname -o dbdirect...

    高璐 评论0 收藏0
  • MongoDB备份恢复

    摘要:不填写该参数会默认备份所有实例。指定备份的数据库的集合可以和配合使用。数据恢复命令参数所在服务器地址,默认为需要恢复的数据库实例,例如,当然这个名称也可以和备份时候的不一样,比如恢复的时候,先删除当前数据,然后恢复备份的数据。 更多内容欢迎来到博客 :https://imjianjian.github.io MongoDB数据备份 命令:mongodump 参数: -h: 服务器地址...

    keithxiaoy 评论0 收藏0
  • 为你的mongodb砌堵墙吧,防止被攻击勒索

    摘要:起因年月,当大家都在为的逝去写总结,并为年的到来做计划的时候,一波黑客发动了一轮攻击,攻击的对象瞄准了数据库。他们删除了所有数据库数据,并留下一个勒索数据库。不幸的是,我也成为这幸运的一员。谨记,安全,安全,安全。 起因 2017年1月,当大家都在为16的逝去写总结,并为17年的到来做计划的时候,一波黑客发动了一轮攻击,攻击的对象瞄准了mongodb数据库。他们删除了所有数据库数据,并...

    calx 评论0 收藏0
  • 为你的mongodb砌堵墙吧,防止被攻击勒索

    摘要:起因年月,当大家都在为的逝去写总结,并为年的到来做计划的时候,一波黑客发动了一轮攻击,攻击的对象瞄准了数据库。他们删除了所有数据库数据,并留下一个勒索数据库。不幸的是,我也成为这幸运的一员。谨记,安全,安全,安全。 起因 2017年1月,当大家都在为16的逝去写总结,并为17年的到来做计划的时候,一波黑客发动了一轮攻击,攻击的对象瞄准了mongodb数据库。他们删除了所有数据库数据,并...

    Meathill 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<