@@ -46,6 +46,50 @@ static parray *get_dbOid_exclude_list(pgBackup *backup, parray *files,
4646parray * datname_list ,bool partial_restore_type );
4747
4848static int pgCompareOid (const void * f1 ,const void * f2 );
49+ static void set_orphan_status (parray * backups ,pgBackup * parent_backup );
50+
51+ /*
52+ * Iterate over backup list to find all ancestors of the broken parent_backup
53+ * and update their status to BACKUP_STATUS_ORPHAN
54+ */
55+ static void
56+ set_orphan_status (parray * backups ,pgBackup * parent_backup )
57+ {
58+ /* chain is intact, but at least one parent is invalid */
59+ char * parent_backup_id ;
60+ int j ;
61+
62+ /* parent_backup_id is a human-readable backup ID */
63+ parent_backup_id = base36enc_dup (parent_backup -> start_time );
64+
65+ for (j = 0 ;j < parray_num (backups );j ++ )
66+ {
67+
68+ pgBackup * backup = (pgBackup * )parray_get (backups ,j );
69+
70+ if (is_parent (parent_backup -> start_time ,backup , false))
71+ {
72+ if (backup -> status == BACKUP_STATUS_OK ||
73+ backup -> status == BACKUP_STATUS_DONE )
74+ {
75+ write_backup_status (backup ,BACKUP_STATUS_ORPHAN );
76+
77+ elog (WARNING ,
78+ "Backup %s is orphaned because his parent %s has status: %s" ,
79+ base36enc (backup -> start_time ),
80+ parent_backup_id ,
81+ status2str (parent_backup -> status ));
82+ }
83+ else
84+ {
85+ elog (WARNING ,"Backup %s has parent %s with status: %s" ,
86+ base36enc (backup -> start_time ),parent_backup_id ,
87+ status2str (parent_backup -> status ));
88+ }
89+ }
90+ }
91+ pg_free (parent_backup_id );
92+ }
4993
5094/*
5195 * Entry point of pg_probackup RESTORE and VALIDATE subcommands.
@@ -208,7 +252,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
208252 * and orphinize all his descendants
209253 */
210254char * missing_backup_id ;
211- time_t missing_backup_start_time ;
255+ time_t missing_backup_start_time ;
212256
213257missing_backup_start_time = tmp_backup -> parent_backup ;
214258missing_backup_id = base36enc_dup (tmp_backup -> parent_backup );
@@ -244,38 +288,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
244288else if (result == 1 )
245289{
246290/* chain is intact, but at least one parent is invalid */
247- char * parent_backup_id ;
248-
249- /* parent_backup_id contain human-readable backup ID of oldest invalid backup */
250- parent_backup_id = base36enc_dup (tmp_backup -> start_time );
251-
252- for (j = 0 ;j < parray_num (backups );j ++ )
253- {
254-
255- pgBackup * backup = (pgBackup * )parray_get (backups ,j );
256-
257- if (is_parent (tmp_backup -> start_time ,backup , false))
258- {
259- if (backup -> status == BACKUP_STATUS_OK ||
260- backup -> status == BACKUP_STATUS_DONE )
261- {
262- write_backup_status (backup ,BACKUP_STATUS_ORPHAN );
263-
264- elog (WARNING ,
265- "Backup %s is orphaned because his parent %s has status: %s" ,
266- base36enc (backup -> start_time ),
267- parent_backup_id ,
268- status2str (tmp_backup -> status ));
269- }
270- else
271- {
272- elog (WARNING ,"Backup %s has parent %s with status: %s" ,
273- base36enc (backup -> start_time ),parent_backup_id ,
274- status2str (tmp_backup -> status ));
275- }
276- }
277- }
278- pg_free (parent_backup_id );
291+ set_orphan_status (backups ,tmp_backup );
279292tmp_backup = find_parent_full_backup (dest_backup );
280293
281294/* sanity */
@@ -386,30 +399,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
386399}
387400/* Orphanize every OK descendant of corrupted backup */
388401else
389- {
390- char * corrupted_backup_id ;
391- corrupted_backup_id = base36enc_dup (corrupted_backup -> start_time );
392-
393- for (j = 0 ;j < parray_num (backups );j ++ )
394- {
395- pgBackup * backup = (pgBackup * )parray_get (backups ,j );
396-
397- if (is_parent (corrupted_backup -> start_time ,backup , false))
398- {
399- if (backup -> status == BACKUP_STATUS_OK ||
400- backup -> status == BACKUP_STATUS_DONE )
401- {
402- write_backup_status (backup ,BACKUP_STATUS_ORPHAN );
403-
404- elog (WARNING ,"Backup %s is orphaned because his parent %s has status: %s" ,
405- base36enc (backup -> start_time ),
406- corrupted_backup_id ,
407- status2str (corrupted_backup -> status ));
408- }
409- }
410- }
411- free (corrupted_backup_id );
412- }
402+ set_orphan_status (backups ,corrupted_backup );
413403}
414404
415405/*