Files

98 lines
3.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package service
import (
"fmt"
"strings"
"git.casaderoll.de/michael/urbm/internal/model"
"git.casaderoll.de/michael/urbm/internal/rsync"
)
func logRsyncSetup(run *model.Run, job model.Job) {
mode := "Kopierlauf – Änderungen am Ziel werden ausgeführt"
if job.Rsync.DryRun {
mode = "Testlauf – es werden keine Dateien geschrieben oder gelöscht"
}
appendLiveLog(run, "Rsync: "+mode)
for _, source := range job.Sources {
appendLiveLog(run, "Quelle: "+source.Path)
}
appendLiveLog(run, "Ziel: "+job.Rsync.Target)
overwrite := "vorhandene Dateien überspringen"
if job.Rsync.Overwrite {
overwrite = "abweichende vorhandene Dateien aktualisieren"
}
deletion := "aus"
if job.Rsync.Delete {
deletion = "an (zusätzliche Einträge im Ziel entfernen)"
}
comparison := "Dateigröße und Änderungszeit"
if job.Rsync.Checksum {
comparison = "Dateiinhalt per Prüfsumme (liest Dateien vollständig)"
}
appendLiveLog(run, "Vorhandene Dateien: "+overwrite+"; Löschen: "+deletion)
appendLiveLog(run, "Vergleich: "+comparison)
var preserve []string
for _, option := range []struct {
enabled bool
label string
}{
{job.Rsync.PreserveTimes, "Zeitstempel"}, {job.Rsync.PreservePermissions, "Berechtigungen"},
{job.Rsync.PreserveOwner, "Besitzer"}, {job.Rsync.PreserveGroup, "Gruppe"},
{job.Rsync.PreserveLinks, "Symlinks"}, {job.Rsync.PreserveACLs, "ACLs"}, {job.Rsync.PreserveXattrs, "erweiterte Attribute"},
} {
if option.enabled {
preserve = append(preserve, option.label)
}
}
if len(preserve) > 0 {
appendLiveLog(run, "Übernehmen: "+strings.Join(preserve, ", "))
}
appendLiveLog(run, fmt.Sprintf("Ausschlussmuster: %d", len(job.Excludes)))
for index, pattern := range job.Excludes {
if index == 10 {
appendLiveLog(run, "Weitere Ausschlussmuster siehe Job-Konfiguration")
break
}
appendLiveLog(run, "Ausschluss: "+pattern)
}
}
func rsyncChangeLabel(code string) string {
if strings.HasPrefix(code, "*deleting") {
return "Löschen"
}
if len(code) != 11 {
return "Änderung"
}
if code[2:] == "+++++++++" {
return "Neu"
}
if code[0] == '.' {
return "Metadaten ändern"
}
return "Aktualisieren"
}
func applyRsyncSummary(run *model.Run, summary rsync.Summary) {
run.Status, run.Message = "success", "rsync completed"
run.BytesProcessed, run.FilesProcessed = summary.Bytes, summary.Files
run.EntriesDeleted = summary.Deleted
run.BytesAdded = summary.Bytes
if run.RsyncDryRun {
run.BytesAdded = 0
run.Message = "Rsync-Testlauf erfolgreich – keine Änderungen vorgenommen"
}
// Rsync's transferred-file count combines new and updated regular files.
run.FilesNew, run.FilesChanged = 0, 0
}
func logRsyncSummary(run *model.Run, summary rsync.Summary) {
if run.RsyncDryRun {
appendLiveLog(run, fmt.Sprintf("Testlauf: %d Dateien würden kopiert/aktualisiert (%s Dateiinhalt); %d Einträge würden gelöscht (inkl. Ordner/Symlinks)", summary.Files, formatBytes(summary.Bytes), summary.Deleted))
appendLiveLog(run, "Testlauf erfolgreich – keine Änderungen vorgenommen")
} else {
appendLiveLog(run, fmt.Sprintf("Rsync abgeschlossen: %d Dateien kopiert/aktualisiert (%s Dateiinhalt); %d Einträge gelöscht (inkl. Ordner/Symlinks)", summary.Files, formatBytes(summary.Bytes), summary.Deleted))
}
}