Skip to content

Commit 9efc32f

Browse files
committed
fix counting in dest_backup search
1 parent 8f4232d commit 9efc32f

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/catalog.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ catalog_get_backup_list(time_t requested_backup_id)
254254
struct dirent *data_ent = NULL;
255255
parray *backups = NULL;
256256
pgBackup *backup = NULL;
257-
258257
int i;
259258

260259
/* open backup instance backups directory */

src/restore.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int
8585
do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
8686
bool is_restore)
8787
{
88-
int i;
88+
int i = 0;
8989
parray *backups;
9090
pgBackup *current_backup = NULL;
9191
pgBackup *dest_backup = NULL;
@@ -119,9 +119,10 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
119119
elog(ERROR, "Failed to get backup list.");
120120

121121
/* Find backup range we should restore or validate. */
122-
for (i = 0; i < parray_num(backups); i++)
122+
while ((i < parray_num(backups)) && !dest_backup)
123123
{
124124
current_backup = (pgBackup *) parray_get(backups, i);
125+
i++;
125126

126127
/* Skip all backups which started after target backup */
127128
if (target_backup_id && current_backup->start_time > target_backup_id)
@@ -133,7 +134,6 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
133134
*/
134135

135136
if (is_restore &&
136-
!dest_backup &&
137137
target_backup_id == INVALID_BACKUP_ID &&
138138
current_backup->status != BACKUP_STATUS_OK)
139139
{
@@ -147,8 +147,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
147147
* ensure that it satisfies recovery target.
148148
*/
149149
if ((target_backup_id == current_backup->start_time
150-
|| target_backup_id == INVALID_BACKUP_ID)
151-
&& !dest_backup)
150+
|| target_backup_id == INVALID_BACKUP_ID))
152151
{
153152

154153
/* backup is not ok,
@@ -201,7 +200,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
201200
* Save it as dest_backup
202201
*/
203202
dest_backup = current_backup;
204-
dest_backup_index = i;
203+
dest_backup_index = i-1;
205204
}
206205
}
207206

0 commit comments

Comments
 (0)