Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

chore: skip stale operations cleanup of remote agents

towfiqifb81f9473d8f
diff --git a/backend/__tests__/services/PlanService.test.ts b/backend/__tests__/services/PlanService.test.ts
index 185643b..07da986 100644
--- a/backend/__tests__/services/PlanService.test.ts
+++ b/backend/__tests__/services/PlanService.test.ts
@@ -1246,6 +1246,31 @@ describe('PlanService', () => {
expect(result.plans).toHaveLength(1);
});
+ it('leaves in-progress rows of a remote device alone', async () => {
+ mockBackupStore.getAll = jest
+ .fn()
+ .mockResolvedValue([{ id: 'b1', planId: 'p1', sourceId: 'device-1', inProgress: true }]);
+ mockRestoreStore.getAll = jest.fn().mockResolvedValue([
+ { id: 'r1', planId: 'p1', backupId: 'b1', sourceId: 'device-1', inProgress: true },
+ ]);
+ mockPlanStore.getAll = jest
+ .fn()
+ .mockResolvedValue([{ id: 'p1', sourceId: 'device-1', inProgress: true }]);
+
+ mockBackupStore.update = jest.fn();
+ mockRestoreStore.update = jest.fn();
+ mockPlanStore.update = jest.fn();
+
+ const result = await planService.clearOrphanedInProgress();
+
+ expect(mockBackupStore.update).not.toHaveBeenCalled();
+ expect(mockRestoreStore.update).not.toHaveBeenCalled();
+ expect(mockPlanStore.update).not.toHaveBeenCalled();
+ expect(result.backups).toHaveLength(0);
+ expect(result.restores).toHaveLength(0);
+ expect(result.plans).toHaveLength(0);
+ });
+
it('does nothing when there are no orphans', async () => {
mockBackupStore.getAll = jest.fn().mockResolvedValue([{ id: 'b1', inProgress: false }]);
mockRestoreStore.getAll = jest.fn().mockResolvedValue(null);
diff --git a/backend/src/services/PlanService.ts b/backend/src/services/PlanService.ts
index b1a0bff..3f57b24 100644
--- a/backend/src/services/PlanService.ts
+++ b/backend/src/services/PlanService.ts
@@ -752,9 +752,10 @@ export class PlanService {
/**
* Marks every orphaned in-progress backup and restore as failed and clears
- * stale in-progress flags on plans. The job queue is in memory only, so any
- * in-progress row at startup is a leftover of a stopped or crashed service.
- * Returns the swept rows.
+ * stale in-progress flags on plans. The job queue is in memory only, so a
+ * row of this host that is in progress at startup is a leftover of a stopped
+ * or crashed service. Rows of a remote device are left alone.
+ * Returns the cleared rows.
*/
public async clearOrphanedInProgress(): Promise<{
backups: Backup[];
@@ -766,8 +767,14 @@ export class PlanService {
const restoreMsg =
'Restore was interrupted because the Pluton service stopped or restarted. It was not completed.';
+ // Only rows of this host. A remote device runs its own agent, which keeps
+ // running when Pluton restarts, so its in-progress rows are not orphans.
+ const isLocal = (row: { sourceId?: string | null }) => (row.sourceId || 'main') === 'main';
+
const sweptBackups: Backup[] = [];
- const orphanBackups = ((await this.backupStore.getAll()) || []).filter(b => b.inProgress);
+ const orphanBackups = ((await this.backupStore.getAll()) || []).filter(
+ b => b.inProgress && isLocal(b)
+ );
for (const backup of orphanBackups) {
const updated = await this.backupStore.update(backup.id, {
inProgress: false,
@@ -780,7 +787,9 @@ export class PlanService {
}
const sweptRestores: Restore[] = [];
- const orphanRestores = ((await this.restoreStore.getAll()) || []).filter(r => r.inProgress);
+ const orphanRestores = ((await this.restoreStore.getAll()) || []).filter(
+ r => r.inProgress && isLocal(r)
+ );
for (const restore of orphanRestores) {
// RestoreStore.update sets `ended` for a final status on its own.
const updated = await this.restoreStore.update(restore.id, {
@@ -792,7 +801,9 @@ export class PlanService {
}
const sweptPlans: Plan[] = [];
- const orphanPlans = ((await this.planStore.getAll()) || []).filter(p => p.inProgress);
+ const orphanPlans = ((await this.planStore.getAll()) || []).filter(
+ p => p.inProgress && isLocal(p)
+ );
for (const plan of orphanPlans) {
const updated = await this.planStore.update(plan.id, { inProgress: false });
if (updated) sweptPlans.push(updated);