@@ -117,10 +117,15 @@ int do_retention(void)
117
117
parray * to_purge_list = parray_new ();
118
118
119
119
bool retention_is_set = false;/* At least one retention policy is set */
120
+ bool backup_list_is_empty = false;
120
121
121
122
/* Get a complete list of backups. */
122
123
backup_list = catalog_get_backup_list (INVALID_BACKUP_ID );
123
124
125
+ /* sanity */
126
+ if (parray_num (backup_list )== 0 )
127
+ backup_list_is_empty = true;
128
+
124
129
if (delete_expired || merge_expired )
125
130
{
126
131
if (instance_config .retention_redundancy > 0 )
@@ -142,14 +147,17 @@ int do_retention(void)
142
147
retention_is_set = true;
143
148
}
144
149
150
+ if (retention_is_set && backup_list_is_empty )
151
+ elog (WARNING ,"Backup list is empty, retention purge and merge are problematic" );
152
+
145
153
/* show fancy message */
146
- if (retention_is_set )
154
+ if (retention_is_set && ! backup_list_is_empty )
147
155
do_retention_internal (backup_list ,to_keep_list ,to_purge_list );
148
156
149
157
if (merge_expired && !dry_run )
150
158
do_retention_merge (backup_list ,to_keep_list ,to_purge_list );
151
159
152
- if (delete_expired && !dry_run )
160
+ if (delete_expired && !dry_run && ! backup_list_is_empty )
153
161
do_retention_purge (to_keep_list ,to_purge_list );
154
162
155
163
/* TODO: some sort of dry run for delete_wal */
@@ -203,40 +211,31 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
203
211
if (parray_num (backup_list )== 0 )
204
212
backup_list_is_empty = true;
205
213
206
- if (backup_list_is_empty )
207
- {
208
- elog (WARNING ,"Backup list is empty, purging won't be executed" );
209
- return ;
210
- }
211
-
212
214
/* Get current time */
213
215
current_time = time (NULL );
214
216
215
217
/* Calculate n_full_backups and days_threshold */
216
- if (! backup_list_is_empty )
218
+ if (instance_config . retention_redundancy > 0 )
217
219
{
218
- if ( instance_config . retention_redundancy > 0 )
220
+ for ( i = 0 ; i < parray_num ( backup_list ); i ++ )
219
221
{
220
- for (i = 0 ;i < parray_num (backup_list );i ++ )
221
- {
222
- pgBackup * backup = (pgBackup * )parray_get (backup_list ,i );
222
+ pgBackup * backup = (pgBackup * )parray_get (backup_list ,i );
223
223
224
- /* Consider only valid backups for Redundancy */
225
- if (instance_config .retention_redundancy > 0 &&
226
- backup -> backup_mode == BACKUP_MODE_FULL &&
227
- (backup -> status == BACKUP_STATUS_OK ||
228
- backup -> status == BACKUP_STATUS_DONE ))
229
- {
230
- n_full_backups ++ ;
231
- }
224
+ /* Consider only valid backups for Redundancy */
225
+ if (instance_config .retention_redundancy > 0 &&
226
+ backup -> backup_mode == BACKUP_MODE_FULL &&
227
+ (backup -> status == BACKUP_STATUS_OK ||
228
+ backup -> status == BACKUP_STATUS_DONE ))
229
+ {
230
+ n_full_backups ++ ;
232
231
}
233
232
}
233
+ }
234
234
235
- if (instance_config .retention_window > 0 )
236
- {
237
- days_threshold = current_time -
238
- (instance_config .retention_window * 60 * 60 * 24 );
239
- }
235
+ if (instance_config .retention_window > 0 )
236
+ {
237
+ days_threshold = current_time -
238
+ (instance_config .retention_window * 60 * 60 * 24 );
240
239
}
241
240
242
241
elog (INFO ,"Evaluate backups by retention" );
@@ -588,7 +587,7 @@ do_retention_wal(void)
588
587
TimeLineID oldest_tli = 0 ;
589
588
bool backup_list_is_empty = false;
590
589
591
- /* Getnew backup_list. Should we */
590
+ /* Getlist of backups. */
592
591
backup_list = catalog_get_backup_list (INVALID_BACKUP_ID );
593
592
594
593
if (parray_num (backup_list )== 0 )