-
Notifications
You must be signed in to change notification settings - Fork 111
PBM-1649 Support profiles in cleanup and delete-backup #1227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
36e5c81
dfddd80
acf607f
5f60fea
90d3623
3483320
f168e05
8677ace
a2c65c5
d44abd3
4cd4f7c
1b04ae4
d90fb0e
e140609
91dc2f3
68c0775
ed3582d
dc3d250
b6fdb4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |
| "go.mongodb.org/mongo-driver/bson/primitive" | ||
|
|
||
| "github.com/percona/percona-backup-mongodb/pbm/backup" | ||
| "github.com/percona/percona-backup-mongodb/pbm/config" | ||
| "github.com/percona/percona-backup-mongodb/pbm/connect" | ||
| "github.com/percona/percona-backup-mongodb/pbm/ctrl" | ||
| "github.com/percona/percona-backup-mongodb/pbm/defs" | ||
|
|
@@ -25,6 +26,7 @@ type deleteBcpOpts struct { | |
| name string | ||
| olderThan string | ||
| bcpType string | ||
| profile string | ||
| dryRun bool | ||
| yes bool | ||
| } | ||
|
|
@@ -36,14 +38,26 @@ func deleteBackup( | |
| d *deleteBcpOpts, | ||
| ) (fmt.Stringer, error) { | ||
| if d.name == "" && d.olderThan == "" { | ||
| return nil, errors.New("either --name or --older-than should be set") | ||
| return nil, errors.New("either [name] or --older-than should be set") | ||
| } | ||
| if d.name != "" && d.olderThan != "" { | ||
| return nil, errors.New("cannot use --name and --older-than at the same command") | ||
| return nil, errors.New("cannot use [name] and --older-than at the same command") | ||
| } | ||
| if d.name != "" && d.profile != "" { | ||
| return nil, errors.New("cannot use [name] with --profile") | ||
| } | ||
| if d.bcpType != "" && d.olderThan == "" { | ||
| return nil, errors.New("cannot use --type without --older-than") | ||
| } | ||
| if d.profile != "" { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we should forbidden delete by name in combination with In case when backup-name is on default storage or on e.g. Alternative is to not delete that backup in case when that backup-name is not present within the profile storage, but I'd recommend the first solution. |
||
| _, err := config.GetProfile(ctx, conn, d.profile) | ||
| if err != nil { | ||
| if errors.Is(err, config.ErrMissedConfigProfile) { | ||
| return nil, errors.Errorf("profile %q is not found", d.profile) | ||
| } | ||
| return nil, errors.Wrap(err, "get config") | ||
| } | ||
| } | ||
| if !d.dryRun { | ||
| err := checkForAnotherOperation(ctx, pbm) | ||
| if err != nil { | ||
|
|
@@ -135,7 +149,7 @@ func deleteManyBackup(ctx context.Context, pbm *sdk.Client, d *deleteBcpOpts) (s | |
| if err != nil { | ||
| return sdk.NoOpID, errors.Wrap(err, "parse --type") | ||
| } | ||
| backups, err := sdk.ListDeleteBackupBefore(ctx, pbm, ts, bcpType) | ||
| backups, err := sdk.ListDeleteBackupBefore(ctx, pbm, ts, bcpType, d.profile) | ||
| if err != nil { | ||
| return sdk.NoOpID, errors.Wrap(err, "fetch backup list") | ||
| } | ||
|
|
@@ -151,7 +165,7 @@ func deleteManyBackup(ctx context.Context, pbm *sdk.Client, d *deleteBcpOpts) (s | |
| } | ||
| } | ||
|
|
||
| cid, err := pbm.DeleteBackupBefore(ctx, ts, sdk.DeleteBackupBeforeOptions{Type: bcpType}) | ||
| cid, err := pbm.DeleteBackupBefore(ctx, ts, sdk.DeleteBackupBeforeOptions{Type: bcpType, Profile: d.profile}) | ||
| return cid, errors.Wrap(err, "schedule delete") | ||
| } | ||
|
|
||
|
|
@@ -255,6 +269,7 @@ type cleanupOptions struct { | |
| wait bool | ||
| waitTime time.Duration | ||
| dryRun bool | ||
| profile string | ||
| } | ||
|
|
||
| func doCleanup(ctx context.Context, conn connect.Client, pbm *sdk.Client, d *cleanupOptions) (fmt.Stringer, error) { | ||
|
|
@@ -267,14 +282,23 @@ func doCleanup(ctx context.Context, conn connect.Client, pbm *sdk.Client, d *cle | |
| realTime := n.Format(time.RFC3339) | ||
| return nil, errors.Errorf("--older-than %q is after now %q", providedTime, realTime) | ||
| } | ||
| if d.profile != "" { | ||
| _, err := config.GetProfile(ctx, conn, d.profile) | ||
| if err != nil { | ||
| if errors.Is(err, config.ErrMissedConfigProfile) { | ||
| return nil, errors.Errorf("profile %q is not found", d.profile) | ||
| } | ||
| return nil, errors.Wrap(err, "get config") | ||
| } | ||
| } | ||
| if !d.dryRun { | ||
| err := checkForAnotherOperation(ctx, pbm) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| info, err := pbm.CleanupReport(ctx, ts) | ||
| info, err := pbm.CleanupReport(ctx, ts, d.profile) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "make cleanup report") | ||
| } | ||
|
|
@@ -296,7 +320,7 @@ func doCleanup(ctx context.Context, conn connect.Client, pbm *sdk.Client, d *cle | |
| } | ||
| } | ||
|
|
||
| cid, err := pbm.RunCleanup(ctx, ts) | ||
| cid, err := pbm.RunCleanup(ctx, ts, d.profile) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "send command") | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.