MongoDB 4.4 错误 mongorestore can’t drop live oplog while replicating 解决方法

1 问题现象

在MongoDB 副本集环境中,恢复全库备份时,报如下错误:

[dave@www.cndba.cn ~]# mongorestore --username=root --password=root --host=127.0.0.1 --port=27017 --authenticationDatabase admin --drop --oplogReplay /data/mongodb/backup
2022-05-31T07:45:21.846+0800    preparing collections to restore from
2022-05-31T07:45:21.846+0800    don't know what to do with file "/data/mongodb/backup/.pbm.init", skipping...
2022-05-31T07:45:21.849+0800    reading metadata for cndba.ustc from /data/mongodb/backup/cndba/ustc.metadata.json
2022-05-31T07:45:21.851+0800    reading metadata for config.external_validation_keys from /data/mongodb/backup/config/external_validation_keys.metadata.json
2022-05-31T07:45:21.851+0800    reading metadata for config.tenantMigrationDonors from /data/mongodb/backup/config/tenantMigrationDonors.metadata.json
2022-05-31T07:45:21.852+0800    reading metadata for config.tenantMigrationRecipients from /data/mongodb/backup/config/tenantMigrationRecipients.metadata.json
2022-05-31T07:45:21.852+0800    reading metadata for m201.people from /data/mongodb/backup/m201/people.metadata.json
2022-05-31T07:45:21.853+0800    reading metadata for m201.restaurants from /data/mongodb/backup/m201/restaurants.metadata.json
2022-05-31T07:45:21.854+0800    reading metadata for local.oplog.rs from /data/mongodb/backup/local/oplog.rs.metadata.json
2022-05-31T07:45:21.857+0800    reading metadata for cndba.user from /data/mongodb/backup/cndba/user.metadata.json
2022-05-31T07:45:21.867+0800    dropping collection m201.restaurants before restoring
2022-05-31T07:45:21.867+0800    dropping collection m201.people before restoring
2022-05-31T07:45:21.871+0800    dropping collection local.oplog.rs before restoring
2022-05-31T07:45:21.882+0800    finished restoring local.oplog.rs (0 documents, 0 failures)
2022-05-31T07:45:21.882+0800    Failed: local.oplog.rs: error dropping collection: (Location5255000) can't drop live oplog while replicating
2022-05-31T07:45:21.882+0800    0 document(s) restored successfully. 0 document(s) failed to restore.
[dave@www.cndba.cn ~]#

2 分析过程


这里提示不能drop local.oplog.rs 集合:

2022-05-31T07:45:21.882+0800 Failed: local.oplog.rs: error dropping collection: (Location5255000) can’t drop live oplog while replicating

实际上,因为是我同一个环境恢复的,在进行备份恢复时,local 库不是我们备份的一部分,所以直接将备份目录下的local 目录删除掉就可以正常备份了,注意这里不能重命名, 必须删除或者移动到其他目录, 恢复命令会检索指定目录下的所有文件,重命名还是会报错。

[dave@www.cndba.cn backup]# ll
total 4
drwxr-xr-x 2 root root 128 May 30 23:17 admin
drwxr-xr-x 2 root root  92 May 30 23:17 cndba
drwxr-xr-x 2 root root 251 May 30 23:17 config
drwxr-xr-x 2 root root  57 May 30 23:42 local
drwxr-xr-x 2 root root 110 May 30 23:17 m201
-rw-r--r-- 1 root root 206 May 30 23:17 oplog.bson
[dave@www.cndba.cn backup]#

3 验证恢复

删除local 目录之后,正常恢复。

