@@ -202,41 +202,40 @@ do_restore_or_validate(time_t target_backup_id,
202202 dest_backup_index = i ;
203203 }
204204
205- /* If we already found dest_backup, look for full backup. */
206- /* TODO Now, as we have all backups linked, we can probably get rid of that?"*/
207- if (dest_backup )
205+ }
206+
207+ /* If we already found dest_backup, look for full backup. */
208+ if (dest_backup )
209+ {
210+ base_full_backup = current_backup ;
211+
212+ if (current_backup -> backup_mode != BACKUP_MODE_FULL )
213+ {
214+ base_full_backup = find_parent_backup (current_backup );
215+
216+ if (base_full_backup == NULL )
217+ elog (ERROR , "Valid full backup for backup %s is not found." ,
218+ base36enc (current_backup -> start_time ));
219+ }
220+
221+ /*
222+ * We have found full backup by link,
223+ * now we need to walk the list to find its index.
224+ *
225+ * TODO I think we should rewrite it someday to use double linked list
226+ * and avoid relying on sort order anymore.
227+ */
228+ for (i = dest_backup_index ; i < parray_num (backups ); i ++ )
208229 {
209- if (current_backup -> backup_mode == BACKUP_MODE_FULL )
230+ pgBackup * temp_backup = (pgBackup * ) parray_get (backups , i );
231+ if (temp_backup -> start_time == base_full_backup -> start_time )
210232 {
211- if (current_backup -> status != BACKUP_STATUS_OK )
212- {
213- /* Full backup revalidation can be done only for DONE and CORRUPT */
214- if (current_backup -> status == BACKUP_STATUS_DONE ||
215- current_backup -> status == BACKUP_STATUS_CORRUPT )
216- elog (WARNING , "base backup %s for given backup %s is in %s status, trying to revalidate" ,
217- base36enc_dup (current_backup -> start_time ),
218- base36enc_dup (dest_backup -> start_time ),
219- status2str (current_backup -> status ));
220- else
221- elog (ERROR , "base backup %s for given backup %s is in %s status" ,
222- base36enc_dup (current_backup -> start_time ),
223- base36enc_dup (dest_backup -> start_time ),
224- status2str (current_backup -> status ));
225- }
226- /* We found both dest and base backups. */
227- base_full_backup = current_backup ;
228233 base_full_backup_index = i ;
229234 break ;
230235 }
231- else
232- /* It`s ok to skip incremental backup */
233- continue ;
234236 }
235237 }
236238
237- if (base_full_backup == NULL )
238- elog (ERROR , "Full backup satisfying target options is not found." );
239-
240239 /*
241240 * Ensure that directories provided in tablespace mapping are valid
242241 * i.e. empty or not exist.
0 commit comments