Skip to content

Commit 342496e

Browse files
author
Michael Paquier
committed
Fix incremental and archive backup removal on delete command
The previous algorithm was smart enough to remove full backups older than the given number of generations, but not enough to remove incremental and archive backups. This resulted in keeping in the backup list a set of incremental and archive backups older than the latest full backup allowed. As it is useless to keep them, the deletion algorithm is made smarter to take that into account and remove all of them cleanly only when necessary.
1 parent c812fa3 commit 342496e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

delete.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ pgBackupDelete(int keep_generations, int keep_days)
8080
int backup_num;
8181
time_t days_threshold = current.start_time - (keep_days * 60 * 60 * 24);
8282

83-
8483
if (verbose)
8584
{
8685
char generations_str[100];
@@ -116,20 +115,21 @@ pgBackupDelete(int keep_generations, int keep_days)
116115
backup_num = 0;
117116
for (i = 0; i < parray_num(backup_list); i++)
118117
{
119-
pgBackup *backup = (pgBackup *)parray_get(backup_list, i);
118+
pgBackup *backup = (pgBackup *) parray_get(backup_list, i);
119+
int backup_num_evaluate = backup_num;
120120

121121
elog(LOG, "%s() %lu", __FUNCTION__, backup->start_time);
122122

123123
/*
124124
* When a validate full backup was found, we can delete the
125-
* backup that is older than it.
125+
* backup that is older than it using the number of generations.
126126
*/
127-
if (backup->backup_mode >= BACKUP_MODE_FULL &&
127+
if (backup->backup_mode == BACKUP_MODE_FULL &&
128128
backup->status == BACKUP_STATUS_OK)
129129
backup_num++;
130130

131131
/* Evaluate if this backup is eligible for removal */
132-
if (backup_num <= keep_generations &&
132+
if (backup_num_evaluate + 1 <= keep_generations &&
133133
keep_generations != KEEP_INFINITE)
134134
{
135135
/* Do not include the latest full backup in this count */

0 commit comments

Comments
 (0)