Log changed files after backup
This commit is contained in:
@@ -586,6 +586,11 @@ func (s *Service) executeBackup(ctx context.Context, run model.Run) (result mode
|
||||
result.Status, result.ErrorCode, result.Message = "warning", "connectivity", result.Message+"; repository unmount failed: "+err.Error()
|
||||
}
|
||||
}()
|
||||
previousSnapshot, previousSnapshotOK, previousSnapshotErr := s.latestJobSnapshot(ctx, mounted.Repository, job.ID)
|
||||
if previousSnapshotErr != nil {
|
||||
appendLiveLog(&live, "Änderungsliste: vorheriger Snapshot konnte nicht ermittelt werden: "+previousSnapshotErr.Error())
|
||||
s.updateActive(live)
|
||||
}
|
||||
prepared, err := s.workloads.Prepare(ctx, job)
|
||||
if err != nil {
|
||||
return failedError(run, err)
|
||||
@@ -671,6 +676,10 @@ func (s *Service) executeBackup(ctx context.Context, run model.Run) (result mode
|
||||
failedRun.LiveLog = live.LiveLog
|
||||
return failedRun
|
||||
}
|
||||
if previousSnapshotOK && summary.SnapshotID != "" {
|
||||
s.appendBackupDiffLog(ctx, &live, mounted.Repository, previousSnapshot, summary.SnapshotID)
|
||||
s.updateActive(live)
|
||||
}
|
||||
appendLiveLog(&live, "Backup-Daten übertragen; Aufbewahrung wird angewendet")
|
||||
s.updateActive(live)
|
||||
if err := s.restic.Forget(ctx, mounted.Repository, job); err != nil {
|
||||
@@ -692,6 +701,69 @@ func (s *Service) executeBackup(ctx context.Context, run model.Run) (result mode
|
||||
return run
|
||||
}
|
||||
|
||||
func (s *Service) latestJobSnapshot(ctx context.Context, repo model.Repository, jobID string) (model.Snapshot, bool, error) {
|
||||
snapshots, err := s.restic.Snapshots(ctx, repo)
|
||||
if err != nil {
|
||||
return model.Snapshot{}, false, err
|
||||
}
|
||||
tag := "job:" + jobID
|
||||
var latest model.Snapshot
|
||||
found := false
|
||||
for _, snapshot := range snapshots {
|
||||
if !hasTag(snapshot.Tags, tag) || hasTag(snapshot.Tags, "usb-image") {
|
||||
continue
|
||||
}
|
||||
if !found || snapshot.Time.After(latest.Time) {
|
||||
latest = snapshot
|
||||
found = true
|
||||
}
|
||||
}
|
||||
return latest, found, nil
|
||||
}
|
||||
|
||||
func hasTag(tags []string, wanted string) bool {
|
||||
for _, tag := range tags {
|
||||
if tag == wanted {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Service) appendBackupDiffLog(ctx context.Context, run *model.Run, repo model.Repository, previous model.Snapshot, currentSnapshotID string) {
|
||||
const limit = 50
|
||||
diff, err := s.restic.Diff(ctx, repo, previous.ID, currentSnapshotID, limit)
|
||||
if err != nil {
|
||||
appendLiveLog(run, "Änderungsliste konnte nicht erstellt werden: "+err.Error())
|
||||
return
|
||||
}
|
||||
if diff.Total == 0 {
|
||||
appendLiveLog(run, "Änderungsliste gegenüber "+shortID(previous.ID)+": keine geänderten Pfade erkannt")
|
||||
return
|
||||
}
|
||||
if diff.Total > len(diff.Entries) {
|
||||
appendLiveLog(run, fmt.Sprintf("Änderungsliste gegenüber %s: letzte %d von %d geänderten Pfaden", shortID(previous.ID), len(diff.Entries), diff.Total))
|
||||
} else {
|
||||
appendLiveLog(run, fmt.Sprintf("Änderungsliste gegenüber %s: %d geänderte Pfade", shortID(previous.ID), diff.Total))
|
||||
}
|
||||
for _, entry := range diff.Entries {
|
||||
appendLiveLog(run, fmt.Sprintf("%s %s", diffKindLabel(entry.Kind), entry.Path))
|
||||
}
|
||||
}
|
||||
|
||||
func diffKindLabel(kind string) string {
|
||||
switch kind {
|
||||
case "new":
|
||||
return "NEU"
|
||||
case "removed":
|
||||
return "GELÖSCHT"
|
||||
case "modified":
|
||||
return "GEÄNDERT"
|
||||
default:
|
||||
return strings.ToUpper(kind)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) updateActive(run model.Run) {
|
||||
s.queue.UpdateActive(run.ID, func(active *model.Run) {
|
||||
active.ProgressPercent, active.ProgressBytes, active.ProgressTotal = run.ProgressPercent, run.ProgressBytes, run.ProgressTotal
|
||||
|
||||
Reference in New Issue
Block a user