@@ -150,7 +150,7 @@ int do_retention(void)
150150if (retention_is_set && backup_list_is_empty )
151151elog (WARNING ,"Backup list is empty, retention purge and merge are problematic" );
152152
153- /* showfancy message */
153+ /*Populate purge and keep lists, and showretention state messages */
154154if (retention_is_set && !backup_list_is_empty )
155155do_retention_internal (backup_list ,to_keep_list ,to_purge_list );
156156
@@ -197,7 +197,6 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
197197{
198198int i ;
199199time_t current_time ;
200- bool backup_list_is_empty = false;
201200
202201/* For retention calculation */
203202uint32 n_full_backups = 0 ;
@@ -207,10 +206,6 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
207206/* For fancy reporting */
208207float actual_window = 0 ;
209208
210- /* sanity */
211- if (parray_num (backup_list )== 0 )
212- backup_list_is_empty = true;
213-
214209/* Get current time */
215210current_time = time (NULL );
216211
@@ -294,21 +289,22 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
294289
295290for (i = 0 ;i < parray_num (backup_list );i ++ )
296291{
297-
298292pgBackup * backup = (pgBackup * )parray_get (backup_list ,i );
299293
300294/* Do not keep invalid backups by retention */
301295if (backup -> status != BACKUP_STATUS_OK &&
302296backup -> status != BACKUP_STATUS_DONE )
303297continue ;
304298
299+ /* only incremental backups should be in keep list */
305300if (backup -> backup_mode == BACKUP_MODE_FULL )
306301continue ;
307302
308303/* orphan backup cannot be in keep list */
309304if (!backup -> parent_backup_link )
310305continue ;
311306
307+ /* skip if backup already in purge list */
312308if (parray_bsearch (to_purge_list ,backup ,pgBackupCompareIdDesc ))
313309continue ;
314310