Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
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.goindex 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 nildiff --git a/backend/internal/system/service.go b/backend/internal/system/service.goindex 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) syserr := s.db.WithContext(ctx).Model(&SystemBackupRun{}).Count(&count).Errorreturn 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 int64err := s.db.WithContext(ctx).Model(&volume.VolumeBackup{}).Where("format = ?", volume.VolumeBackupFormatRustic).Count(&count).Errordiff --git a/backend/internal/volume/children/backup/service.go b/backend/internal/volume/children/backup/service.goindex 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 errdiff --git a/backend/internal/volume/service.go b/backend/internal/volume/service.goindex 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).Errorreturn 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+ },}}