85
85
do_restore_or_validate (time_t target_backup_id , pgRecoveryTarget * rt ,
86
86
bool is_restore )
87
87
{
88
- int i ;
88
+ int i = 0 ;
89
89
parray * backups ;
90
90
pgBackup * current_backup = NULL ;
91
91
pgBackup * dest_backup = NULL ;
@@ -119,9 +119,10 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
119
119
elog (ERROR , "Failed to get backup list." );
120
120
121
121
/* 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 )
123
123
{
124
124
current_backup = (pgBackup * ) parray_get (backups , i );
125
+ i ++ ;
125
126
126
127
/* Skip all backups which started after target backup */
127
128
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,
133
134
*/
134
135
135
136
if (is_restore &&
136
- !dest_backup &&
137
137
target_backup_id == INVALID_BACKUP_ID &&
138
138
current_backup -> status != BACKUP_STATUS_OK )
139
139
{
@@ -147,8 +147,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
147
147
* ensure that it satisfies recovery target.
148
148
*/
149
149
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 ))
152
151
{
153
152
154
153
/* backup is not ok,
@@ -201,7 +200,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
201
200
* Save it as dest_backup
202
201
*/
203
202
dest_backup = current_backup ;
204
- dest_backup_index = i ;
203
+ dest_backup_index = i - 1 ;
205
204
}
206
205
}
207
206
0 commit comments