Skip to content

Commit 9db184f

Browse files
authored
feat: log the downloaded backup catalog before restore (#323)
Closes: #319 Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent 087623f commit 9db184f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

internal/cnpgi/restore/restore.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/exec"
99
"path"
10+
"time"
1011

1112
"github.com/cloudnative-pg/barman-cloud/pkg/api"
1213
barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver"
@@ -358,10 +359,12 @@ func loadBackupObjectFromExternalCluster(
358359
return nil, nil, err
359360
}
360361

362+
contextLogger.Info("Downloading backup catalog")
361363
backupCatalog, err := barmanCommand.GetBackupList(ctx, recoveryObjectStore, serverName, env)
362364
if err != nil {
363365
return nil, nil, err
364366
}
367+
contextLogger.Info("Downloaded backup catalog", "backupCatalog", shortenedCatalog(backupCatalog))
365368

366369
// We are now choosing the right backup to restore
367370
var targetBackup *barmanCatalog.BarmanBackup
@@ -408,3 +411,34 @@ func loadBackupObjectFromExternalCluster(
408411
},
409412
}, env, nil
410413
}
414+
415+
// ShortBackupCatalogEntry is used when logging the downloaded backup
416+
// catalog and contains only the fields used for debugging
417+
type ShortBackupCatalogEntry struct {
418+
// BackupID is the backup ID
419+
BackupID string `json:"backupID"`
420+
421+
// StartTime is the backup time
422+
StartTime time.Time `json:"startTime"`
423+
424+
// EndTime is the end time
425+
EndTime time.Time `json:"endTime"`
426+
}
427+
428+
// shortenedCatalog creates a structure containing the debug information
429+
// of a backup catalog.
430+
func shortenedCatalog(catalog *barmanCatalog.Catalog) []ShortBackupCatalogEntry {
431+
if catalog == nil {
432+
return nil
433+
}
434+
435+
result := make([]ShortBackupCatalogEntry, len(catalog.List))
436+
437+
for i, v := range catalog.List {
438+
result[i].BackupID = v.BackupName
439+
result[i].StartTime = v.BeginTime
440+
result[i].EndTime = v.EndTime
441+
}
442+
443+
return result
444+
}

0 commit comments

Comments
 (0)