@@ -259,6 +259,7 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
259
259
{
260
260
261
261
bool redundancy_keep = false;
262
+ time_t backup_time = 0 ;
262
263
pgBackup * backup = (pgBackup * )parray_get (backup_list , (size_t )i );
263
264
264
265
/* 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
280
281
cur_full_backup_num ++ ;
281
282
}
282
283
283
- /*Check if backup in needed by retention policy
284
- *TODO: consider that ERROR backup most likely to have recovery_time == 0
284
+ /*Invalid and running backups most likely to have recovery_time == 0,
285
+ *so in this case use start_time instead.
285
286
*/
286
- if ((days_threshold == 0 || (days_threshold > backup -> recovery_time ))&&
287
+ if (backup -> recovery_time )
288
+ backup_time = backup -> recovery_time ;
289
+ else
290
+ backup_time = backup -> start_time ;
291
+
292
+ /* Check if backup in needed by retention policy */
293
+ if ((days_threshold == 0 || (days_threshold > backup_time ))&&
287
294
(instance_config .retention_redundancy == 0 || !redundancy_keep ))
288
295
{
289
296
/* This backup is not guarded by retention