From af20de27e1a67c0c119f3356085a63a2ce4fd88b Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Mon, 7 Jul 2025 11:27:13 +0200 Subject: [PATCH] Run backups in order after startup This changes the order that backups are queue to better match their intended execution order. If the machine is off for a day, the next time Duplicati starts, it will find all backups that were supposed to have run and queues these. Before, the order of backups being queued would depend on the database order, essentially creation order. This PR changes the logic to keep track of when they were supposed to run (first triggered time if multiple slots were skipped), and then adds the backups into the queue, so the job that was supposed to run first, will now be queued first. This fixes #1476 --- Duplicati/Library/RestAPI/Scheduler.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Duplicati/Library/RestAPI/Scheduler.cs b/Duplicati/Library/RestAPI/Scheduler.cs index bc1f175cc..459cc14e4 100644 --- a/Duplicati/Library/RestAPI/Scheduler.cs +++ b/Duplicati/Library/RestAPI/Scheduler.cs @@ -305,7 +305,7 @@ namespace Duplicati.Server //If time is exceeded, run it now if (start <= DateTime.UtcNow) { - var jobsToRun = new List(); + var collectedJobs = new List<(DateTime When, Server.Runner.IRunnerData Job)>(); //TODO: Cache this to avoid frequent lookups foreach (var id in m_dataConnection.GetBackupIDsForTags(sc.Tags).Distinct() .Select(x => x.ToString())) @@ -355,7 +355,7 @@ namespace Duplicati.Server var job = Server.Runner.CreateTask(Serialization.DuplicatiOperation.Backup, entry, taskOptions); job.OnStarting = () => OnStartingWork(job); job.OnFinished = (_) => OnCompleted(job); - jobsToRun.Add(job); + collectedJobs.Add((start, job)); } } } @@ -376,6 +376,10 @@ namespace Duplicati.Server continue; } + var jobsToRun = collectedJobs.OrderBy(x => x.When) + .Select(x => x.Job) + .ToList(); + var lastJob = jobsToRun.LastOrDefault(); if (lastJob != null) {