From 1c3512fadf7b8b733f5d11e1018ffc5c09eebe62 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 10 Jan 2014 08:40:39 +0900 Subject: [PATCH] Fix old backup removal for specified number of days Backups could be removed even if generation number was set to infinite without caring of the day threashold calculated. Backups are removed if they either satisfy the generation or the day threshold. --- backup.c | 6 ++++-- delete.c | 6 ++++-- expected/backup_restore.out | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/backup.c b/backup.c index e7272dc1..ce3091b8 100644 --- a/backup.c +++ b/backup.c @@ -1379,13 +1379,15 @@ delete_old_files(const char *root, * If the mtime of the file is older than the threshold and there are * enough number of files newer than the files, delete the file. */ - if (file->mtime >= days_threshold) + if (file->mtime >= days_threshold && + keep_days != KEEP_INFINITE) { elog(LOG, "%s() %lu is not older than %lu", __FUNCTION__, file->mtime, days_threshold); continue; } - else if (file_num <= keep_files) + else if (file_num <= keep_files && + keep_files != KEEP_INFINITE) { elog(LOG, "%s() newer files are only %d", __FUNCTION__, file_num); continue; diff --git a/delete.c b/delete.c index fe057fac..da161093 100644 --- a/delete.c +++ b/delete.c @@ -129,13 +129,15 @@ pgBackupDelete(int keep_generations, int keep_days) backup_num++; /* Evaluate if this backup is eligible for removal */ - if (backup_num <= keep_generations) + if (backup_num <= keep_generations && + keep_generations != KEEP_INFINITE) { /* Do not include the latest full backup in this count */ elog(LOG, "%s() backup are only %d", __FUNCTION__, backup_num); continue; } - else if (backup->start_time >= days_threshold) + else if (backup->start_time >= days_threshold && + keep_days != KEEP_INFINITE) { /* * If the start time of the backup is older than the threshold and diff --git a/expected/backup_restore.out b/expected/backup_restore.out index 9f7ba948..aaa83b21 100644 --- a/expected/backup_restore.out +++ b/expected/backup_restore.out @@ -29,11 +29,11 @@ CHECKPOINT # of recovery target option in recovery.conf 3 # of deleted backups (show all) -3 +4 # of deleted backups 0 delete backup # of deleted backups -3 +4 # of deleted backups -8 +9