Add per-job backup retention
This commit is contained in:
@@ -74,9 +74,10 @@ type Consistency struct {
|
||||
}
|
||||
|
||||
type Retention struct {
|
||||
Daily int `json:"daily"`
|
||||
Weekly int `json:"weekly"`
|
||||
Monthly int `json:"monthly"`
|
||||
KeepWithinDays int `json:"keepWithinDays,omitempty"`
|
||||
Daily int `json:"daily"`
|
||||
Weekly int `json:"weekly"`
|
||||
Monthly int `json:"monthly"`
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
|
||||
@@ -87,9 +87,12 @@ func ValidateJob(j Job) error {
|
||||
if j.Consistency.Mode != "live" && j.Consistency.Mode != "stop" {
|
||||
return errors.New("consistency mode must be live or stop")
|
||||
}
|
||||
if j.Retention.Daily < 0 || j.Retention.Weekly < 0 || j.Retention.Monthly < 0 {
|
||||
if j.Retention.KeepWithinDays < 0 || j.Retention.Daily < 0 || j.Retention.Weekly < 0 || j.Retention.Monthly < 0 {
|
||||
return errors.New("retention values cannot be negative")
|
||||
}
|
||||
if j.Retention.KeepWithinDays == 0 && j.Retention.Daily == 0 && j.Retention.Weekly == 0 && j.Retention.Monthly == 0 {
|
||||
return errors.New("retention must keep at least one age or calendar policy")
|
||||
}
|
||||
for _, exclude := range j.Excludes {
|
||||
if strings.ContainsAny(exclude, "\x00\r\n") {
|
||||
return errors.New("exclude contains forbidden control characters")
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestRepositoryCannotBeSharedByJobs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDockerJobRequiresWorkloadSources(t *testing.T) {
|
||||
job := Job{SchemaVersion: 1, ID: "docker-job", Name: "Docker", Type: JobDocker, RepositoryID: "repo", Sources: []Source{{Path: "/mnt/user/appdata"}}, Consistency: Consistency{Mode: "live"}, Compression: "auto"}
|
||||
job := Job{SchemaVersion: 1, ID: "docker-job", Name: "Docker", Type: JobDocker, RepositoryID: "repo", Sources: []Source{{Path: "/mnt/user/appdata"}}, Consistency: Consistency{Mode: "live"}, Compression: "auto", Retention: Retention{KeepWithinDays: 30}}
|
||||
if err := ValidateJob(job); err == nil {
|
||||
t.Fatal("docker path source accepted without workload selection")
|
||||
}
|
||||
@@ -45,3 +45,14 @@ func TestDockerJobRequiresWorkloadSources(t *testing.T) {
|
||||
t.Fatalf("valid docker workload rejected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetentionRequiresAtLeastOneRule(t *testing.T) {
|
||||
job := Job{SchemaVersion: 1, ID: "job", Name: "Share", Type: JobShare, RepositoryID: "repo", Sources: []Source{{Path: "/mnt/user/data"}}, Consistency: Consistency{Mode: "live"}, Compression: "auto"}
|
||||
if err := ValidateJob(job); err == nil {
|
||||
t.Fatal("empty retention policy accepted")
|
||||
}
|
||||
job.Retention.KeepWithinDays = 30
|
||||
if err := ValidateJob(job); err != nil {
|
||||
t.Fatalf("age retention rejected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user