From 9db184f5d4c325ed18aeb4fba6c57c28b0e3ae40 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Thu, 8 May 2025 10:51:35 +0200 Subject: [PATCH] feat: log the downloaded backup catalog before restore (#323) Closes: #319 Signed-off-by: Leonardo Cecchi --- internal/cnpgi/restore/restore.go | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/internal/cnpgi/restore/restore.go b/internal/cnpgi/restore/restore.go index ae1a776..03c8941 100644 --- a/internal/cnpgi/restore/restore.go +++ b/internal/cnpgi/restore/restore.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path" + "time" "github.com/cloudnative-pg/barman-cloud/pkg/api" barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver" @@ -358,10 +359,12 @@ func loadBackupObjectFromExternalCluster( return nil, nil, err } + contextLogger.Info("Downloading backup catalog") backupCatalog, err := barmanCommand.GetBackupList(ctx, recoveryObjectStore, serverName, env) if err != nil { return nil, nil, err } + contextLogger.Info("Downloaded backup catalog", "backupCatalog", shortenedCatalog(backupCatalog)) // We are now choosing the right backup to restore var targetBackup *barmanCatalog.BarmanBackup @@ -408,3 +411,34 @@ func loadBackupObjectFromExternalCluster( }, }, env, nil } + +// ShortBackupCatalogEntry is used when logging the downloaded backup +// catalog and contains only the fields used for debugging +type ShortBackupCatalogEntry struct { + // BackupID is the backup ID + BackupID string `json:"backupID"` + + // StartTime is the backup time + StartTime time.Time `json:"startTime"` + + // EndTime is the end time + EndTime time.Time `json:"endTime"` +} + +// shortenedCatalog creates a structure containing the debug information +// of a backup catalog. +func shortenedCatalog(catalog *barmanCatalog.Catalog) []ShortBackupCatalogEntry { + if catalog == nil { + return nil + } + + result := make([]ShortBackupCatalogEntry, len(catalog.List)) + + for i, v := range catalog.List { + result[i].BackupID = v.BackupName + result[i].StartTime = v.BeginTime + result[i].EndTime = v.EndTime + } + + return result +}