Skip to content

Modern Docker Management, Designed for Everyone

fix: allow deleting backups whose S3 repository no longer exists (#4319)

Kyle Mendellcf5ed429a493
diff --git a/backend/internal/backup/service.go b/backend/internal/backup/service.go
index 68b7e4559..9b1abf31d 100644
--- a/backend/internal/backup/service.go
+++ b/backend/internal/backup/service.go
@@ -876,18 +876,24 @@ func RemoteSnapshotChecker(ctx context.Context, destinations *s3.S3DestinationSe
}
}
-// CheckScheduledRemote permits first-use initialization, but detects lost repositories.
-func CheckScheduledRemote(ctx context.Context, db *database.DB, destinations *s3.S3DestinationService, table, destinationID, root string) error {
+// CheckRemoteRepository probes the destination's repository config within a bounded budget.
+// Transport and credential failures are returned as errors so callers never forget snapshots blindly.
+func CheckRemoteRepository(ctx context.Context, destinations *s3.S3DestinationService, destinationID, root string) (backup.RepositoryObservation, error) {
if destinations == nil {
- return errors.New("S3 destinations are unavailable")
+ return backup.RepositoryObservation{}, errors.New("S3 destinations are unavailable")
}
configuration, err := destinations.Configuration(ctx, destinationID)
if err != nil {
- return err
+ return backup.RepositoryObservation{}, err
}
checkCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
- result, err := s3util.CheckRepository(checkCtx, configuration, root, "")
+ return s3util.CheckRepository(checkCtx, configuration, root, "")
+}
+
+// CheckScheduledRemote permits first-use initialization, but detects lost repositories.
+func CheckScheduledRemote(ctx context.Context, db *database.DB, destinations *s3.S3DestinationService, table, destinationID, root string) error {
+ result, err := CheckRemoteRepository(ctx, destinations, destinationID, root)
if err != nil || result.Available {
return err
}
diff --git a/backend/internal/system/children/backup/service.go b/backend/internal/system/children/backup/service.go
index 5562266be..01ad644d8 100644
--- a/backend/internal/system/children/backup/service.go
+++ b/backend/internal/system/children/backup/service.go
@@ -748,6 +748,14 @@ func (s *Service) deleteRunsInternal(ctx context.Context, localRuns2 []*backupty
}
continue
}
+ switch {
+ case run.LocalSnapshotID != "" && run.RemoteSnapshotID != "":
+ run.Destination = backuptypes.SystemBackupDestinationLocalS3
+ case run.LocalSnapshotID != "":
+ run.Destination = backuptypes.SystemBackupDestinationLocal
+ default:
+ run.Destination = backuptypes.SystemBackupDestinationS3
+ }
if saveErr := s.store.SaveRun(ctx, run); saveErr != nil {
deleteErr = errors.Join(deleteErr, saveErr)
}
@@ -783,7 +791,16 @@ func (s *Service) forgetRemoteSnapshotsInternal(ctx context.Context, dockerClien
}
repository, repoErr := s.remoteRepositoryInternal(ctx, destinationID)
if repoErr == nil {
- repoErr = s.engine.ForgetSnapshots(ctx, dockerClient, repository, key, snapshotIDs)
+ var observation backuptypes.RepositoryObservation
+ observation, repoErr = backup.CheckRemoteRepository(ctx, s.s3Destinations, destinationID, "arcane-system-recovery")
+ switch {
+ case repoErr != nil:
+ case !observation.Available:
+ // Nothing remains to forget; drop the references so the run can be removed.
+ slog.WarnContext(ctx, "S3 repository is missing; dropping remote snapshot references", "destinationId", destinationID, "snapshots", len(snapshotIDs))
+ default:
+ repoErr = s.engine.ForgetSnapshots(ctx, dockerClient, repository, key, snapshotIDs)
+ }
}
if repoErr != nil {
return fmt.Errorf("failed to delete S3 snapshots: %w", repoErr)
diff --git a/backend/internal/volume/children/backup/service.go b/backend/internal/volume/children/backup/service.go
index e72511b83..69847cabd 100644
--- a/backend/internal/volume/children/backup/service.go
+++ b/backend/internal/volume/children/backup/service.go
@@ -794,7 +794,21 @@ func (s *Service) forgetRemoteSnapshotsInternal(ctx context.Context, dockerClien
}
repository, repoErr := s.remoteRusticRepositoryForInstanceInternal(ctx, destinationID, instanceID)
if repoErr == nil {
- repoErr = s.forgetSnapshotsInternal(ctx, dockerClient, repository, snapshotIDs)
+ // Mirror remoteRusticRepositoryForInstanceInternal so the check targets the Rustic root.
+ root := instanceID
+ if strings.TrimSpace(root) == "" {
+ root = strings.TrimSpace(s.deps.Settings.GetSettingsConfig().InstanceID.Value)
+ }
+ var observation backuptypes.RepositoryObservation
+ observation, repoErr = backup.CheckRemoteRepository(ctx, s.deps.S3Destinations, destinationID, path.Join("arcane-volume-backups", root))
+ switch {
+ case repoErr != nil:
+ case !observation.Available:
+ // Nothing remains to forget; drop the references so the entry can be removed.
+ slog.WarnContext(ctx, "S3 repository is missing; dropping remote snapshot references", "destinationId", destinationID, "snapshots", len(snapshotIDs))
+ default:
+ repoErr = s.forgetSnapshotsInternal(ctx, dockerClient, repository, snapshotIDs)
+ }
}
if repoErr != nil {
return fmt.Errorf("failed to delete S3 Rustic snapshots: %w", repoErr)