@@ -259,6 +259,7 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
259259{
260260
261261bool redundancy_keep = false;
262+ time_t backup_time = 0 ;
262263pgBackup * backup = (pgBackup * )parray_get (backup_list , (size_t )i );
263264
264265/* 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
280281cur_full_backup_num ++ ;
281282}
282283
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.
285286 */
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 ))&&
287294(instance_config .retention_redundancy == 0 || !redundancy_keep ))
288295{
289296/* This backup is not guarded by retention