[dave@www.cndba.cn backup]# mongorestore --username=root --password=root --host=127.0.0.1 --port=27017 --authenticationDatabase admin --drop --oplogReplay /data/mongodb/backup
2022-05-31T08:43:08.705+0800    preparing collections to restore from
2022-05-31T08:43:08.705+0800    don't know what to do with file "/data/mongodb/backup/.pbm.init", skipping...
2022-05-31T08:43:08.707+0800    reading metadata for m201.restaurants from /data/mongodb/backup/m201/restaurants.metadata.json
2022-05-31T08:43:08.708+0800    reading metadata for cndba.user from /data/mongodb/backup/cndba/user.metadata.json
2022-05-31T08:43:08.708+0800    reading metadata for cndba.ustc from /data/mongodb/backup/cndba/ustc.metadata.json
2022-05-31T08:43:08.708+0800    reading metadata for config.external_validation_keys from /data/mongodb/backup/config/external_validation_keys.metadata.json
2022-05-31T08:43:08.708+0800    reading metadata for config.tenantMigrationDonors from /data/mongodb/backup/config/tenantMigrationDonors.metadata.json
2022-05-31T08:43:08.708+0800    reading metadata for config.tenantMigrationRecipients from /data/mongodb/backup/config/tenantMigrationRecipients.metadata.json
2022-05-31T08:43:08.708+0800    reading metadata for m201.people from /data/mongodb/backup/m201/people.metadata.json
2022-05-31T08:43:08.708+0800    dropping collection m201.restaurants before restoring
2022-05-31T08:43:08.708+0800    dropping collection m201.people before restoring
2022-05-31T08:43:08.710+0800    dropping collection cndba.user before restoring
2022-05-31T08:43:08.710+0800    dropping collection cndba.ustc before restoring
2022-05-31T08:43:08.757+0800    restoring m201.restaurants from /data/mongodb/backup/m201/restaurants.bson
2022-05-31T08:43:08.774+0800    restoring cndba.user from /data/mongodb/backup/cndba/user.bson
2022-05-31T08:43:08.785+0800    restoring cndba.ustc from /data/mongodb/backup/cndba/ustc.bson
2022-05-31T08:43:08.798+0800    restoring m201.people from /data/mongodb/backup/m201/people.bson
2022-05-31T08:43:08.864+0800    finished restoring cndba.ustc (2 documents, 0 failures)
2022-05-31T08:43:08.871+0800    dropping collection config.external_validation_keys before restoring
2022-05-31T08:43:08.954+0800    restoring config.external_validation_keys from /data/mongodb/backup/config/external_validation_keys.bson
2022-05-31T08:43:08.964+0800    finished restoring config.external_validation_keys (0 documents, 0 failures)
2022-05-31T08:43:08.964+0800    dropping collection config.tenantMigrationDonors before restoring
2022-05-31T08:43:09.083+0800    restoring config.tenantMigrationDonors from /data/mongodb/backup/config/tenantMigrationDonors.bson
2022-05-31T08:43:09.104+0800    finished restoring config.tenantMigrationDonors (0 documents, 0 failures)
2022-05-31T08:43:09.104+0800    dropping collection config.tenantMigrationRecipients before restoring
2022-05-31T08:43:09.195+0800    restoring config.tenantMigrationRecipients from /data/mongodb/backup/config/tenantMigrationRecipients.bson
2022-05-31T08:43:09.217+0800    finished restoring config.tenantMigrationRecipients (0 documents, 0 failures)
2022-05-31T08:43:11.710+0800    [#.......................]  m201.restaurants   8.65MB/173MB   (5.0%)
2022-05-31T08:43:11.710+0800    [############............]        cndba.user  1.46MB/2.86MB  (51.0%)
2022-05-31T08:43:11.710+0800    [#####################...]       m201.people  17.0MB/18.7MB  (91.2%)
2022-05-31T08:43:11.710+0800
2022-05-31T08:43:12.013+0800    [########################]  m201.people  18.7MB/18.7MB  (100.0%)
2022-05-31T08:43:12.013+0800    finished restoring m201.people (50474 documents, 0 failures)
2022-05-31T08:43:13.949+0800    [########################]  cndba.user  2.86MB/2.86MB  (100.0%)
2022-05-31T08:43:13.949+0800    finished restoring cndba.user (100000 documents, 0 failures)
2022-05-31T08:43:14.705+0800    [##......................]  m201.restaurants  20.4MB/173MB  (11.8%)
2022-05-31T08:43:17.706+0800    [#####...................]  m201.restaurants  36.2MB/173MB  (20.9%)
2022-05-31T08:43:20.706+0800    [#######.................]  m201.restaurants  52.4MB/173MB  (30.3%)
2022-05-31T08:43:23.707+0800    [#########...............]  m201.restaurants  68.7MB/173MB  (39.7%)
2022-05-31T08:43:26.706+0800    [###########.............]  m201.restaurants  83.0MB/173MB  (48.0%)
2022-05-31T08:43:29.706+0800    [#############...........]  m201.restaurants  100MB/173MB  (57.8%)
2022-05-31T08:43:32.706+0800    [################........]  m201.restaurants  117MB/173MB  (67.5%)
2022-05-31T08:43:35.705+0800    [##################......]  m201.restaurants  133MB/173MB  (77.1%)
2022-05-31T08:43:38.705+0800    [####################....]  m201.restaurants  150MB/173MB  (86.9%)
2022-05-31T08:43:41.706+0800    [#######################.]  m201.restaurants  167MB/173MB  (96.6%)
2022-05-31T08:43:42.779+0800    [########################]  m201.restaurants  173MB/173MB  (100.0%)
2022-05-31T08:43:42.779+0800    finished restoring m201.restaurants (1000000 documents, 0 failures)
2022-05-31T08:43:42.779+0800    restoring users from /data/mongodb/backup/admin/system.users.bson
2022-05-31T08:43:42.894+0800    replaying oplog
2022-05-31T08:43:42.895+0800    applied 0 oplog entries
2022-05-31T08:43:42.895+0800    restoring indexes for collection m201.restaurants from metadata
2022-05-31T08:43:42.898+0800    index: &idx.IndexDocument{Options:primitive.M{"name":"stars_1_cuisine_1", "v":2}, Key:primitive.D{primitive.E{Key:"stars", Value:1}, primitive.E{Key:"cuisine", Value:1}}, PartialFilterExpression:primitive.D(nil)}
2022-05-31T08:43:42.898+0800    no indexes to restore for collection m201.people
2022-05-31T08:43:42.898+0800    restoring indexes for collection config.tenantMigrationRecipients from metadata
2022-05-31T08:43:42.898+0800    index: &idx.IndexDocument{Options:primitive.M{"expireAfterSeconds":0, "name":"TenantMigrationRecipientTTLIndex", "v":2}, Key:primitive.D{primitive.E{Key:"expireAt", Value:1}}, PartialFilterExpression:primitive.D(nil)}
2022-05-31T08:43:42.898+0800    no indexes to restore for collection cndba.user
2022-05-31T08:43:42.898+0800    restoring indexes for collection config.external_validation_keys from metadata
2022-05-31T08:43:42.898+0800    index: &idx.IndexDocument{Options:primitive.M{"expireAfterSeconds":0, "name":"ExternalKeysTTLIndex", "v":2}, Key:primitive.D{primitive.E{Key:"ttlExpiresAt", Value:1}}, PartialFilterExpression:primitive.D(nil)}
2022-05-31T08:43:42.899+0800    no indexes to restore for collection cndba.ustc
2022-05-31T08:43:42.899+0800    restoring indexes for collection config.tenantMigrationDonors from metadata
2022-05-31T08:43:42.899+0800    index: &idx.IndexDocument{Options:primitive.M{"expireAfterSeconds":0, "name":"TenantMigrationDonorTTLIndex", "v":2}, Key:primitive.D{primitive.E{Key:"expireAt", Value:1}}, PartialFilterExpression:primitive.D(nil)}
2022-05-31T08:43:48.066+0800    Failed: m201.restaurants: error creating indexes for m201.restaurants: createIndex error: connection(127.0.0.1:27017[-4]) socket was unexpectedly closed: EOF
2022-05-31T08:43:48.066+0800    1150476 document(s) restored successfully. 0 document(s) failed to restore.
[dave@www.cndba.cn backup]#

数据运维技术 » MongoDB 4.4 错误 mongorestore can’t drop live oplog while replicating 解决方法