Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Scope PBS backup recency to uniquely attributed guests
pulse-triage[bot]7d7b1a0b85b9
diff --git a/internal/models/issue2292_backup_age_test.go b/internal/models/issue2292_backup_age_test.goindex b252e1d41a..56c91d41a0 100644--- a/internal/models/issue2292_backup_age_test.go+++ b/internal/models/issue2292_backup_age_test.go@@ -5,9 +5,9 @@ import ("time")-// A match score establishes whether a PBS snapshot can be attributed to a-// guest. Once it can, the badge must reflect the newest completed snapshot,-// even if an older snapshot has a stronger namespace/comment match (#2292).+// A unique typed VMID permits the root-namespace fallback. Once attributed,+// the badge must reflect the newest completed snapshot, even if an older+// snapshot has a stronger namespace/comment match (#2292).func TestSyncGuestBackupTimesNewestAttributablePBSBackup(t *testing.T) {now := time.Date(2026, time.September, 28, 0, 0, 0, 0, time.UTC)old := now.Add(-65 * 24 * time.Hour)@@ -52,9 +52,9 @@ func TestSyncGuestBackupTimesNewestAttributablePBSBackup(t *testing.T) {}}-// With a colliding typed VMID, the newer snapshot must still carry positive-// attribution for this guest; a newer snapshot for the other PVE connection-// must not advance its badge. VM and CT subjects also remain separate.+// With a colliding typed VMID, the newer snapshot must be distinguishable+// from the other PVE connection; a newer snapshot for that other connection+// must not advance this guest's badge. VM and CT subjects remain separate.func TestSyncGuestBackupTimesNewestPBSBackupPreservesCollisionGuard(t *testing.T) {now := time.Date(2026, time.September, 28, 0, 0, 0, 0, time.UTC)oldA := now.Add(-27 * 24 * time.Hour)@@ -114,3 +114,85 @@ func TestSyncGuestBackupTimesNewestPBSBackupPreservesCollisionGuard(t *testing.T})}}++// Two independent clusters can have the same VMID and node label. In that+// case, a node namespace alone is positive for both guests, but a matching+// guest name makes the backup specific to one. Recency must be considered+// only after deciding which guest each snapshot can actually identify.+func TestSyncGuestBackupTimesNewestPBSBackupSameNodeCollision(t *testing.T) {+ now := time.Date(2026, time.September, 28, 0, 0, 0, 0, time.UTC)+ oldA := now.Add(-65 * 24 * time.Hour)+ recentA := now.Add(-24 * time.Hour)+ recentB := now.Add(-2 * time.Hour)++ for _, backupType := range []string{"vm", "ct"} {+ t.Run(backupType, func(t *testing.T) {+ state := NewState()+ if backupType == "vm" {+ state.UpdateVMs([]VM{+ {VMID: 112, Name: "guest-a", Instance: "cluster-a", Node: "pve"},+ {VMID: 112, Name: "guest-b", Instance: "cluster-b", Node: "pve"},+ })+ } else {+ state.UpdateContainers([]Container{+ {VMID: 112, Name: "guest-a", Instance: "cluster-a", Node: "pve"},+ {VMID: 112, Name: "guest-b", Instance: "cluster-b", Node: "pve"},+ })+ }++ state.mu.Lock()+ state.PBSBackups = []PBSBackup{+ {ID: "old-a", VMID: "112", BackupType: backupType, BackupTime: oldA,+ Instance: "pbs-main", Namespace: "pve", Comment: "guest-a"},+ // Weaker than old-a, but only cluster-a matches this namespace.+ {ID: "recent-a", VMID: "112", BackupType: backupType, BackupTime: recentA,+ Instance: "pbs-main", Namespace: "cluster-a"},+ // Both guests match node pve, but guest-b is the stronger match.+ {ID: "recent-b", VMID: "112", BackupType: backupType, BackupTime: recentB,+ Instance: "pbs-main", Namespace: "pve", Comment: "guest-b"},+ // Neither guest owns an otherwise indistinguishable newer copy.+ {ID: "shared-node", VMID: "112", BackupType: backupType, BackupTime: now.Add(-time.Hour),+ Instance: "pbs-main", Namespace: "pve"},+ // The same attribution rule also governs a live, incomplete PBS+ // snapshot: only B may show a running backup.+ {ID: "running-b", VMID: "112", BackupType: backupType, BackupTime: time.Now(),+ Instance: "pbs-main", Namespace: "pve", Comment: "guest-b", InProgress: true},+ {ID: "running-shared", VMID: "112", BackupType: backupType, BackupTime: time.Now(),+ Instance: "pbs-main", Namespace: "pve", InProgress: true},+ }+ state.mu.Unlock()++ state.SyncGuestBackupTimes()+ snapshot := state.GetSnapshot()+ got := make(map[string]time.Time)+ if backupType == "vm" {+ for _, guest := range snapshot.VMs {+ got[guest.Instance] = guest.LastBackup+ }+ } else {+ for _, guest := range snapshot.Containers {+ got[guest.Instance] = guest.LastBackup+ }+ }+ if !got["cluster-a"].Equal(recentA) {+ t.Errorf("cluster-a LastBackup = %v, want its newer uniquely attributable backup %v", got["cluster-a"], recentA)+ }+ if !got["cluster-b"].Equal(recentB) {+ t.Errorf("cluster-b LastBackup = %v, want its own backup %v", got["cluster-b"], recentB)+ }+ if backupType == "vm" {+ for _, guest := range snapshot.VMs {+ if guest.BackupInProgress != (guest.Instance == "cluster-b") {+ t.Errorf("%s BackupInProgress = %v, want only cluster-b running", guest.Instance, guest.BackupInProgress)+ }+ }+ } else {+ for _, guest := range snapshot.Containers {+ if guest.BackupInProgress != (guest.Instance == "cluster-b") {+ t.Errorf("%s BackupInProgress = %v, want only cluster-b running", guest.Instance, guest.BackupInProgress)+ }+ }+ }+ })+ }+}diff --git a/internal/models/models.go b/internal/models/models.goindex d15c91778b..359f242c1e 100644--- a/internal/models/models.go+++ b/internal/models/models.go@@ -4718,9 +4718,8 @@ func (s *State) SyncGuestBackupTimes() {}// findBestPBSBackup finds the newest attributable PBS backup for a given- // typed VMID and guest location. A positive placement/name score, or a- // guarded VMID-only fallback, establishes attribution; score strength must- // not let an older snapshot hide a newer completed backup (#2292).+ // typed VMID and guest location. Match strength decides which guest owns+ // each snapshot, not whether an older owned snapshot outranks a newer one.// Returns zero time if no suitable backup found. The subject map is a// parameter so the same attribution rules apply to completed snapshots// (feeding LastBackup) and to in-flight ones (feeding BackupInProgress).@@ -4742,6 +4741,32 @@ func (s *State) SyncGuestBackupTimes() {node,)snapshotKey := pbsSnapshotKey{backupType: backupType, vmid: vmid, unixTime: backup.BackupTime.Unix()}+ if score > 0 && subjectIsAmbiguous[subjectKey] {+ // A namespace such as "pve" can match two clusters with the+ // same node label. A positive score is not attribution when a+ // different connection matches the same snapshot at least as+ // strongly. A stronger competitor rules this guest out; a tie+ // needs independent storage/source evidence below (#2292).+ strongestOther := 0+ for _, other := range subjectGuests[subjectKey] {+ if other.instance == instance {+ continue+ }+ otherScore := proxmoxidentity.BackupGuestMatchScore(+ backup.Namespace, backup.Comment, backup.VMID,+ other.name, other.instance, other.node,+ )+ if otherScore > strongestOther {+ strongestOther = otherScore+ }+ }+ if strongestOther > score {+ continue+ }+ if strongestOther == score {+ score = 0+ }+ }if score == 0 {if !subjectIsAmbiguous[subjectKey] {score = 1