From d249d23bdd3f05aae2d8ff6c718e5e0d37e8cf78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rad=C3=BCnz?= Date: Sun, 11 Feb 2018 15:15:06 +0100 Subject: [PATCH] Comply with option allow-full-removal when applying retention policy --- .../Library/Main/Operation/DeleteHandler.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Duplicati/Library/Main/Operation/DeleteHandler.cs b/Duplicati/Library/Main/Operation/DeleteHandler.cs index 6fde2de22..84539b4f6 100644 --- a/Duplicati/Library/Main/Operation/DeleteHandler.cs +++ b/Duplicati/Library/Main/Operation/DeleteHandler.cs @@ -228,8 +228,11 @@ namespace Duplicati.Library.Main.Operation // Make sure the backups are in descending order (newest backup in the beginning) clonedBackupList = clonedBackupList.OrderByDescending(x => x).ToList(); - // Most current backup should never get deleted in this process, so exclude it + // Most recent backup usually should never get deleted in this process, so exclude it for now, + // but keep a reference to potentiall delete it when allow-full-removal is set + var mostRecentBackup = clonedBackupList.ElementAt(0); clonedBackupList.RemoveAt(0); + var deleteMostRecentBackup = m_options.AllowFullRemoval; Logging.Log.WriteMessage(string.Format("[Retention Policy]: Time frames and intervals pairs: {0}", string.Join(", ", retentionPolicyOptionValue.Select(x => x.Key + " / " + x.Value))), Logging.LogMessageType.Information); @@ -279,6 +282,9 @@ namespace Duplicati.Library.Main.Operation backupsToDelete.Add(backup); } } + + // Check if most recent backup is outside of this time frame (meaning older/smaller) + deleteMostRecentBackup &= (mostRecentBackup < timeFrame); } // Delete all remaining backups @@ -286,6 +292,14 @@ namespace Duplicati.Library.Main.Operation Logging.Log.WriteMessage(string.Format("[Retention Policy]: Backups outside of all time frames and thus getting deleted: {0}", string.Join(", ", clonedBackupList)), Logging.LogMessageType.Information); + // Delete most recent backup if allow-full-removal is set and the most current backup is outside of any time frame + if (deleteMostRecentBackup) + { + backupsToDelete.Add(mostRecentBackup); + Logging.Log.WriteMessage(string.Format("[Retention Policy]: Deleting most recent backup: {0}", + mostRecentBackup), Logging.LogMessageType.Information); + } + Logging.Log.WriteMessage(string.Format("[Retention Policy]: All backups to delete: {0}", string.Join(", ", backupsToDelete.OrderByDescending(x => x))), Logging.LogMessageType.Information);