Add scheduled rsync copy jobs

This commit is contained in:
Mikei386
2026-06-15 17:15:27 +02:00
parent 2abfc8eb26
commit 6c795fd97d
15 changed files with 524 additions and 59 deletions
+43 -18
View File
@@ -1,6 +1,9 @@
package model
import "time"
import (
"strings"
"time"
)
const SchemaVersion = 1
@@ -12,6 +15,7 @@ const (
JobDocker JobType = "docker"
JobVM JobType = "vm"
JobFlash JobType = "flash"
JobRsync JobType = "rsync"
)
type RepositoryType string
@@ -33,6 +37,7 @@ type Config struct {
type Settings struct {
ResticPath string `json:"resticPath"`
RsyncPath string `json:"rsyncPath"`
RestoreRoot string `json:"restoreRoot"`
PersistentLogDir string `json:"persistentLogDir,omitempty"`
ShowLiveLog bool `json:"showLiveLog"`
@@ -42,23 +47,39 @@ type Settings struct {
}
type Job struct {
SchemaVersion int `json:"schemaVersion"`
ID string `json:"id"`
Name string `json:"name"`
Type JobType `json:"type"`
Enabled bool `json:"enabled"`
RepositoryID string `json:"repositoryId"`
Sources []Source `json:"sources"`
Schedule Schedule `json:"schedule"`
Consistency Consistency `json:"consistency"`
Compression string `json:"compression"`
CPUCores int `json:"cpuCores,omitempty"`
Excludes []string `json:"excludes,omitempty"`
Tags []string `json:"tags,omitempty"`
FlashImage bool `json:"flashImage,omitempty"`
Retention Retention `json:"retention"`
NotifyOn []string `json:"notifyOn,omitempty"`
ShutdownSecs int `json:"shutdownTimeoutSeconds"`
SchemaVersion int `json:"schemaVersion"`
ID string `json:"id"`
Name string `json:"name"`
Type JobType `json:"type"`
Enabled bool `json:"enabled"`
RepositoryID string `json:"repositoryId"`
Sources []Source `json:"sources"`
Schedule Schedule `json:"schedule"`
Consistency Consistency `json:"consistency"`
Compression string `json:"compression"`
CPUCores int `json:"cpuCores,omitempty"`
Excludes []string `json:"excludes,omitempty"`
Tags []string `json:"tags,omitempty"`
FlashImage bool `json:"flashImage,omitempty"`
Retention Retention `json:"retention"`
NotifyOn []string `json:"notifyOn,omitempty"`
ShutdownSecs int `json:"shutdownTimeoutSeconds"`
Rsync RsyncOptions `json:"rsync,omitempty"`
}
type RsyncOptions struct {
Target string `json:"target"`
Overwrite bool `json:"overwrite"`
Delete bool `json:"delete"`
PreservePermissions bool `json:"preservePermissions"`
PreserveOwner bool `json:"preserveOwner"`
PreserveGroup bool `json:"preserveGroup"`
PreserveTimes bool `json:"preserveTimes"`
PreserveLinks bool `json:"preserveLinks"`
PreserveACLs bool `json:"preserveAcls"`
PreserveXattrs bool `json:"preserveXattrs"`
Checksum bool `json:"checksum"`
DryRun bool `json:"dryRun"`
}
type Source struct {
@@ -180,6 +201,7 @@ func DefaultConfig() Config {
Notifications: []NotificationTarget{{SchemaVersion: SchemaVersion, ID: "unraid", Name: "Unraid", Type: "unraid", Enabled: true, Events: []string{"success", "warning", "failed"}}},
Settings: Settings{
ResticPath: "/usr/local/libexec/urbm/restic",
RsyncPath: "/usr/bin/rsync",
RestoreRoot: "/mnt/user/urbm-restores",
CatchUpWindowHrs: 24,
CheckCron: "0 3 1 * *",
@@ -189,6 +211,9 @@ func DefaultConfig() Config {
}
func NormalizeConfig(c Config) Config {
if strings.TrimSpace(c.Settings.RsyncPath) == "" {
c.Settings.RsyncPath = "/usr/bin/rsync"
}
notifications := make([]NotificationTarget, 0, len(c.Notifications)+1)
hasUnraid := false
for _, target := range c.Notifications {