From 342496e331ea55a1f6e2d086436654fc127ddaba Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 17 Jan 2014 22:02:27 +0900 Subject: [PATCH] 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. --- delete.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/delete.c b/delete.c index da161093..bdafd7bc 100644 --- a/delete.c +++ b/delete.c @@ -80,7 +80,6 @@ pgBackupDelete(int keep_generations, int keep_days) int backup_num; time_t days_threshold = current.start_time - (keep_days * 60 * 60 * 24); - if (verbose) { char generations_str[100]; @@ -116,20 +115,21 @@ pgBackupDelete(int keep_generations, int keep_days) backup_num = 0; for (i = 0; i < parray_num(backup_list); i++) { - pgBackup *backup = (pgBackup *)parray_get(backup_list, i); + pgBackup *backup = (pgBackup *) parray_get(backup_list, i); + int backup_num_evaluate = backup_num; elog(LOG, "%s() %lu", __FUNCTION__, backup->start_time); /* * When a validate full backup was found, we can delete the - * backup that is older than it. + * backup that is older than it using the number of generations. */ - if (backup->backup_mode >= BACKUP_MODE_FULL && + if (backup->backup_mode == BACKUP_MODE_FULL && backup->status == BACKUP_STATUS_OK) backup_num++; /* Evaluate if this backup is eligible for removal */ - if (backup_num <= keep_generations && + if (backup_num_evaluate + 1 <= keep_generations && keep_generations != KEEP_INFINITE) { /* Do not include the latest full backup in this count */