Skip to content

Commit

Permalink
restore only required collections for config db
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin committed Feb 26, 2024
1 parent 53ea810 commit ecb722c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
19 changes: 16 additions & 3 deletions pbm/oplog/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/mongodb/mongo-tools/common/bsonutil"
"github.com/mongodb/mongo-tools/common/db"
"github.com/mongodb/mongo-tools/common/dumprestore"
"github.com/mongodb/mongo-tools/common/idx"
"github.com/mongodb/mongo-tools/common/txn"
"github.com/mongodb/mongo-tools/mongorestore/ns"
Expand Down Expand Up @@ -291,15 +292,21 @@ func (o *OplogRestore) handleOp(oe db.Oplog) error {
return nil
}

if o.excludeNS.Has(oe.Namespace) {
// skip no-ops
if oe.Operation == "n" {
return nil
}

// skip no-ops
if oe.Operation == "n" {
if o.excludeNS.Has(oe.Namespace) {
return nil
}

if db, coll, _ := strings.Cut(oe.Namespace, "."); db == "config" {
if !sliceContains(dumprestore.ConfigCollectionsToKeep, coll) {
return nil
}
}

if !o.isOpSelected(&oe) {
return nil
}
Expand Down Expand Up @@ -623,6 +630,12 @@ func (o *OplogRestore) handleNonTxnOp(op db.Oplog) error {
return nil
}

if db, coll, _ := strings.Cut(op.Namespace, "."); db == "config" {
if !sliceContains(dumprestore.ConfigCollectionsToKeep, coll) {
return nil
}
}

op, err := o.filterUUIDs(op)
if err != nil {
return errors.Wrap(err, "filtering UUIDs from oplog")
Expand Down
10 changes: 10 additions & 0 deletions pbm/oplog/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package oplog

func sliceContains[S ~[]E, E comparable](s S, v E) bool {
for i := range s {
if v == s[i] {
return true
}
}
return false
}
14 changes: 0 additions & 14 deletions pbm/snapshot/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ var ExcludeFromRestore = []string{
defs.DB + "." + defs.AgentsStatusCollection,
defs.DB + "." + defs.PBMOpLogCollection,
"admin.system.version",
"config.version",
"config.mongos",
"config.lockpings",
"config.locks",
"config.system.sessions",
"config.cache.*",
"config.shards",
"config.transactions",
"config.transaction_coordinators",
"config.changelog",
"config.actionlog",
"config.image_collection",
"config.system.indexBuilds",
"config.system.sharding_ddl_coordinators",

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

0 comments on commit ecb722c

Please sign in to comment.