Skip to content

Commit 15228f3

Browse files
committed
[Issue #169] merge: handle the case of crash right after deletion of the target incremental backup. It should be possible to rerun merge by using the backup ID of deleted backup as an argument
1 parent 7b342e3 commit 15228f3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/merge.c

+26
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ do_merge(time_t backup_id)
106106
}
107107
}
108108

109+
/*
110+
* Handle the case of crash right after deletion of the target
111+
* incremental backup. We still can recover from this.
112+
* Iterate over backups and look for the FULL backup with
113+
* MERGED status, that has merge-target-id eqial to backup_id.
114+
*/
115+
if (dest_backup == NULL)
116+
{
117+
for (i = 0; i < parray_num(backups); i++)
118+
{
119+
pgBackup *backup = (pgBackup *) parray_get(backups, i);
120+
121+
if (backup->status == BACKUP_STATUS_MERGED &&
122+
backup->merge_dest_backup == backup_id)
123+
{
124+
dest_backup = backup;
125+
break;
126+
}
127+
}
128+
}
129+
109130
if (dest_backup == NULL)
110131
elog(ERROR, "Target backup %s was not found", base36enc(backup_id));
111132

@@ -776,6 +797,11 @@ merge_chain(parray *parent_chain, pgBackup *full_backup, pgBackup *dest_backup)
776797
full_backup->root_dir, destination_path, strerror(errno));
777798
}
778799

800+
/* If we crash here, it will produce full backup in MERGED
801+
* status, located in directory with wrong backup id.
802+
* It should not be a problem.
803+
*/
804+
779805
/*
780806
* Merging finished, now we can safely update ID of the FULL backup
781807
*/

0 commit comments

Comments
 (0)