Skip to content

Commit 61551ee

Browse files
committed
Add validation for fallback & allowPartlyDone opts
1 parent 12861d2 commit 61551ee

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

cmd/pbm/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ func (app *pbmApp) buildRestoreCmd() *cobra.Command {
822822
restoreCmd.Flags().Bool(
823823
"allow-partly-done", false,
824824
"Allows parly done state of the cluster after physical restore. "+
825+
"If enabled (default), partly-done status for RS will be treated as successful restore."+
825826
"If disabled, fallback will be applied when cluster is partly-done.",
826827
)
827828

cmd/pbm/restore.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ func runRestore(
141141
if err := validateRestoreUsersAndRoles(o.usersAndRoles, nss); err != nil {
142142
return nil, errors.Wrap(err, "parse --with-users-and-roles option")
143143
}
144+
if err := validateFallbackOpts(o); err != nil {
145+
return nil, err
146+
}
144147

145148
rsMap, err := parseRSNamesMapping(o.rsMap)
146149
if err != nil {
@@ -816,6 +819,15 @@ func validateNSFromNSTo(o *restoreOpts) error {
816819
return nil
817820
}
818821

822+
func validateFallbackOpts(o *restoreOpts) error {
823+
if o.fallback != nil && !*o.fallback &&
824+
o.allowPartlyDone != nil && !*o.allowPartlyDone {
825+
return errors.New("It's not possible to disable both --allow-partly-done " +
826+
"and --fallback-enabled at the same time.")
827+
}
828+
return nil
829+
}
830+
819831
func parseCLINumInsertionWorkersOption(value int32) (*int32, error) {
820832
if value < 0 {
821833
return nil, errors.New("Number of insertion workers has to be greater than zero.")

pbm/restore/physical.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,9 @@ func (r *PhysRestore) prepareBackup(ctx context.Context, backupName string) erro
25672567
return errors.Wrap(err, "check disk space")
25682568
}
25692569
}
2570+
if !r.fallback && !r.allowPartlyDone {
2571+
return errors.New("fallbackEnabled and allowPartlyDone cannot be disabled at the same time")
2572+
}
25702573

25712574
s, err := topo.ClusterMembers(ctx, r.leadConn.MongoClient())
25722575
if err != nil {

0 commit comments

Comments
 (0)