Skip to content

Commit f585684

Browse files
committed
PBM-1649 Profile support for delete and cleanup in PBM CLI
1 parent ab25022 commit f585684

File tree

7 files changed

+40
-9
lines changed

7 files changed

+40
-9
lines changed

cmd/pbm/delete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func deleteManyBackup(ctx context.Context, pbm *sdk.Client, d *deleteBcpOpts) (s
146146
if err != nil {
147147
return sdk.NoOpID, errors.Wrap(err, "parse --type")
148148
}
149-
backups, err := sdk.ListDeleteBackupBefore(ctx, pbm, ts, bcpType)
149+
backups, err := sdk.ListDeleteBackupBefore(ctx, pbm, ts, bcpType, d.profile)
150150
if err != nil {
151151
return sdk.NoOpID, errors.Wrap(err, "fetch backup list")
152152
}
@@ -162,7 +162,7 @@ func deleteManyBackup(ctx context.Context, pbm *sdk.Client, d *deleteBcpOpts) (s
162162
}
163163
}
164164

165-
cid, err := pbm.DeleteBackupBefore(ctx, ts, sdk.DeleteBackupBeforeOptions{Type: bcpType})
165+
cid, err := pbm.DeleteBackupBefore(ctx, ts, sdk.DeleteBackupBeforeOptions{Type: bcpType, Profile: d.profile})
166166
return cid, errors.Wrap(err, "schedule delete")
167167
}
168168

@@ -295,7 +295,7 @@ func doCleanup(ctx context.Context, conn connect.Client, pbm *sdk.Client, d *cle
295295
}
296296
}
297297

298-
info, err := pbm.CleanupReport(ctx, ts)
298+
info, err := pbm.CleanupReport(ctx, ts, d.profile)
299299
if err != nil {
300300
return nil, errors.Wrap(err, "make cleanup report")
301301
}
@@ -317,7 +317,7 @@ func doCleanup(ctx context.Context, conn connect.Client, pbm *sdk.Client, d *cle
317317
}
318318
}
319319

320-
cid, err := pbm.RunCleanup(ctx, ts)
320+
cid, err := pbm.RunCleanup(ctx, ts, d.profile)
321321
if err != nil {
322322
return nil, errors.Wrap(err, "send command")
323323
}

