Skip to content

Commit 8c74cf7

Browse files
committed
If WAL segment is lost or broken, update status of the corresponding backup to CORRUPT
1 parent 0f212e0 commit 8c74cf7

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

parsexlog.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ extractPageMap(const char *archivedir, XLogRecPtr startpoint, TimeLineID tli,
155155
}
156156
}
157157

158+
/* TODO Add comment, review */
158159
void
159160
validate_wal(pgBackup *backup,
160161
const char *archivedir,
@@ -245,6 +246,10 @@ validate_wal(pgBackup *backup,
245246
{
246247
if (xlogfpath[0] != 0)
247248
{
249+
/* Update backup status */
250+
backup->status = BACKUP_STATUS_CORRUPT;
251+
pgBackupWriteBackupControlFile(backup);
252+
248253
/* XLOG reader couldnt read WAL segment */
249254
if (!xlogexists)
250255
elog(WARNING, "WAL segment \"%s\" is absent", xlogfpath);
@@ -254,11 +259,17 @@ validate_wal(pgBackup *backup,
254259
}
255260

256261
if (!got_endpoint)
262+
{
263+
/* Update backup status */
264+
backup->status = BACKUP_STATUS_CORRUPT;
265+
pgBackupWriteBackupControlFile(backup);
266+
257267
elog(ERROR, "there are not enough WAL records to restore from %X/%X to %X/%X",
258268
(uint32) (backup->start_lsn >> 32),
259269
(uint32) (backup->start_lsn),
260270
(uint32) (backup->stop_lsn >> 32),
261271
(uint32) (backup->stop_lsn));
272+
}
262273
else
263274
{
264275
if (target_time > 0)

restore.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ do_restore_or_validate(time_t target_backup_id,
122122
timelines = readTimeLineHistory_probackup(target_tli);
123123
}
124124

125-
/* Find backup range we should restore. */
125+
/* Find backup range we should restore or validate. */
126126
for (i = 0; i < parray_num(backups); i++)
127127
{
128128
current_backup = (pgBackup *) parray_get(backups, i);
@@ -217,40 +217,42 @@ do_restore_or_validate(time_t target_backup_id,
217217
pgBackupValidate(backup);
218218
}
219219

220+
/*
221+
* Validate corresponding WAL files.
222+
* TODO Shouldn't we pass recovery_target_timeline as last argument?
223+
*/
224+
validate_wal(dest_backup, arclog_path, rt->recovery_target_time,
225+
rt->recovery_target_xid, base_full_backup->tli);
226+
227+
220228
/* We ensured that all backups are valid, now restore if required */
221229
if (is_restore)
222230
{
231+
pgBackup *backup;
223232
for (i = base_full_backup_index; i >= dest_backup_index; i--)
224233
{
225-
pgBackup *backup = (pgBackup *) parray_get(backups, i);
234+
backup = (pgBackup *) parray_get(backups, i);
226235
if (backup->status == BACKUP_STATUS_OK)
227236
restore_backup(backup);
228237
else
229238
elog(ERROR, "backup %s is not valid",
230239
base36enc(backup->start_time));
231240
}
232-
}
233241

234-
/*
235-
* Delete files which are not in dest backup file list. Files which were
236-
* deleted between previous and current backup are not in the list.
237-
*/
238-
if (is_restore)
239-
{
240-
pgBackup *dest_backup = (pgBackup *) parray_get(backups, dest_backup_index);
242+
/*
243+
* Delete files which are not in dest backup file list. Files which were
244+
* deleted between previous and current backup are not in the list.
245+
*/
241246
if (dest_backup->backup_mode != BACKUP_MODE_FULL)
242247
remove_deleted_files(dest_backup);
243-
}
244248

245-
if (!dest_backup->stream
246-
|| (target_time != NULL || target_xid != NULL))
247-
{
248-
if (is_restore)
249+
/* TODO Add comment */
250+
if (!dest_backup->stream
251+
|| (target_time != NULL || target_xid != NULL))
252+
{
249253
create_recovery_conf(target_backup_id, target_time, target_xid,
250254
target_inclusive, target_tli);
251-
else
252-
validate_wal(dest_backup, arclog_path, rt->recovery_target_time,
253-
rt->recovery_target_xid, base_full_backup->tli);
255+
}
254256
}
255257

256258
/* cleanup */

0 commit comments

Comments
 (0)