Skip to content

Commit f685305

Browse files
committed
Merge branch 'pgpro-1504'
2 parents 541195b + fb88c42 commit f685305

File tree

6 files changed

+397
-82
lines changed

6 files changed

+397
-82
lines changed

src/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ typedef enum ProbackupSubcmd
151151

152152

153153
/* special values of pgBackup fields */
154-
#define INVALID_BACKUP_ID 0
154+
#define INVALID_BACKUP_ID 0 /* backup ID is not provided by user */
155155
#define BYTES_INVALID (-1)
156156

157157
typedef struct pgBackupConfig

src/restore.c

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/validate.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,28 @@ pgBackupValidate(pgBackup *backup)
3939
validate_files_args *validate_threads_args[num_threads];
4040
int i;
4141

42+
/* Revalidation is attempted for DONE, ORPHAN and CORRUPT backups */
4243
if (backup->status != BACKUP_STATUS_OK &&
43-
backup->status != BACKUP_STATUS_DONE)
44+
backup->status != BACKUP_STATUS_DONE &&
45+
backup->status != BACKUP_STATUS_ORPHAN &&
46+
backup->status != BACKUP_STATUS_CORRUPT)
4447
{
45-
elog(INFO, "Backup %s has status %s. Skip validation.",
48+
elog(WARNING, "Backup %s has status %s. Skip validation.",
4649
base36enc(backup->start_time), status2str(backup->status));
50+
corrupted_backup_found = true;
4751
return;
4852
}
4953

50-
elog(INFO, "Validating backup %s", base36enc(backup->start_time));
54+
if (backup->status == BACKUP_STATUS_OK || backup->status == BACKUP_STATUS_DONE)
55+
elog(INFO, "Validating backup %s", base36enc(backup->start_time));
56+
else
57+
elog(INFO, "Revalidating backup %s", base36enc(backup->start_time));
5158

5259
if (backup->backup_mode != BACKUP_MODE_FULL &&
5360
backup->backup_mode != BACKUP_MODE_DIFF_PAGE &&
5461
backup->backup_mode != BACKUP_MODE_DIFF_PTRACK &&
5562
backup->backup_mode != BACKUP_MODE_DIFF_DELTA)
56-
elog(INFO, "Invalid backup_mode of backup %s", base36enc(backup->start_time));
63+
elog(WARNING, "Invalid backup_mode of backup %s", base36enc(backup->start_time));
5764

5865
pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR);
5966
pgBackupGetPath(backup, path, lengthof(path), DATABASE_FILE_LIST);
@@ -227,7 +234,7 @@ do_validate_all(void)
227234

228235
if (corrupted_backup_found)
229236
{
230-
elog(INFO, "Some backups are not valid");
237+
elog(WARNING, "Some backups are not valid");
231238
return 1;
232239
}
233240
else
@@ -295,7 +302,7 @@ do_validate_instance(void)
295302
0, base_full_backup->tli);
296303
}
297304
/* Mark every incremental backup between corrupted backup and nearest FULL backup as orphans */
298-
if (current_backup->status != BACKUP_STATUS_OK)
305+
if (current_backup->status == BACKUP_STATUS_CORRUPT)
299306
{
300307
int j;
301308
corrupted_backup_found = true;
@@ -309,7 +316,6 @@ do_validate_instance(void)
309316
continue;
310317
else
311318
{
312-
313319
backup->status = BACKUP_STATUS_ORPHAN;
314320
pgBackupWriteBackupControlFile(backup);
315321

tests/backup_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_incremental_backup_corrupt_full(self):
204204
file) in e.message and
205205
"WARNING: Backup {0} data files are corrupted\n".format(
206206
backup_id) in e.message and
207-
"INFO: Some backups are not valid\n" in e.message,
207+
"WARNING: Some backups are not valid\n" in e.message,
208208
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
209209
repr(e.message), self.cmd))
210210

tests/helpers/ptrack_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ def show_pb(
636636
header_element.rstrip() for header_element in header_split
637637
]
638638
for backup_record in body:
639+
backup_record = backup_record.rstrip()
639640
# split list with str for every backup record element
640641
backup_record_split = re.split(" +", backup_record)
641642
# Remove empty items

0 commit comments

Comments
 (0)