@@ -15,6 +15,7 @@ import (
1515 "github.com/percona/percona-backup-mongodb/pbm/errors"
1616 "github.com/percona/percona-backup-mongodb/pbm/log"
1717 "github.com/percona/percona-backup-mongodb/pbm/oplog"
18+ "github.com/percona/percona-backup-mongodb/pbm/storage"
1819 "github.com/percona/percona-backup-mongodb/pbm/util"
1920)
2021
@@ -321,17 +322,23 @@ func DeleteBackupBefore(
321322 conn connect.Client ,
322323 t time.Time ,
323324 bcpType defs.BackupType ,
325+ profile string ,
324326 node string ,
325327) error {
326- backups , err := ListDeleteBackupBefore (ctx , conn , primitive.Timestamp {T : uint32 (t .Unix ())}, bcpType )
328+ backups , err := ListDeleteBackupBefore (ctx , conn , primitive.Timestamp {T : uint32 (t .Unix ())}, bcpType , profile )
327329 if err != nil {
328330 return err
329331 }
330332 if len (backups ) == 0 {
331333 return nil
332334 }
333335
334- stg , err := util .GetStorage (ctx , conn , node , log .LogEventFromContext (ctx ))
336+ var stg storage.Storage
337+ if profile == "" {
338+ stg , err = util .GetStorage (ctx , conn , node , log .LogEventFromContext (ctx ))
339+ } else {
340+ stg , err = util .GetProfiledStorage (ctx , conn , profile , node , log .LogEventFromContext (ctx ))
341+ }
335342 if err != nil {
336343 return errors .Wrap (err , "get storage" )
337344 }
@@ -360,7 +367,7 @@ func ListDeleteBackupBefore(
360367 bcpType defs.BackupType ,
361368 profile string ,
362369) ([]BackupMeta , error ) {
363- info , err := MakeCleanupInfo (ctx , conn , ts )
370+ info , err := MakeCleanupInfo (ctx , conn , ts , profile )
364371 if err != nil {
365372 return nil , err
366373 }
@@ -391,8 +398,8 @@ func ListDeleteBackupBefore(
391398 return rv , nil
392399}
393400
394- func MakeCleanupInfo (ctx context.Context , conn connect.Client , ts primitive.Timestamp ) (CleanupInfo , error ) {
395- backups , err := listBackupsBefore (ctx , conn , primitive.Timestamp {T : ts .T + 1 })
401+ func MakeCleanupInfo (ctx context.Context , conn connect.Client , ts primitive.Timestamp , profile string ) (CleanupInfo , error ) {
402+ backups , err := listBackupsBefore (ctx , conn , primitive.Timestamp {T : ts .T + 1 }, profile )
396403 if err != nil {
397404 return CleanupInfo {}, errors .Wrap (err , "list backups before" )
398405 }
@@ -500,9 +507,8 @@ func MakeCleanupInfo(ctx context.Context, conn connect.Client, ts primitive.Time
500507// listBackupsBefore returns backups with restore cluster time less than or equals to ts.
501508//
502509// It does not include backups stored on an external storages.
503- func listBackupsBefore (ctx context.Context , conn connect.Client , ts primitive.Timestamp ) ([]BackupMeta , error ) {
510+ func listBackupsBefore (ctx context.Context , conn connect.Client , ts primitive.Timestamp , profile string ) ([]BackupMeta , error ) {
504511 f := bson.D {
505- {"store.profile" , nil },
506512 {"last_write_ts" , bson.M {"$lt" : ts }},
507513 {"status" , bson.M {"$in" : bson.A {
508514 defs .StatusDone ,
0 commit comments