MongoDB备份和恢复命令

learningops

备份

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
阅读 1.6k

Java, DevOps

2 声望
0 粉丝
0 条评论
你知道吗?

Java, DevOps

2 声望
0 粉丝
宣传栏