pbm/backup/delete.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func ListDeleteBackupBefore(
358358
conn connect.Client,
359359
ts primitive.Timestamp,
360360
bcpType defs.BackupType,
361+
profile string,
361362
) ([]BackupMeta, error) {
362363
info, err := MakeCleanupInfo(ctx, conn, ts)
363364
if err != nil {
@@ -509,6 +510,12 @@ func listBackupsBefore(ctx context.Context, conn connect.Client, ts primitive.Ti
509510
defs.StatusError,
510511
}}},
511512
}
513+
if profile == "" {
514+
f = append(f, bson.E{Key: "store.profile", Value: nil})
515+
} else {
516+
f = append(f, bson.E{Key: "store.profile", Value: true}, bson.E{Key: "store.name", Value: profile})
517+
}
518+
512519
o := options.Find().SetSort(bson.D{{"last_write_ts", 1}})
513520
cur, err := conn.BcpCollection().Find(ctx, f, o)
514521
if err != nil {

pbm/ctrl/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ type DeleteBackupCmd struct {
203203
Backup string `bson:"backup"`
204204
OlderThan int64 `bson:"olderthan"`
205205
Type defs.BackupType `bson:"type"`
206+
Profile string `bson:"profile"`
206207
}
207208

208209
type DeletePITRCmd struct {
@@ -211,6 +212,7 @@ type DeletePITRCmd struct {
211212

212213
type CleanupCmd struct {
213214
OlderThan primitive.Timestamp `bson:"olderThan"`
215+
Profile string `bson:"profile"`
214216
}
215217

216218
func (d DeleteBackupCmd) String() string {

pbm/ctrl/send.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ func SendDeleteBackupBefore(
2727
m connect.Client,
2828
before primitive.Timestamp,
2929
type_ defs.BackupType,
30+
profile string,
3031
) (OPID, error) {
3132
cmd := Cmd{
3233
Cmd: CmdDeleteBackup,
3334
Delete: &DeleteBackupCmd{
3435
OlderThan: int64(before.T),
3536
Type: type_,
37+
Profile: profile,
3638
},
3739
}
3840
return sendCommand(ctx, m, cmd)
@@ -56,11 +58,13 @@ func SendCleanup(
5658
ctx context.Context,
5759
m connect.Client,
5860
before primitive.Timestamp,
61+
profile string,
5962
) (OPID, error) {
6063
cmd := Cmd{
6164
Cmd: CmdCleanup,
6265
Cleanup: &CleanupCmd{
6366
OlderThan: before,
67+
Profile: profile,
6468
},
6569
}
6670
return sendCommand(ctx, m, cmd)

pbm/util/storage.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ func GetStorage(ctx context.Context, m connect.Client, node string, l log.LogEve
7979
return StorageFromConfig(&c.Storage, node, l)
8080
}
8181

82+
func GetProfiledStorage(
83+
ctx context.Context,
84+
m connect.Client,
85+
profile string,
86+
node string,
87+
l log.LogEvent,
88+
) (storage.Storage, error) {
89+
c, err := config.GetProfile(ctx, m, profile)
90+
if err != nil {
91+
return nil, errors.Wrap(err, "get profile")
92+
}
93+
94+
return StorageFromConfig(&c.Storage, node, l)
95+
}
96+
8297
// Initialize write current PBM version to PBM init file.
8398
//
8499
// It does not handle "file already exists" error.

sdk/impl.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (c *Client) DeleteBackupBefore(
323323
beforeTS Timestamp,
324324
options DeleteBackupBeforeOptions,
325325
) (CommandID, error) {
326-
opid, err := ctrl.SendDeleteBackupBefore(ctx, c.conn, beforeTS, options.Type)
326+
opid, err := ctrl.SendDeleteBackupBefore(ctx, c.conn, beforeTS, options.Type, options.Profile)
327327
return CommandID(opid.String()), err
328328
}
329329

@@ -334,10 +334,11 @@ func (c *Client) DeleteOplogRange(ctx context.Context, until Timestamp) (Command
334334

335335
func (c *Client) CleanupReport(ctx context.Context, beforeTS Timestamp) (CleanupReport, error) {
336336
return backup.MakeCleanupInfo(ctx, c.conn, beforeTS)
337+
func (c *Client) CleanupReport(ctx context.Context, beforeTS Timestamp, profile string) (CleanupReport, error) {
337338
}
338339

339-
func (c *Client) RunCleanup(ctx context.Context, beforeTS Timestamp) (CommandID, error) {
340-
opid, err := ctrl.SendCleanup(ctx, c.conn, beforeTS)
340+
func (c *Client) RunCleanup(ctx context.Context, beforeTS Timestamp, profile string) (CommandID, error) {
341+
opid, err := ctrl.SendCleanup(ctx, c.conn, beforeTS, profile)
341342
return CommandID(opid.String()), err
342343
}
343344

sdk/sdk.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ type GetAllRestoresOptions struct {
107107
}
108108

109109
type DeleteBackupBeforeOptions struct {
110-
Type BackupType
110+
Type BackupType
111+
Profile string
111112
}
112113

113114
// OpLock represents internal PBM lock.
@@ -214,8 +215,9 @@ func ListDeleteBackupBefore(
214215
client *Client,
215216
ts primitive.Timestamp,
216217
bcpType BackupType,
218+
profile string,
217219
) ([]BackupMetadata, error) {
218-
return backup.ListDeleteBackupBefore(ctx, client.conn, ts, bcpType)
220+
return backup.ListDeleteBackupBefore(ctx, client.conn, ts, bcpType, profile)
219221
}
220222

221223
func ListDeleteChunksBefore(

0 commit comments

Comments
 (0)