Check rsync destination capacity before copying

This commit is contained in:
Mikei386
2026-06-15 17:20:07 +02:00
parent 6c795fd97d
commit e66d89598d
10 changed files with 110 additions and 9 deletions
+26
View File
@@ -11,6 +11,7 @@ import (
"path/filepath"
"strings"
"sync"
"syscall"
"time"
"git.casaderoll.de/michael/urbm/internal/model"
@@ -402,6 +403,23 @@ func (s *Service) executeRsync(ctx context.Context, run model.Run) (result model
}
return failed(run, "environment", "rsync target unavailable: "+err.Error())
}
if !job.Rsync.DryRun && !job.Rsync.SkipSpaceCheck {
appendLiveLog(&live, "Rsync-Vorabprüfung ermittelt den tatsächlich zu übertragenden Datenumfang")
s.updateActive(live)
estimate, err := s.rsync.Estimate(ctx, run.ID, job)
if err != nil {
return failedError(run, err)
}
available, err := availableBytes(job.Rsync.Target)
if err != nil {
return failed(run, "environment", "read rsync target capacity: "+err.Error())
}
appendLiveLog(&live, fmt.Sprintf("Rsync-Vorabprüfung: %s zu übertragen, %s am Ziel frei", formatBytes(estimate.Bytes), formatBytes(available)))
s.updateActive(live)
if estimate.Bytes > available {
return failed(run, "environment", fmt.Sprintf("Rsync-Ziel hat nicht genügend freien Speicher: ungefähr %s für %d Dateien erforderlich, aber nur %s frei unter %s", formatBytes(estimate.Bytes), estimate.Files, formatBytes(available), job.Rsync.Target))
}
}
started := time.Now()
lastLoggedPercent := -10
summary, err := s.rsync.Run(ctx, run.ID, job, func(progress rsync.Progress) {
@@ -442,6 +460,14 @@ func (s *Service) executeRsync(ctx context.Context, run model.Run) (result model
return run
}
func availableBytes(path string) (int64, error) {
var stats syscall.Statfs_t
if err := syscall.Statfs(path, &stats); err != nil {
return 0, err
}
return int64(stats.Bavail) * int64(stats.Bsize), nil
}
func (s *Service) executeBackup(ctx context.Context, run model.Run) (result model.Run) {
job, ok := s.job(run.JobID)
if !ok {