Skip to content

Commit 2a91e74

Browse files
committed
PBM-1389: disallow sel backup/restore with ConfigShard
1 parent e67c983 commit 2a91e74

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

pbm/backup/backup.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ func (b *Backup) Init(
166166
//
167167
//nolint:nonamedreturns
168168
func (b *Backup) Run(ctx context.Context, bcp *ctrl.BackupCmd, opid ctrl.OPID, l log.LogEvent) (err error) {
169+
if b.brief.Sharded &&
170+
b.brief.Version.IsConfigShardSupported() &&
171+
util.IsSelective(bcp.Namespaces) {
172+
hasConfigShard, err := topo.HasConfigShard(ctx, b.leadConn)
173+
if err != nil {
174+
return errors.Wrap(err, "check for Config Shard")
175+
}
176+
if hasConfigShard {
177+
return errors.New("selective backup is not supported with Config Shard")
178+
}
179+
}
180+
169181
inf, err := topo.GetNodeInfoExt(ctx, b.nodeConn)
170182
if err != nil {
171183
return errors.Wrap(err, "get cluster info")

pbm/restore/logical.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (r *Restore) Snapshot(
187187
return errors.Wrap(err, "set backup name")
188188
}
189189

190-
err = r.checkSnapshot(ctx, bcp)
190+
err = r.checkSnapshot(ctx, bcp, nss)
191191
if err != nil {
192192
return err
193193
}
@@ -316,7 +316,7 @@ func (r *Restore) PITR(
316316
return errors.Wrap(err, "set backup name")
317317
}
318318

319-
err = r.checkSnapshot(ctx, bcp)
319+
err = r.checkSnapshot(ctx, bcp, nss)
320320
if err != nil {
321321
return err
322322
}
@@ -697,7 +697,7 @@ func (r *Restore) snapshotObjects(bcp *backup.BackupMeta) (string, []oplog.Oplog
697697
return rsMeta.DumpName, chunks, nil
698698
}
699699

700-
func (r *Restore) checkSnapshot(ctx context.Context, bcp *backup.BackupMeta) error {
700+
func (r *Restore) checkSnapshot(ctx context.Context, bcp *backup.BackupMeta, nss []string) error {
701701
if bcp.Status != defs.StatusDone {
702702
return errors.Errorf("backup wasn't successful: status: %s, error: %s",
703703
bcp.Status, bcp.Error())
@@ -731,6 +731,16 @@ func (r *Restore) checkSnapshot(ctx context.Context, bcp *backup.BackupMeta) err
731731
bcp.MongoVersion, ver.VersionString)
732732
return nil
733733
}
734+
735+
if r.brief.Sharded && ver.IsConfigShardSupported() && util.IsSelective(nss) {
736+
hasConfigShard, err := topo.HasConfigShard(ctx, r.leadConn)
737+
if err != nil {
738+
return errors.Wrap(err, "check for Config Shard")
739+
}
740+
if hasConfigShard {
741+
return errors.New("selective restore is not supported with Config Shard")
742+
}
743+
}
734744
}
735745

736746
return nil

0 commit comments

Comments
 (0)