8585do_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