Skip to content

Commit ee6bab4

Browse files
za-arthurArthur Zakirov
authored and
Arthur Zakirov
committed
PGPRO-1892: Add validation of merged backups
1 parent fcc4ed7 commit ee6bab4

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

Diff for: src/merge.c

+31-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ do_merge(time_t backup_id)
5959
if (instance_name == NULL)
6060
elog(ERROR, "required parameter is not specified: --instance");
6161

62-
elog(LOG, "Merge started");
62+
elog(INFO, "Merge started");
6363

6464
catalog_lock();
6565

@@ -129,17 +129,21 @@ do_merge(time_t backup_id)
129129
*/
130130
for (i = full_backup_idx; i > dest_backup_idx; i--)
131131
{
132-
pgBackup *to_backup = (pgBackup *) parray_get(backups, i);
133132
pgBackup *from_backup = (pgBackup *) parray_get(backups, i - 1);
134133

135-
merge_backups(to_backup, from_backup);
134+
full_backup = (pgBackup *) parray_get(backups, i);
135+
merge_backups(full_backup, from_backup);
136136
}
137137

138+
pgBackupValidate(full_backup);
139+
if (full_backup->status == BACKUP_STATUS_CORRUPT)
140+
elog(ERROR, "Merging of backup %s failed", base36enc(backup_id));
141+
138142
/* cleanup */
139143
parray_walk(backups, pgBackupFree);
140144
parray_free(backups);
141145

142-
elog(LOG, "Merge completed");
146+
elog(INFO, "Merge of backup %s completed", base36enc(backup_id));
143147
}
144148

145149
/*
@@ -167,6 +171,28 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
167171

168172
elog(INFO, "Merging backup %s with backup %s", from_backup_id, to_backup_id);
169173

174+
/*
175+
* Validate to_backup only if it is BACKUP_STATUS_OK. If it has
176+
* BACKUP_STATUS_MERGING status then it isn't valid backup until merging
177+
* finished.
178+
*/
179+
if (to_backup->status == BACKUP_STATUS_OK)
180+
{
181+
pgBackupValidate(to_backup);
182+
if (to_backup->status == BACKUP_STATUS_CORRUPT)
183+
elog(ERROR, "Interrupt merging");
184+
}
185+
186+
/*
187+
* It is OK to validate from_backup if it has BACKUP_STATUS_OK or
188+
* BACKUP_STATUS_MERGING status.
189+
*/
190+
Assert(from_backup->status == BACKUP_STATUS_OK ||
191+
from_backup->status == BACKUP_STATUS_MERGING);
192+
pgBackupValidate(from_backup);
193+
if (from_backup->status == BACKUP_STATUS_CORRUPT)
194+
elog(ERROR, "Interrupt merging");
195+
170196
/*
171197
* Previous merging was interrupted during deleting source backup. It is
172198
* safe just to delete it again.
@@ -302,6 +328,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
302328
/*
303329
* Rename FULL backup directory.
304330
*/
331+
elog(INFO, "Rename %s to %s", to_backup_id, from_backup_id);
305332
if (rename(to_backup_path, from_backup_path) == -1)
306333
elog(ERROR, "Could not rename directory \"%s\" to \"%s\": %s",
307334
to_backup_path, from_backup_path, strerror(errno));

Diff for: tests/merge.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,6 @@ def test_continue_failed_merge_with_corrupted_delta_backup(self):
694694

695695
gdb._execute('signal SIGKILL')
696696

697-
print(self.show_pb(backup_dir, as_text=True, as_json=False))
698-
699697
# CORRUPT incremental backup
700698
# read block from future
701699
# block_size + backup_header = 8200
@@ -723,16 +721,14 @@ def test_continue_failed_merge_with_corrupted_delta_backup(self):
723721
"Output: {0} \n CMD: {1}".format(
724722
repr(self.output), self.cmd))
725723
except ProbackupException as e:
726-
self.assertEqual(
727-
e.message,
728-
'INSERT ERROR MESSAGE HERE\n',
724+
self.assertTrue(
725+
"WARNING: Backup {0} data files are corrupted".format(
726+
backup_id) in e.message and
727+
"ERROR: Merging of backup {0} failed".format(
728+
backup_id) in e.message,
729729
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
730730
repr(e.message), self.cmd))
731731

732-
# Drop node and restore it
733-
node.cleanup()
734-
self.restore_node(backup_dir, 'node', node)
735-
736732
# Clean after yourself
737733
self.del_test_dir(module_name, fname)
738734

0 commit comments

Comments
 (0)