Skip to content

Modern Docker Management, Designed for Everyone

fix: skip local Rustic prune when no local backups exist (#4584)

Kyle Mendell1a890180d839
diff --git a/backend/internal/system/children/backup/service.go b/backend/internal/system/children/backup/service.go
index d0a57b5d6..81f7f8c91 100644
--- a/backend/internal/system/children/backup/service.go
+++ b/backend/internal/system/children/backup/service.go
@@ -82,6 +82,7 @@ type Store struct {
LatestPolicyRun func(ctx context.Context, policyID string) (*backuptypes.SystemBackupRun, error)
RemoteSnapshotIDs func(ctx context.Context, destinationID string) ([]string, error)
CountRuns func(ctx context.Context) (int64, error)
+ CountLocalRuns func(ctx context.Context) (int64, error)
CountVolumeRepositoryRuns func(ctx context.Context) (int64, error)
CountRunningVolumeBackups func(ctx context.Context) (int64, error)
Policies func(ctx context.Context) ([]backuptypes.SystemBackupPolicy, error)
@@ -901,7 +902,12 @@ func (s *Service) deleteRuns(ctx context.Context, backupRuns []*backuptypes.Syst
}
// PruneLocalRepository frees the data of deleted local system backups once Rustic's keep-delete window passes.
+// Without local backups there is nothing worth pruning, so no Rustic helper, image, or volume is created.
func (s *Service) PruneLocalRepository(ctx context.Context) error {
+ localBackups, err := s.store.CountLocalRuns(ctx)
+ if err != nil || localBackups == 0 {
+ return err
+ }
key, err := s.recoveryKeys.Get(ctx)
if errors.Is(err, backup.ErrRecoveryKeyNotConfigured) {
return nil
diff --git a/backend/internal/system/service.go b/backend/internal/system/service.go
index 8f2c6a9de..b117fbb93 100644
--- a/backend/internal/system/service.go
+++ b/backend/internal/system/service.go
@@ -611,6 +611,11 @@ func (s *SystemService) backupStore(s3Destinations *s3.S3DestinationService) sys
err := s.db.WithContext(ctx).Model(&SystemBackupRun{}).Count(&count).Error
return count, err
},
+ CountLocalRuns: func(ctx context.Context) (int64, error) {
+ var count int64
+ err := s.db.WithContext(ctx).Model(&SystemBackupRun{}).Where("local_snapshot_id <> ''").Count(&count).Error
+ return count, err
+ },
CountVolumeRepositoryRuns: func(ctx context.Context) (int64, error) {
var count int64
err := s.db.WithContext(ctx).Model(&volume.VolumeBackup{}).Where("format = ?", volume.VolumeBackupFormatRustic).Count(&count).Error
diff --git a/backend/internal/volume/children/backup/service.go b/backend/internal/volume/children/backup/service.go
index 173ab38bf..bdf17248e 100644
--- a/backend/internal/volume/children/backup/service.go
+++ b/backend/internal/volume/children/backup/service.go
@@ -61,6 +61,7 @@ type Store struct {
Latest func(ctx context.Context, policyID string) (*volume.Backup, error)
List func(ctx context.Context, volumeName string, params pagination.QueryParams) ([]volume.Backup, int64, error)
RemoteSnapshotIDs func(ctx context.Context, destinationID string) ([]string, error)
+ CountLocal func(ctx context.Context) (int64, error)
}
// Dependencies are the persistence, runtime, and helper-container operations volume backups use.
@@ -692,7 +693,12 @@ func (s *Service) deleteRusticBackups(ctx context.Context, entries []*volume.Bac
}
// PruneLocalRepository frees the data of deleted local volume backups once Rustic's keep-delete window passes.
+// Without local backups there is nothing worth pruning, so no Rustic helper, image, or volume is created.
func (s *Service) PruneLocalRepository(ctx context.Context) error {
+ localBackups, err := s.deps.Store.CountLocal(ctx)
+ if err != nil || localBackups == 0 {
+ return err
+ }
dockerClient, err := s.deps.Docker.GetClient(ctx)
if err != nil {
return err
diff --git a/backend/internal/volume/service.go b/backend/internal/volume/service.go
index 34d7097da..466caacb3 100644
--- a/backend/internal/volume/service.go
+++ b/backend/internal/volume/service.go
@@ -280,6 +280,11 @@ func (s *VolumeService) backupStore() volumebackup.Store {
Pluck("remote_snapshot_id", &knownIDs).Error
return knownIDs, err
},
+ CountLocal: func(ctx context.Context) (int64, error) {
+ var count int64
+ err := s.db.WithContext(ctx).Model(&VolumeBackup{}).Where("local_snapshot_id <> ''").Count(&count).Error
+ return count, err
+ },
}
}