v0.6.0-rc1: slice 6 Phase A — backup + the self-restore-test (local target)
The guest-level backup layer + the journaled self-restore-test (restore→boot→verify→ teardown) that closes "a backup you haven't restored isn't a backup". All benign (reuses the slice-4 classifier/gate/journal; no new destructive class/crypto). Local target only; PBS = Phase B. Restore to a NEW guest only. Backups crash-consistent. - proxmox: DestroyLXC, VzdumpOptions.Notes (notes-template), LatestBackupVolID. - reconcile: Engine.RunRestoreTest (journal Scratch entry BEFORE mutation; net link-down pre-boot; defer teardown always; benign gated destroy) + Recover extended to reap a leaked scratch guest (Scratch flag, special-cased before the UPID path; idempotent). - internal/backup: runner (vzdump + archive resolve + bulk-gap = backup!=1) + cadence scheduler (4th daemon goroutine, default 24h) + in-memory report store. - hub: Backup/RestoreTest filled; collector seams; cross-repo golden byte-identical + bidirectional key-set tests; hub handler logs a FAILED restore-test prominently. - config BackupConfig (band 990000-990009 default); --selftest=backup / restore-test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/hub"
|
||||
)
|
||||
|
||||
// Store holds the agent's LATEST backup result per target and the latest restore-test
|
||||
// result — the point-in-time state the host-report surfaces. It is updated by the backup
|
||||
// runner + the restore-test scheduler/selftest and read by the collector via the hub
|
||||
// BackupReporter / RestoreTestReporter seams. In-memory (lost on restart; the cadence
|
||||
// re-populates) and mutex-guarded for the concurrent collector vs scheduler access.
|
||||
type Store struct {
|
||||
mu sync.Mutex
|
||||
byTarget map[string]hub.Backup // latest backup per target id
|
||||
lastTest *hub.RestoreTest
|
||||
}
|
||||
|
||||
// NewStore builds an empty Store.
|
||||
func NewStore() *Store {
|
||||
return &Store{byTarget: map[string]hub.Backup{}}
|
||||
}
|
||||
|
||||
// RecordBackup stores the latest backup for its target.
|
||||
func (s *Store) RecordBackup(b hub.Backup) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.byTarget[b.TargetID] = b
|
||||
}
|
||||
|
||||
// RecordRestoreTest stores the latest restore-test result.
|
||||
func (s *Store) RecordRestoreTest(r hub.RestoreTest) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
cp := r
|
||||
s.lastTest = &cp
|
||||
}
|
||||
|
||||
// Backups implements hub.BackupReporter — the latest backup per target (stable order by
|
||||
// target id is not guaranteed; the hub does not depend on order).
|
||||
func (s *Store) Backups(context.Context) []hub.Backup {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
out := make([]hub.Backup, 0, len(s.byTarget))
|
||||
for _, b := range s.byTarget {
|
||||
out = append(out, b)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// RestoreTests implements hub.RestoreTestReporter — the latest restore-test result (0 or 1).
|
||||
func (s *Store) RestoreTests(context.Context) []hub.RestoreTest {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.lastTest == nil {
|
||||
return []hub.RestoreTest{}
|
||||
}
|
||||
return []hub.RestoreTest{*s.lastTest}
|
||||
}
|
||||
Reference in New Issue
Block a user