From b6e97e47f2ccfb09db649b9a7eff2e1d17123c7e Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Fri, 2 Aug 2019 11:50:28 +0300 Subject: [PATCH] [Issue #106] fix agressive retention purging of backups with empty recovery-time --- src/delete.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/delete.c b/src/delete.c index 83be5d52..0db3c96b 100644 --- a/src/delete.c +++ b/src/delete.c @@ -259,6 +259,7 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg { bool redundancy_keep = false; + time_t backup_time = 0; pgBackup *backup = (pgBackup *) parray_get(backup_list, (size_t) i); /* check if backup`s FULL ancestor is in redundancy list */ @@ -280,10 +281,16 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg cur_full_backup_num++; } - /* Check if backup in needed by retention policy - * TODO: consider that ERROR backup most likely to have recovery_time == 0 + /* Invalid and running backups most likely to have recovery_time == 0, + * so in this case use start_time instead. */ - if ((days_threshold == 0 || (days_threshold > backup->recovery_time)) && + if (backup->recovery_time) + backup_time = backup->recovery_time; + else + backup_time = backup->start_time; + + /* Check if backup in needed by retention policy */ + if ((days_threshold == 0 || (days_threshold > backup_time)) && (instance_config.retention_redundancy == 0 || !redundancy_keep)) { /* This backup is not guarded by retention