@@ -141,7 +141,10 @@ do_restore_or_validate(time_t target_backup_id,
141141 * we must find the first valid(!) backup.
142142 */
143143
144- if (is_restore && target_backup_id == 0 && current_backup -> status != BACKUP_STATUS_OK )
144+ if (is_restore &&
145+ !dest_backup &&
146+ target_backup_id == INVALID_BACKUP_ID &&
147+ current_backup -> status != BACKUP_STATUS_OK )
145148 {
146149 elog (WARNING , "Skipping backup %s, because it has non-valid status: %s" ,
147150 base36enc (current_backup -> start_time ), status2str (current_backup -> status ));
@@ -156,9 +159,22 @@ do_restore_or_validate(time_t target_backup_id,
156159 || target_backup_id == INVALID_BACKUP_ID )
157160 && !dest_backup )
158161 {
162+
163+ /* backup is not ok,
164+ * but in case of CORRUPT, ORPHAN or DONE revalidation can be done,
165+ * in other cases throw an error.
166+ */
159167 if (current_backup -> status != BACKUP_STATUS_OK )
160- elog (ERROR , "Backup %s has status: %s" ,
161- base36enc (current_backup -> start_time ), status2str (current_backup -> status ));
168+ {
169+ if (current_backup -> status == BACKUP_STATUS_DONE ||
170+ current_backup -> status == BACKUP_STATUS_ORPHAN ||
171+ current_backup -> status == BACKUP_STATUS_CORRUPT )
172+ elog (WARNING , "Backup %s has status: %s" ,
173+ base36enc (current_backup -> start_time ), status2str (current_backup -> status ));
174+ else
175+ elog (ERROR , "Backup %s has status: %s" ,
176+ base36enc (current_backup -> start_time ), status2str (current_backup -> status ));
177+ }
162178
163179 if (target_tli )
164180 {
@@ -197,17 +213,24 @@ do_restore_or_validate(time_t target_backup_id,
197213 if (current_backup -> backup_mode == BACKUP_MODE_FULL )
198214 {
199215 if (current_backup -> status != BACKUP_STATUS_OK )
200- elog (ERROR , "base backup %s for given backup %s is in %s status" ,
201- base36enc_dup (current_backup -> start_time ),
202- base36enc_dup (dest_backup -> start_time ),
203- status2str (current_backup -> status ));
204- else
205216 {
206- /* We found both dest and base backups. */
207- base_full_backup = current_backup ;
208- base_full_backup_index = i ;
209- break ;
217+ /* Full backup revalidation can be done only for DONE and CORRUPT */
218+ if (current_backup -> status == BACKUP_STATUS_DONE ||
219+ current_backup -> status == BACKUP_STATUS_CORRUPT )
220+ elog (WARNING , "base backup %s for given backup %s is in %s status, trying to revalidate" ,
221+ base36enc_dup (current_backup -> start_time ),
222+ base36enc_dup (dest_backup -> start_time ),
223+ status2str (current_backup -> status ));
224+ else
225+ elog (ERROR , "base backup %s for given backup %s is in %s status" ,
226+ base36enc_dup (current_backup -> start_time ),
227+ base36enc_dup (dest_backup -> start_time ),
228+ status2str (current_backup -> status ));
210229 }
230+ /* We found both dest and base backups. */
231+ base_full_backup = current_backup ;
232+ base_full_backup_index = i ;
233+ break ;
211234 }
212235 else
213236 /* It`s ok to skip incremental backup */
@@ -235,12 +258,16 @@ do_restore_or_validate(time_t target_backup_id,
235258 {
236259 pgBackup * backup = (pgBackup * ) parray_get (backups , i );
237260 pgBackupValidate (backup );
261+ /* Maybe we should be more paranoid and check for !BACKUP_STATUS_OK? */
238262 if (backup -> status == BACKUP_STATUS_CORRUPT )
239263 {
240264 corrupted_backup = backup ;
241265 corrupted_backup_index = i ;
242266 break ;
243267 }
268+ /* We do not validate WAL files of intermediate backups
269+ * It`s done to speed up restore
270+ */
244271 }
245272 /* There is no point in wal validation
246273 * if there is corrupted backup between base_backup and dest_backup
0 commit comments