P2-05: forget command with retention policy
End-to-end forget plumbing — operator can create a forget schedule with keep-* values, agent runs restic forget --keep-* … on the schedule's cron (or via per-row Run-now), snapshot list shrinks, UI updates. * api.CommandRunPayload gains retention_policy json.RawMessage so the agent doesn't need a typed copy of the server-side struct. * restic.ForgetPolicy mirrors restic's --keep-* flags. Empty() reports zero dimensions; restic wrapper RunForget refuses to run an empty policy (would delete every snapshot). Does NOT pass --prune — pruning lives behind a separate admin-only credential (P2-06); forget just rewrites the snapshot index. * runner.RunForget mirrors RunBackup's envelope shape so the live log viewer works without special-casing. On success triggers reportSnapshots (forget shrinks the index, the host's snapshot count almost certainly changed). * cmd/agent dispatcher handles MsgCommandRun with kind=forget, decodes RetentionPolicy from the wire, builds restic.ForgetPolicy. * Server dispatchScheduleNow marshals the schedule's RetentionPolicy into the wire payload for kind=forget jobs. Refuses to dispatch a forget schedule with empty retention. * validateSchedule rejects kind=forget without at least one keep-* dimension (new error code: missing_retention). * UI schedule edit form gains a Kind dropdown (backup or forget; immutable on edit). Paths block toggles by kind via inline data-kind attributes. Form help-text explains the prune separation. Other kinds (prune, check, unlock) deferred to P2-06..08; the Kind dropdown only offers backup and forget today. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -279,6 +280,34 @@ func (d *dispatcher) runJob(ctx context.Context, p api.CommandRunPayload, tx wsc
|
||||
}
|
||||
slog.Info("agent: init job complete", "job_id", p.JobID)
|
||||
}()
|
||||
case api.JobForget:
|
||||
var policy restic.ForgetPolicy
|
||||
if len(p.RetentionPolicy) > 0 {
|
||||
var raw struct {
|
||||
KeepLast *int `json:"keep_last,omitempty"`
|
||||
KeepHourly *int `json:"keep_hourly,omitempty"`
|
||||
KeepDaily *int `json:"keep_daily,omitempty"`
|
||||
KeepWeekly *int `json:"keep_weekly,omitempty"`
|
||||
KeepMonthly *int `json:"keep_monthly,omitempty"`
|
||||
KeepYearly *int `json:"keep_yearly,omitempty"`
|
||||
}
|
||||
if err := json.Unmarshal(p.RetentionPolicy, &raw); err != nil {
|
||||
return fmt.Errorf("forget: decode retention_policy: %w", err)
|
||||
}
|
||||
policy = restic.ForgetPolicy{
|
||||
KeepLast: raw.KeepLast, KeepHourly: raw.KeepHourly,
|
||||
KeepDaily: raw.KeepDaily, KeepWeekly: raw.KeepWeekly,
|
||||
KeepMonthly: raw.KeepMonthly, KeepYearly: raw.KeepYearly,
|
||||
}
|
||||
}
|
||||
slog.Info("agent: accepting forget job", "job_id", p.JobID, "policy", p.RetentionPolicy)
|
||||
go func() {
|
||||
if err := r.RunForget(ctx, p.JobID, policy); err != nil {
|
||||
slog.Warn("agent: forget job failed", "job_id", p.JobID, "err", err)
|
||||
return
|
||||
}
|
||||
slog.Info("agent: forget job complete", "job_id", p.JobID)
|
||||
}()
|
||||
default:
|
||||
return fmt.Errorf("kind %q not implemented yet (Phase 2 lands the rest)", p.Kind)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user