MongoDB備份和恢復命令

備份

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的文件rest

嘗試重複執行備份

會覆蓋第一次的備份文件code

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 errorit

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後恢復

沒有任何異常恢復成功io

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
相關文章
相關標籤/搜索