Skip to content

Commit a5e2c83

Browse files
author
Artur Zakirov
committed
Remove all increments, even backups with errors
1 parent 5c76697 commit a5e2c83

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

delete.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ int
2222
do_delete(time_t backup_id)
2323
{
2424
int i;
25-
int b_index;
26-
parray *backup_list;
27-
pgBackup *last_backup = NULL;
25+
int last_index;
26+
parray *backup_list;
27+
pgBackup *last_backup = NULL;
2828

2929
/* DATE are always required */
3030
if (backup_id == 0)
@@ -49,27 +49,33 @@ do_delete(time_t backup_id)
4949
elog(ERROR, "no backup found, cannot delete.");
5050

5151
found_backup:
52-
b_index = i;
52+
last_index = i;
5353
/* check for interrupt */
5454
if (interrupted)
5555
elog(ERROR, "interrupted during delete backup");
5656

5757
/* just do it */
5858
pgBackupDeleteFiles(last_backup);
5959

60-
if (last_backup->status == BACKUP_STATUS_ERROR)
60+
/*
61+
* Do not remove next backups, if current backup is not full backup and
62+
* was finished incorrectly.
63+
*/
64+
if (last_backup->status != BACKUP_STATUS_OK &&
65+
last_backup->status != BACKUP_STATUS_CORRUPT &&
66+
last_backup->backup_mode != BACKUP_MODE_FULL)
6167
return 0;
6268

63-
/* remove all increments after removed backup */
64-
for (i = b_index - 1; i >= 0; i--)
69+
/* Remove all increments after removed backup */
70+
for (i = last_index - 1; i >= 0; i--)
6571
{
66-
pgBackup *backup = (pgBackup *) parray_get(backup_list, i);
72+
pgBackup *backup = (pgBackup *) parray_get(backup_list, i);
73+
74+
/* Stop removing increments */
6775
if (backup->backup_mode >= BACKUP_MODE_FULL)
6876
break;
69-
if ((backup->status == BACKUP_STATUS_OK || backup->status == BACKUP_STATUS_CORRUPT) &&
70-
(backup->backup_mode == BACKUP_MODE_DIFF_PAGE || backup->backup_mode == BACKUP_MODE_DIFF_PTRACK)
71-
)
72-
pgBackupDeleteFiles(backup);
77+
78+
pgBackupDeleteFiles(backup);
7379
}
7480

7581
/* cleanup */

0 commit comments

Comments
 (0)