[root@sh_01 backup]# mongorestore -ubackup -puplooking --authenticationDatabase=admin --gzip -d test --drop --dir=/alidata/backup/test 2018-07-24T14:40:16.961+0800 building a list of collections to restore from /alidata/backup/test dir 2018-07-24T14:40:16.962+0800 reading metadata for test.t1 from /alidata/backup/test/t1.metadata.json.gz 2018-07-24T14:40:16.976+0800 restoring test.t1 from /alidata/backup/test/t1.bson.gz 2018-07-24T14:40:16.977+0800 restoring indexes for collection test.t1 from metadata 2018-07-24T14:40:16.977+0800 finished restoring test.t1 (1 document) 2018-07-24T14:40:16.977+0800 done
将压缩过的逻辑备份,以合并的方式导入test库(不加--drop)
# 备份数据为test.t1 { "_id" : ObjectId("5b55b8623496bc5ff3fb047e"), "id" : 1 } ## 场景1 #> 当前数据为test.t1 > db.t1.find() { "_id" : ObjectId("5b55b8623496bc5ff3fb047e"), "id" : 1 } #> 导入数据时会发现存在报错,跳过了重复的文档(行) [root@sh_01 backup]# mongorestore -ubackup -puplooking --authenticationDatabase=admin --gzip -d test --dir=/alidata/backup/test 2018-07-24T14:49:14.472+0800 building a list of collections to restore from /alidata/backup/test dir 2018-07-24T14:49:14.473+0800 reading metadata for test.t1 from /alidata/backup/test/t1.metadata.json.gz 2018-07-24T14:49:14.473+0800 restoring test.t1 from /alidata/backup/test/t1.bson.gz 2018-07-24T14:49:14.475+0800 error: E11000 duplicate key error collection: test.t1 index: _id_ dup key: { : ObjectId('5b55b8623496bc5ff3fb047e') } 2018-07-24T14:49:14.475+0800 restoring indexes for collection test.t1 from metadata 2018-07-24T14:49:14.475+0800 finished restoring test.t1 (1 document) 2018-07-24T14:49:14.475+0800 done #> 恢复结果 > db.t1.find() { "_id" : ObjectId("5b55b8623496bc5ff3fb047e"), "id" : 1 } ## 场景2 #> 当前数据为test.t1 > db.t1.find() { "_id" : ObjectId("5b55b8623496bc5ff3fb047e"), "id" : 1 } { "_id" : ObjectId("5b56cc3eaa626db6a5bc7141"), "name" : "booboo" } #> 导入数据时会发现存在报错,跳过了重复的文档(行) [root@sh_01 backup]# mongorestore -ubackup -puplooking --authenticationDatabase=admin --gzip -d test --dir=/alidata/backup/test 2018-07-24T14:56:48.230+0800 building a list of collections to restore from /alidata/backup/test dir 2018-07-24T14:56:48.231+0800 reading metadata for test.t1 from /alidata/backup/test/t1.metadata.json.gz 2018-07-24T14:56:48.232+0800 restoring test.t1 from /alidata/backup/test/t1.bson.gz 2018-07-24T14:56:48.233+0800 error: E11000 duplicate key error collection: test.t1 index: _id_ dup key: { : ObjectId('5b55b8623496bc5ff3fb047e') } 2018-07-24T14:56:48.233+0800 restoring indexes for collection test.t1 from metadata 2018-07-24T14:56:48.234+0800 finished restoring test.t1 (1 document) 2018-07-24T14:56:48.234+0800 done #> 恢复结果 > db.t1.find() { "_id" : ObjectId("5b55b8623496bc5ff3fb047e"), "id" : 1 } { "_id" : ObjectId("5b56cc3eaa626db6a5bc7141"), "name" : "booboo" } ## 场景3 #> 当前数据为test.t1 > db.t1.find() { "_id" : ObjectId("5b56ce7caa626db6a5bc7142"), "justice" : 1 } #> 导入数据 [root@sh_01 backup]# mongorestore -ubackup -puplooking --authenticationDatabase=admin --gzip -d test --dir=/alidata/backup/test 2018-07-24T15:00:38.507+0800 building a list of collections to restore from /alidata/backup/test dir 2018-07-24T15:00:38.508+0800 reading metadata for test.t1 from /alidata/backup/test/t1.metadata.json.gz 2018-07-24T15:00:38.508+0800 restoring test.t1 from /alidata/backup/test/t1.bson.gz 2018-07-24T15:00:38.511+0800 restoring indexes for collection test.t1 from metadata 2018-07-24T15:00:38.511+0800 finished restoring test.t1 (1 document) 2018-07-24T15:00:38.511+0800 done #> 恢复结果 > db.t1.find() { "_id" : ObjectId("5b55b8623496bc5ff3fb047e"), "id" : 1 } { "_id" : ObjectId("5b56cc3eaa626db6a5bc7141"), "name" : "booboo" }