Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Stop partial PBS sync copies pinning guests as backing up

rcourtmana1336348cbdd
diff --git a/internal/models/backup_in_progress_test.go b/internal/models/backup_in_progress_test.go
index 06f07d1b1c..8e8dc50e4b 100644
--- a/internal/models/backup_in_progress_test.go
+++ b/internal/models/backup_in_progress_test.go
@@ -179,3 +179,68 @@ func TestUpdateVMsForInstancePreservesBackupInProgress(t *testing.T) {
t.Error("BackupInProgress lost across instance update")
}
}
+
+// A PBS-to-PBS sync interrupted mid-snapshot leaves a manifest-less copy of
+// an already-completed backup on the target datastore. That partial copy
+// carries the original backup time, so it is never newer than its completed
+// twin and must not report the guest as backing up until the sync is
+// repaired (#1815).
+func TestSyncGuestBackupTimesIgnoresPartialSyncCopyOfCompletedBackup(t *testing.T) {
+ state := NewState()
+ now := time.Now()
+ backupTime := now.Add(-2 * time.Hour)
+
+ state.UpdateVMs([]VM{
+ {VMID: 117, Name: "win11-pvepc", Instance: "pve-pc", Node: "pve-pc"},
+ })
+
+ state.mu.Lock()
+ state.PBSBackups = []PBSBackup{
+ // Completed snapshot on the primary PBS.
+ {ID: "done-117", VMID: "117", BackupType: "vm", BackupTime: backupTime,
+ Instance: "verdeclose", Datastore: "main", Namespace: "pve-pc"},
+ // Partial copy of the same snapshot on the sync target.
+ {ID: "partial-117", VMID: "117", BackupType: "vm", BackupTime: backupTime,
+ Instance: "offsite", Datastore: "sync", Namespace: "pve-pc", InProgress: true},
+ }
+ state.mu.Unlock()
+
+ state.SyncGuestBackupTimes()
+ snapshot := state.GetSnapshot()
+
+ vm := snapshot.VMs[0]
+ if !vm.LastBackup.Equal(backupTime) {
+ t.Errorf("LastBackup = %v, want %v", vm.LastBackup, backupTime)
+ }
+ if vm.BackupInProgress {
+ t.Error("BackupInProgress = true, want false for a partial sync copy of a completed backup")
+ }
+}
+
+// A manifest-less snapshot with no completed twin left must age out the same
+// way a stale running task does: whatever was writing it is long gone.
+func TestSyncGuestBackupTimesIgnoresAbandonedInFlightSnapshot(t *testing.T) {
+ state := NewState()
+ now := time.Now()
+
+ state.UpdateVMs([]VM{
+ {VMID: 117, Name: "win11-pvepc", Instance: "pve-pc", Node: "pve-pc"},
+ })
+
+ state.mu.Lock()
+ state.PBSBackups = []PBSBackup{
+ {ID: "flight-117", VMID: "117", BackupType: "vm", BackupTime: now.Add(-72 * time.Hour),
+ Instance: "verdeclose", Datastore: "main", Namespace: "pve-pc", InProgress: true},
+ }
+ state.mu.Unlock()
+
+ state.SyncGuestBackupTimes()
+ snapshot := state.GetSnapshot()
+
+ if snapshot.VMs[0].BackupInProgress {
+ t.Error("BackupInProgress = true, want false for an abandoned in-flight snapshot")
+ }
+ if !snapshot.VMs[0].LastBackup.IsZero() {
+ t.Errorf("LastBackup = %v, want zero", snapshot.VMs[0].LastBackup)
+ }
+}
diff --git a/internal/models/models.go b/internal/models/models.go
index 6ae5b7dfdb..4f3432b0e1 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -4360,10 +4360,12 @@ func (s *State) UpdateContainers(containers []Container) {
s.LastUpdate = time.Now()
}
-// runningBackupTaskMaxAge bounds how long an unfinished vzdump task keeps
+// runningBackupTaskMaxAge bounds how long unfinished backup evidence (a
+// vzdump task still listed as running, or a manifest-less PBS snapshot) keeps
// reporting a guest as backing up. Task lists stop refreshing for an
-// unreachable instance, and a wedged multi-day vzdump is not a state worth
-// advertising as "running" on the guest badge.
+// unreachable instance, partial snapshots survive interrupted syncs, and a
+// wedged multi-day backup is not a state worth advertising as "running" on
+// the guest badge.
const runningBackupTaskMaxAge = 24 * time.Hour
// backupKey creates a composite key for backup matching using instance and VMID.
@@ -4752,8 +4754,14 @@ func (s *State) SyncGuestBackupTimes() {
}
s.VMs[i].LastBackup = lastBackup
_, taskRunning := runningBackupTask[key]
+ // A manifest-less PBS snapshot that is not newer than the guest's last
+ // completed backup is a partial copy left behind by an interrupted
+ // sync, not a backup being written now, and one older than the
+ // running-task cutoff has been abandoned. Neither may pin the guest
+ // as backing up (#1815).
+ inFlight := findBestPBSBackup(pbsInProgressBySubject, s.VMs[i].VMID, "vm", s.VMs[i].Instance, s.VMs[i].Node, s.VMs[i].Name)
s.VMs[i].BackupInProgress = taskRunning ||
- !findBestPBSBackup(pbsInProgressBySubject, s.VMs[i].VMID, "vm", s.VMs[i].Instance, s.VMs[i].Node, s.VMs[i].Name).IsZero()
+ (inFlight.After(lastBackup) && !inFlight.Before(runningTaskCutoff))
}
// Update Containers - recompute from current backup evidence instead of preserving stale values
@@ -4772,8 +4780,10 @@ func (s *State) SyncGuestBackupTimes() {
}
s.Containers[i].LastBackup = lastBackup
_, taskRunning := runningBackupTask[key]
+ // Same partial-copy and abandonment guards as the VM loop (#1815).
+ inFlight := findBestPBSBackup(pbsInProgressBySubject, s.Containers[i].VMID, "ct", s.Containers[i].Instance, s.Containers[i].Node, s.Containers[i].Name)
s.Containers[i].BackupInProgress = taskRunning ||
- !findBestPBSBackup(pbsInProgressBySubject, s.Containers[i].VMID, "ct", s.Containers[i].Instance, s.Containers[i].Node, s.Containers[i].Name).IsZero()
+ (inFlight.After(lastBackup) && !inFlight.Before(runningTaskCutoff))
}
s.LastUpdate = time.Now()