Skip to content

Commit

Permalink
delete files on failed backup
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Nov 4, 2024
1 parent 5b787d0 commit efcb57e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/service/backup_routine_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (h *BackupRoutineHandler) runFullBackupInternal(ctx context.Context, now ti
return err
}

err = h.waitForFullBackups(ctx, now)
err = h.waitForFullBackups(ctx, now, logger)
if err != nil {
return err
}
Expand All @@ -123,7 +123,7 @@ func (h *BackupRoutineHandler) runFullBackupInternal(ctx context.Context, now ti
h.deleteFolder(ctx, h.backend.incrementalBackupsPath, logger)
}

h.writeClusterConfiguration(ctx, client.AerospikeClient(), now)
h.writeClusterConfiguration(ctx, client.AerospikeClient(), now, logger)
return nil
}

Expand Down Expand Up @@ -157,17 +157,20 @@ func (h *BackupRoutineHandler) startFullBackupForAllNamespaces(
return nil
}

func (h *BackupRoutineHandler) waitForFullBackups(ctx context.Context, backupTimestamp time.Time) error {
func (h *BackupRoutineHandler) waitForFullBackups(
ctx context.Context, backupTimestamp time.Time, logger *slog.Logger,
) error {
startTime := time.Now() // startTime is only used to measure backup time
for namespace, handler := range h.fullBackupHandlers {
backupFolder := getFullPath(h.backend.fullBackupsPath, h.backupFullPolicy, namespace, backupTimestamp)
err := handler.Wait(ctx)
if err != nil {
backupFailureCounter.Inc()
h.deleteFolder(ctx, backupFolder, logger) // cleanup on failure
return fmt.Errorf("error during backup namespace %s, routine %s: %w",
namespace, h.routineName, err)
}

backupFolder := getFullPath(h.backend.fullBackupsPath, h.backupFullPolicy, namespace, backupTimestamp)
if err := h.writeBackupMetadata(ctx, handler.GetStats(), backupTimestamp, namespace, backupFolder); err != nil {
return err
}
Expand All @@ -177,10 +180,8 @@ func (h *BackupRoutineHandler) waitForFullBackups(ctx context.Context, backupTim
}

func (h *BackupRoutineHandler) writeClusterConfiguration(
ctx context.Context, client backup.AerospikeClient, now time.Time,
ctx context.Context, client backup.AerospikeClient, now time.Time, logger *slog.Logger,
) {
logger := slog.Default().With(slog.String("routine", h.routineName))

infos := getClusterConfiguration(client)
if len(infos) == 0 {
logger.Warn("Could not read aerospike configuration")
Expand Down

0 comments on commit efcb57e

Please sign in to comment.