fdecde0d5c
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>
199 lines
12 KiB
HTML
199 lines
12 KiB
HTML
{{define "title"}}{{.Title}}{{end}}
|
|
|
|
{{define "content"}}
|
|
{{$page := .Page}}
|
|
{{$host := $page.Host}}
|
|
<div class="max-w-[1280px] mx-auto px-8 pt-9 pb-24">
|
|
|
|
<div class="crumbs">
|
|
<a href="/">Dashboard</a><span class="sep">/</span>
|
|
<a href="/hosts/{{$host.ID}}">{{$host.Name}}</a><span class="sep">/</span>
|
|
<a href="/hosts/{{$host.ID}}/schedules">schedules</a><span class="sep">/</span>
|
|
<span class="text-ink-mid">{{if $page.IsNew}}new{{else}}edit{{end}}</span>
|
|
</div>
|
|
|
|
<h1 class="text-2xl font-medium tracking-[-0.012em] mt-2.5">
|
|
{{if $page.IsNew}}New schedule{{else}}Edit schedule{{end}}
|
|
<span class="text-ink-fade">·</span>
|
|
<span class="mono text-ink">{{$host.Name}}</span>
|
|
</h1>
|
|
<p class="text-pretty text-ink-mute text-[13px] mt-1.5 max-w-[640px]">
|
|
Backups run on the cron expression below. The agent applies whatever the server most
|
|
recently pushed; an offline agent catches up on the next reconnect.
|
|
</p>
|
|
|
|
{{if $page.Error}}
|
|
<div class="mt-6 px-4 py-3 rounded-[5px] text-[13px]"
|
|
style="background: color-mix(in oklch, var(--bad), transparent 88%);
|
|
border: 1px solid color-mix(in oklch, var(--bad), transparent 70%);
|
|
color: oklch(0.85 0.10 25);">
|
|
{{$page.Error}}
|
|
</div>
|
|
{{end}}
|
|
|
|
<form method="post"
|
|
action="{{if $page.IsNew}}/hosts/{{$host.ID}}/schedules/new{{else}}/hosts/{{$host.ID}}/schedules/{{$page.ScheduleID}}/edit{{end}}"
|
|
class="grid grid-cols-12 gap-8 mt-7">
|
|
|
|
<div class="col-span-7 panel rounded-[7px] px-8 py-7">
|
|
|
|
<h3 class="text-[13px] font-semibold uppercase tracking-[0.08em] text-ink-mute mb-4">Kind</h3>
|
|
<div class="mb-7">
|
|
{{if $page.IsNew}}
|
|
<label class="field-label" for="se-kind">What does this schedule do?</label>
|
|
<select id="se-kind" name="kind" class="field mono"
|
|
onchange="document.querySelectorAll('[data-kind]').forEach(el => { el.style.display = el.dataset.kind === this.value ? '' : 'none'; });">
|
|
<option value="backup" {{if eq $page.Kind "backup"}}selected{{end}}>backup — snapshot the configured paths</option>
|
|
<option value="forget" {{if eq $page.Kind "forget"}}selected{{end}}>forget — apply retention policy (rewrite the snapshot index)</option>
|
|
</select>
|
|
<div class="field-help">
|
|
<span class="mono text-ink-mid">backup</span> reads files and writes a snapshot.
|
|
<span class="mono text-ink-mid">forget</span> trims the index by your <strong>Keep-*</strong> rules without deleting data —
|
|
an admin-only <span class="mono text-ink-mid">prune</span> job (P2-06) reclaims the disk space later.
|
|
Other kinds (<span class="mono text-ink-mid">prune</span>, <span class="mono text-ink-mid">check</span>, <span class="mono text-ink-mid">unlock</span>) land in P2-06..08.
|
|
</div>
|
|
{{else}}
|
|
<input type="hidden" name="kind" value="{{$page.Kind}}">
|
|
<div class="text-[13px] text-ink-mid">
|
|
Kind: <span class="mono text-ink">{{$page.Kind}}</span>
|
|
<span class="text-ink-fade">— immutable on edit; delete and recreate to switch kind.</span>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
|
|
<h3 class="text-[13px] font-semibold uppercase tracking-[0.08em] text-ink-mute mb-4 pt-6 border-t border-line-soft">When</h3>
|
|
|
|
<div class="mb-5">
|
|
<label class="flex items-center gap-2.5 cursor-pointer text-[13px]">
|
|
<input id="se-manual" type="checkbox" name="manual" {{if $page.Manual}}checked{{end}}
|
|
onchange="document.getElementById('se-cron-block').style.display=this.checked?'none':'';">
|
|
<span>Manual schedule <span class="text-ink-fade font-normal">— no cron, only fires when you click Run-now</span></span>
|
|
</label>
|
|
</div>
|
|
|
|
<div id="se-cron-block" class="mb-5" {{if $page.Manual}}style="display: none;"{{end}}>
|
|
<label class="field-label" for="se-cron">Cron expression</label>
|
|
<input id="se-cron" name="cron_expr" type="text" class="field mono" value="{{$page.CronExpr}}">
|
|
<div class="field-help">
|
|
Standard 5-field cron with descriptors. Examples:
|
|
<span class="mono text-ink-mid">0 3 * * *</span> (daily 03:00),
|
|
<span class="mono text-ink-mid">@hourly</span>,
|
|
<span class="mono text-ink-mid">*/30 * * * *</span> (every 30 min).
|
|
Server validates with the same parser the agent uses to fire.
|
|
</div>
|
|
<div class="flex flex-wrap gap-1.5 mt-2.5">
|
|
{{range $cron := list "0 3 * * *" "0 */6 * * *" "@hourly" "0 3 * * 0" "0 3 1 * *"}}
|
|
<button type="button" class="btn btn-ghost mono text-[11px]"
|
|
onclick="document.getElementById('se-cron').value='{{$cron}}'">{{$cron}}</button>
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
|
|
<div data-kind="backup" {{if ne $page.Kind "backup"}}style="display: none;"{{end}}>
|
|
<h3 class="text-[13px] font-semibold uppercase tracking-[0.08em] text-ink-mute mb-4 pt-6 border-t border-line-soft">Paths</h3>
|
|
<div class="mb-5">
|
|
<label class="field-label" for="se-paths">Backup paths <span class="text-ink-fade font-normal">· one per line</span></label>
|
|
<textarea id="se-paths" name="paths" rows="4" class="field mono"
|
|
style="resize: vertical;"
|
|
placeholder="/etc /home /var/lib/postgresql">{{$page.PathsRaw}}</textarea>
|
|
<div class="field-help">What <span class="mono text-ink-mid">restic backup</span> walks. The agent runs as root with <span class="mono text-ink-mid">CAP_DAC_READ_SEARCH</span>, so any readable path is fair game.</div>
|
|
</div>
|
|
<div class="mb-7">
|
|
<label class="field-label" for="se-excludes">Excludes <span class="text-ink-fade font-normal">· optional, one per line</span></label>
|
|
<textarea id="se-excludes" name="excludes" rows="3" class="field mono"
|
|
style="resize: vertical;"
|
|
placeholder="*.tmp node_modules .cache">{{$page.ExcludesRaw}}</textarea>
|
|
<div class="field-help">Passed straight through as <span class="mono text-ink-mid">--exclude</span> args.</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 class="text-[13px] font-semibold uppercase tracking-[0.08em] text-ink-mute mb-4 pt-6 border-t border-line-soft">Tags <span class="text-ink-fade font-normal">· optional</span></h3>
|
|
<div class="mb-7">
|
|
<label class="field-label" for="se-tags">Tags <span class="text-ink-fade font-normal">· comma-separated</span></label>
|
|
<input id="se-tags" name="tags" type="text" class="field mono" placeholder="nightly, prod" value="{{$page.TagsRaw}}">
|
|
<div class="field-help">Attached to every snapshot this schedule produces. Useful for retention rules (P2-05).</div>
|
|
</div>
|
|
|
|
<h3 class="text-[13px] font-semibold uppercase tracking-[0.08em] text-ink-mute mb-4 pt-6 border-t border-line-soft">Retention <span class="text-ink-fade font-normal">· optional, all blank = keep everything</span></h3>
|
|
<div class="grid grid-cols-3 gap-4 mb-7">
|
|
<div>
|
|
<label class="field-label" for="se-keep-last">Keep last</label>
|
|
<input id="se-keep-last" name="keep_last" type="number" min="0" class="field mono" value="{{$page.KeepLast}}">
|
|
</div>
|
|
<div>
|
|
<label class="field-label" for="se-keep-hourly">Keep hourly</label>
|
|
<input id="se-keep-hourly" name="keep_hourly" type="number" min="0" class="field mono" value="{{$page.KeepHourly}}">
|
|
</div>
|
|
<div>
|
|
<label class="field-label" for="se-keep-daily">Keep daily</label>
|
|
<input id="se-keep-daily" name="keep_daily" type="number" min="0" class="field mono" value="{{$page.KeepDaily}}">
|
|
</div>
|
|
<div>
|
|
<label class="field-label" for="se-keep-weekly">Keep weekly</label>
|
|
<input id="se-keep-weekly" name="keep_weekly" type="number" min="0" class="field mono" value="{{$page.KeepWeekly}}">
|
|
</div>
|
|
<div>
|
|
<label class="field-label" for="se-keep-monthly">Keep monthly</label>
|
|
<input id="se-keep-monthly" name="keep_monthly" type="number" min="0" class="field mono" value="{{$page.KeepMonthly}}">
|
|
</div>
|
|
<div>
|
|
<label class="field-label" for="se-keep-yearly">Keep yearly</label>
|
|
<input id="se-keep-yearly" name="keep_yearly" type="number" min="0" class="field mono" value="{{$page.KeepYearly}}">
|
|
</div>
|
|
</div>
|
|
<div class="text-[12px] text-ink-mute leading-[1.55] mb-7">
|
|
Applied by <span class="mono text-ink-mid">restic forget</span> when the prune job kind lands in P2-05. Mirrors restic's <span class="mono text-ink-mid">--keep-*</span> flags one-for-one.
|
|
</div>
|
|
|
|
<h3 class="text-[13px] font-semibold uppercase tracking-[0.08em] text-ink-mute mb-4 pt-6 border-t border-line-soft">Bandwidth <span class="text-ink-fade font-normal">· optional</span></h3>
|
|
<div class="grid grid-cols-2 gap-4 mb-7">
|
|
<div>
|
|
<label class="field-label" for="se-up">Limit upload <span class="text-ink-fade font-normal">· KB/s</span></label>
|
|
<input id="se-up" name="limit_up_kbps" type="number" min="0" class="field mono" value="{{$page.LimitUpKBps}}">
|
|
</div>
|
|
<div>
|
|
<label class="field-label" for="se-down">Limit download <span class="text-ink-fade font-normal">· KB/s</span></label>
|
|
<input id="se-down" name="limit_down_kbps" type="number" min="0" class="field mono" value="{{$page.LimitDownKBps}}">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="pt-6 border-t border-line-soft">
|
|
<label class="flex items-center gap-2.5 cursor-pointer text-[13px]">
|
|
<input type="checkbox" name="enabled" {{if $page.Enabled}}checked{{end}}>
|
|
<span>Enabled</span>
|
|
<span class="text-ink-fade">— uncheck to keep the row but stop it from firing.</span>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="flex gap-2 pt-7">
|
|
<button type="submit" class="btn btn-primary btn-lg">{{if $page.IsNew}}Create schedule{{else}}Save changes{{end}}</button>
|
|
<a href="/hosts/{{$host.ID}}/schedules" class="btn btn-lg">Cancel</a>
|
|
</div>
|
|
</div>
|
|
|
|
<aside class="col-span-5">
|
|
<div class="text-[11px] uppercase tracking-[0.1em] text-ink-fade mb-3">How this works</div>
|
|
<ol class="list-none p-0 m-0 space-y-4">
|
|
<li class="relative pl-9">
|
|
<span class="absolute left-0 top-0 w-[22px] h-[22px] border border-line rounded-full text-[11px] leading-[20px] text-center text-ink-mute mono">1</span>
|
|
<div class="text-[13px] text-ink font-medium">Server is the source of truth</div>
|
|
<div class="text-[12px] text-ink-mute mt-1 leading-[1.55]">Saving here bumps <span class="mono text-ink-mid">host_schedule_version</span> and pushes the new set to the agent over WS. Offline agents catch up on reconnect.</div>
|
|
</li>
|
|
<li class="relative pl-9">
|
|
<span class="absolute left-0 top-0 w-[22px] h-[22px] border border-line rounded-full text-[11px] leading-[20px] text-center text-ink-mute mono">2</span>
|
|
<div class="text-[13px] text-ink font-medium">Agent fires locally</div>
|
|
<div class="text-[12px] text-ink-mute mt-1 leading-[1.55]">On each tick the agent sends <span class="mono text-ink-mid">schedule.fire</span>; the server creates a job row (<span class="mono text-ink-mid">actor_kind=schedule</span>) and ships <span class="mono text-ink-mid">command.run</span> back. Same job lifecycle as run-now.</div>
|
|
</li>
|
|
<li class="relative pl-9">
|
|
<span class="absolute left-0 top-0 w-[22px] h-[22px] border border-line rounded-full text-[11px] leading-[20px] text-center text-ink-mute mono">3</span>
|
|
<div class="text-[13px] text-ink font-medium">Missed ticks fire on reconnect</div>
|
|
<div class="text-[12px] text-ink-mute mt-1 leading-[1.55]">By design — the operator wants the missed backup to run, not be silently skipped because the agent was bouncing.</div>
|
|
</li>
|
|
</ol>
|
|
</aside>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
{{end}}
|