1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-10-30 23:37:45 +02:00

Error on db history mismatch when expiring.

Amend commit 434cd832 to error when the db history in archive.info and backup.info do not match.

The Perl code would attempt to reconcile the history by matching on system id and version but we are not planning to migrate that code to C.  It's possible that there are users with mismatches but if so they should have been getting errors from info for the last six months.  It's easy enough to manually fix these files if there are any mismatches in the field.

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang
2019-06-24 11:59:44 -04:00
committed by David Steele
parent 039e515a31
commit b498188f01
6 changed files with 320 additions and 65 deletions

View File

@@ -292,6 +292,8 @@ sub run
# Remove the archive info file and force reconstruction
if (!$bEncrypt)
{
forceStorageMove(storageRepo(), $strArchiveInfoFile, $strArchiveInfoOldFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strArchiveInfoCopyFile, $strArchiveInfoCopyOldFile, {bRecurse => false});
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
@@ -303,6 +305,8 @@ sub run
#--------------------------------------------------------------------------------------------------------------------------
if (!$bEncrypt)
{
forceStorageMove(storageRepo(), $strBackupInfoFile, $strBackupInfoOldFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strBackupInfoCopyFile, $strBackupInfoCopyOldFile, {bRecurse => false});
forceStorageRemove(storageRepo(), $strBackupInfoFile);
forceStorageRemove(storageRepo(), $strBackupInfoCopyFile);
@@ -310,13 +314,15 @@ sub run
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
}
# Confirm successful backup at db-1 although archive at db-2
# Confirm successful backup at db-1 although archive at db-2 and format error thrown by expire (if not encrypted) since
# archive.info history and backup.info history are mismatched
#--------------------------------------------------------------------------------------------------------------------------
# Create the tablespace directory and perform a backup
storageTest()->pathCreate($oHostDbMaster->dbBasePath() . '/' . DB_PATH_PGTBLSPC);
$oHostBackup->backup(
'full', 'create first full backup ',
{strOptionalParam => '--repo1-retention-full=2 --no-' . cfgOptionName(CFGOPT_ONLINE)}, false);
{iExpectedExitStatus => $bEncrypt ? undef : ERROR_FORMAT,
strOptionalParam => '--repo1-retention-full=2 --no-' . cfgOptionName(CFGOPT_ONLINE)}, false);
# Stanza Create fails when not using force - no backup.info but backup exists
#--------------------------------------------------------------------------------------------------------------------------
@@ -340,31 +346,45 @@ sub run
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE),
iExpectedExitStatus => $bEncrypt ? ERROR_FILE_MISSING : undef});
# Encrypted info files could not be reconstructed above so just copy them back
if ($bEncrypt)
{
forceStorageMove(storageRepo(), $strBackupInfoOldFile, $strBackupInfoFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strBackupInfoCopyOldFile, $strBackupInfoCopyFile, {bRecurse => false});
}
# Test archive dir version XX.Y-Z ensuring sort order of db ids is reconstructed correctly from the directory db-id value
#--------------------------------------------------------------------------------------------------------------------------
# Create the 10.0-3 directory and copy a WAL file to it (something that has a different system id)
forceStorageMode(storageRepo(), STORAGE_REPO_ARCHIVE, '770');
storageRepo()->pathCreate(STORAGE_REPO_ARCHIVE . '/10.0-3/0000000100000001', {bCreateParent => true});
storageRepo()->put(
storageRepo()->openWrite(
STORAGE_REPO_ARCHIVE . '/10.0-3/0000000100000001/000000010000000100000001',
{strCipherPass => $oHostBackup->cipherPassArchive()}),
$self->walGenerateContent(PG_VERSION_94));
forceStorageOwner(storageRepo(), STORAGE_REPO_ARCHIVE . '/10.0-3', $oHostBackup->userGet(), {bRecurse => true});
# Copy old backup.info files back to avoid history mismatch
forceStorageMove(storageRepo(), $strBackupInfoOldFile, $strBackupInfoFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strBackupInfoCopyOldFile, $strBackupInfoCopyFile, {bRecurse => false});
# Copy pg_control for 9.5
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_95);
forceStorageMode(storageDb(), $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL, '600');
# Test archive dir version XX.Y-Z ensuring sort order of db ids is reconstructed correctly from the directory db-id value.
# Not testing with encryption since unnecessary and copying files around in this case is burdensome.
#--------------------------------------------------------------------------------------------------------------------------
if (!$bEncrypt)
{
# Create the 10-3 directory and copy a WAL file to it (with a different system id than what it will be upgraded to)
forceStorageMode(storageRepo(), STORAGE_REPO_ARCHIVE, '770');
storageRepo()->pathCreate(STORAGE_REPO_ARCHIVE . '/10-3/0000000100000001', {bCreateParent => true});
storageRepo()->put(
storageRepo()->openWrite(
STORAGE_REPO_ARCHIVE . '/10-3/0000000100000001/000000010000000100000001',
{strCipherPass => $oHostBackup->cipherPassArchive()}),
$self->walGenerateContent(PG_VERSION_10));
forceStorageOwner(storageRepo(), STORAGE_REPO_ARCHIVE . '/10-3', $oHostBackup->userGet(), {bRecurse => true});
# Make sure the archive.info has the history in the db-id order such that 10 is before 9.5.
$oHostBackup->stanzaUpgrade(
'successfully upgrade with XX.Y-Z',
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
# Remove the 10-3 directory and copy old archive.info file back. Recreate so archive.info and backup.info files match.
forceStorageRemove(storageRepo(), STORAGE_REPO_ARCHIVE . '/10-3', {bRecurse => true});
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
forceStorageMove(storageRepo(), $strArchiveInfoOldFile, $strArchiveInfoFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strArchiveInfoCopyOldFile, $strArchiveInfoCopyFile, {bRecurse => false});
}
$oHostBackup->stanzaUpgrade(
'successfully upgrade with XX.Y-Z', {strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
'successfully upgrade - no info file mismatch',
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
# Push a WAL and create a backup in the new DB to confirm diff changed to full and info command displays the JSON correctly
#--------------------------------------------------------------------------------------------------------------------------