Skip to content

Commit 484a40a

Browse files
committed
restore only required collections for config db
1 parent 53ea810 commit 484a40a

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

pbm/oplog/restore.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/mongodb/mongo-tools/common/bsonutil"
2121
"github.com/mongodb/mongo-tools/common/db"
22+
"github.com/mongodb/mongo-tools/common/dumprestore"
2223
"github.com/mongodb/mongo-tools/common/idx"
2324
"github.com/mongodb/mongo-tools/common/txn"
2425
"github.com/mongodb/mongo-tools/mongorestore/ns"
@@ -291,15 +292,21 @@ func (o *OplogRestore) handleOp(oe db.Oplog) error {
291292
return nil
292293
}
293294

294-
if o.excludeNS.Has(oe.Namespace) {
295+
// skip no-ops
296+
if oe.Operation == "n" {
295297
return nil
296298
}
297299

298-
// skip no-ops
299-
if oe.Operation == "n" {
300+
if o.excludeNS.Has(oe.Namespace) {
300301
return nil
301302
}
302303

304+
if db, coll, _ := strings.Cut(oe.Namespace, "."); db == "config" {
305+
if !sliceContains(dumprestore.ConfigCollectionsToKeep, coll) {
306+
return nil
307+
}
308+
}
309+
303310
if !o.isOpSelected(&oe) {
304311
return nil
305312
}
@@ -623,6 +630,12 @@ func (o *OplogRestore) handleNonTxnOp(op db.Oplog) error {
623630
return nil
624631
}
625632

633+
if db, coll, _ := strings.Cut(op.Namespace, "."); db == "config" {
634+
if !sliceContains(dumprestore.ConfigCollectionsToKeep, coll) {
635+
return nil
636+
}
637+
}
638+
626639
op, err := o.filterUUIDs(op)
627640
if err != nil {
628641
return errors.Wrap(err, "filtering UUIDs from oplog")

pbm/oplog/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package oplog
2+
3+
func sliceContains[S ~[]E, E comparable](s S, v E) bool {
4+
for i := range s {
5+
if v == s[i] {
6+
return true
7+
}
8+
}
9+
return false
10+
}

pbm/snapshot/restore.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,7 @@ var ExcludeFromRestore = []string{
3232
defs.DB + "." + defs.PBMOpLogCollection,
3333
"admin.system.version",
3434
"config.version",
35-
"config.mongos",
36-
"config.lockpings",
37-
"config.locks",
38-
"config.system.sessions",
39-
"config.cache.*",
4035
"config.shards",
41-
"config.transactions",
42-
"config.transaction_coordinators",
43-
"config.changelog",
44-
"config.actionlog",
45-
"config.image_collection",
46-
"config.system.indexBuilds",
47-
"config.system.sharding_ddl_coordinators",
4836

4937
// deprecated PBM collections, keep it here not to bring back from old backups
5038
defs.DB + ".pbmBackups.old",

0 commit comments

Comments
 (0)