1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-03-26 22:20:10 +02:00

PGPRO-1892: Add validation of merged backups

This commit is contained in:
Arthur Zakirov 2018-11-09 18:32:37 +03:00 committed by Arthur Zakirov
parent fcc4ed7439
commit ee6bab40a9
2 changed files with 36 additions and 13 deletions

View File

@ -59,7 +59,7 @@ do_merge(time_t backup_id)
if (instance_name == NULL)
elog(ERROR, "required parameter is not specified: --instance");
elog(LOG, "Merge started");
elog(INFO, "Merge started");
catalog_lock();
@ -129,17 +129,21 @@ do_merge(time_t backup_id)
*/
for (i = full_backup_idx; i > dest_backup_idx; i--)
{
pgBackup *to_backup = (pgBackup *) parray_get(backups, i);
pgBackup *from_backup = (pgBackup *) parray_get(backups, i - 1);
merge_backups(to_backup, from_backup);
full_backup = (pgBackup *) parray_get(backups, i);
merge_backups(full_backup, from_backup);
}
pgBackupValidate(full_backup);
if (full_backup->status == BACKUP_STATUS_CORRUPT)
elog(ERROR, "Merging of backup %s failed", base36enc(backup_id));
/* cleanup */
parray_walk(backups, pgBackupFree);
parray_free(backups);
elog(LOG, "Merge completed");
elog(INFO, "Merge of backup %s completed", base36enc(backup_id));
}
/*
@ -167,6 +171,28 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
elog(INFO, "Merging backup %s with backup %s", from_backup_id, to_backup_id);
/*
* Validate to_backup only if it is BACKUP_STATUS_OK. If it has
* BACKUP_STATUS_MERGING status then it isn't valid backup until merging
* finished.
*/
if (to_backup->status == BACKUP_STATUS_OK)
{
pgBackupValidate(to_backup);
if (to_backup->status == BACKUP_STATUS_CORRUPT)
elog(ERROR, "Interrupt merging");
}
/*
* It is OK to validate from_backup if it has BACKUP_STATUS_OK or
* BACKUP_STATUS_MERGING status.
*/
Assert(from_backup->status == BACKUP_STATUS_OK ||
from_backup->status == BACKUP_STATUS_MERGING);
pgBackupValidate(from_backup);
if (from_backup->status == BACKUP_STATUS_CORRUPT)
elog(ERROR, "Interrupt merging");
/*
* Previous merging was interrupted during deleting source backup. It is
* safe just to delete it again.
@ -302,6 +328,7 @@ delete_source_backup:
/*
* Rename FULL backup directory.
*/
elog(INFO, "Rename %s to %s", to_backup_id, from_backup_id);
if (rename(to_backup_path, from_backup_path) == -1)
elog(ERROR, "Could not rename directory \"%s\" to \"%s\": %s",
to_backup_path, from_backup_path, strerror(errno));

View File

@ -694,8 +694,6 @@ class MergeTest(ProbackupTest, unittest.TestCase):
gdb._execute('signal SIGKILL')
print(self.show_pb(backup_dir, as_text=True, as_json=False))
# CORRUPT incremental backup
# read block from future
# block_size + backup_header = 8200
@ -723,16 +721,14 @@ class MergeTest(ProbackupTest, unittest.TestCase):
"Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertEqual(
e.message,
'INSERT ERROR MESSAGE HERE\n',
self.assertTrue(
"WARNING: Backup {0} data files are corrupted".format(
backup_id) in e.message and
"ERROR: Merging of backup {0} failed".format(
backup_id) in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(e.message), self.cmd))
# Drop node and restore it
node.cleanup()
self.restore_node(backup_dir, 'node', node)
# Clean after yourself
self.del_test_dir(module_name, fname)