1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-08 03:22:25 +03:00

Require PostgreSQL catalog version when instantiating a Manifest object (and not loading it from disk).

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang
2018-07-16 17:25:15 -04:00
committed by David Steele
parent 4e38cbaea9
commit 0acf705416
13 changed files with 125 additions and 85 deletions

View File

@@ -142,7 +142,6 @@ sub run
my $strBackupLabel = backupLabelFormat(CFGOPTVAL_BACKUP_TYPE_FULL, undef, 1482000000);
my $strBackupPath = storageRepo->pathGet(STORAGE_REPO_BACKUP . "/${strBackupLabel}");
my $strBackupManifestFile = "$strBackupPath/" . FILE_MANIFEST;
my $iDbCatalogVersion = 201409291;
my $lTime = time() - 10000;
my $strTest = 'test';
@@ -151,6 +150,7 @@ sub run
# Section: backup:db
$oManifestBase->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_94);
$oManifestBase->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef, $self->dbCatalogVersion(PG_VERSION_94));
# Section: target:path
my $hDefault = {};
$oManifestBase->set(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA, undef, $hDefault);
@@ -166,15 +166,28 @@ sub run
################################################################################################################################
if ($self->begin('new()'))
{
# Missing DB version
# Missing DB and DB Catalog version
#---------------------------------------------------------------------------------------------------------------------------
$self->testException(sub {(new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false}))}, ERROR_ASSERT,
'strDbVersion must be provided with bLoad = false');
'strDbVersion and iDbCatalogVersion must be provided with bLoad = false');
# Missing DB version
#---------------------------------------------------------------------------------------------------------------------------
$self->testException(sub {(new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)}))}, ERROR_ASSERT,
'strDbVersion and iDbCatalogVersion must be provided with bLoad = false');
# Missing DB Catalog version
#---------------------------------------------------------------------------------------------------------------------------
$self->testException(sub {(new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false,
strDbVersion => PG_VERSION_94}))}, ERROR_ASSERT,
'strDbVersion and iDbCatalogVersion must be provided with bLoad = false');
# Successfully instantiate
#---------------------------------------------------------------------------------------------------------------------------
my $oManifest = $self->testResult(sub {(new pgBackRest::Manifest($strBackupManifestFile,
{bLoad => false, strDbVersion => PG_VERSION_94}))}, "[object]", 'manifest instantiated');
{bLoad => false, strDbVersion => PG_VERSION_94, iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)}))},
"[object]", 'manifest instantiated');
# Initialize
#---------------------------------------------------------------------------------------------------------------------------
@@ -207,7 +220,8 @@ sub run
################################################################################################################################
if ($self->begin('build()'))
{
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
# Build error if offline = true and no tablespace path
#---------------------------------------------------------------------------------------------------------------------------
@@ -391,8 +405,11 @@ sub run
my $oManifestExpectedUnskip = dclone($oManifestExpected);
# Change DB version to 93
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_93});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_93,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_93)});
$oManifestExpectedUnskip->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_93);
$oManifestExpectedUnskip->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef,
$self->dbCatalogVersion(PG_VERSION_93));
# Update expected manifest
$oManifestExpectedUnskip->set(MANIFEST_SECTION_TARGET_FILE . ":default", MANIFEST_SUBKEY_MODE, undef, MODE_0600);
@@ -413,8 +430,11 @@ sub run
$self->testResult(sub {$self->manifestCompare($oManifestExpectedUnskip, $oManifest)}, "", 'unskip 94 directories');
# Change DB version to 91
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_91});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_91,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_91)});
$oManifestExpectedUnskip->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_91);
$oManifestExpectedUnskip->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef,
$self->dbCatalogVersion(PG_VERSION_91));
$oManifestExpectedUnskip->set(MANIFEST_SECTION_TARGET_FILE, MANIFEST_PATH_PGSNAPSHOTS . '/' . BOGUS,
MANIFEST_SUBKEY_SIZE, 0);
@@ -425,8 +445,11 @@ sub run
$self->testResult(sub {$self->manifestCompare($oManifestExpectedUnskip, $oManifest)}, "", 'unskip 92 directories');
# Change DB version to 90
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_90});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_90,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_90)});
$oManifestExpectedUnskip->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_90);
$oManifestExpectedUnskip->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef,
$self->dbCatalogVersion(PG_VERSION_90));
$oManifestExpectedUnskip->set(MANIFEST_SECTION_TARGET_FILE, MANIFEST_PATH_PGSERIAL . '/' . BOGUS,
MANIFEST_SUBKEY_SIZE, 0);
@@ -437,8 +460,11 @@ sub run
$self->testResult(sub {$self->manifestCompare($oManifestExpectedUnskip, $oManifest)}, "", 'unskip 91 directories');
# Change DB version to 84
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_84});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_84,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_84)});
$oManifestExpectedUnskip->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_84);
$oManifestExpectedUnskip->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef,
$self->dbCatalogVersion(PG_VERSION_84));
$oManifestExpectedUnskip->set(MANIFEST_SECTION_TARGET_FILE, MANIFEST_PATH_PGNOTIFY . '/' . BOGUS,
MANIFEST_SUBKEY_SIZE, 0);
@@ -449,8 +475,11 @@ sub run
$self->testResult(sub {$self->manifestCompare($oManifestExpectedUnskip, $oManifest)}, "", 'unskip 90 directories');
# Change DB version to 83
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_83});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_83,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_83)});
$oManifestExpectedUnskip->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_83);
$oManifestExpectedUnskip->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef,
$self->dbCatalogVersion(PG_VERSION_83));
$oManifestExpectedUnskip->set(MANIFEST_SECTION_TARGET_FILE, MANIFEST_PATH_PGSTATTMP . '/' . BOGUS,
MANIFEST_SUBKEY_SIZE, 0);
@@ -461,7 +490,8 @@ sub run
$self->testResult(sub {$self->manifestCompare($oManifestExpectedUnskip, $oManifest)}, "", 'unskip 84 directories');
# Reset Manifest for next tests
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
$oManifest->build(storageDb(), $self->{strDbPath}, undef, true);
$self->testResult(sub {$self->manifestCompare($oManifestExpected, $oManifest)}, "", 'manifest reset');
@@ -498,9 +528,6 @@ sub run
'tablespace symlink ../base destination must not be in $PGDATA');
testFileRemove("${strTblSpcPath}/${strTblspcId}");
# Create the catalog key for the tablespace construction
$oManifest->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef, $iDbCatalogVersion);
# Invalid absolute tablespace is $self->{strDbPath} . /base
# INVESTIGATE: But this should fail because the link points to a directory in pg_data but instead it passes the
# index($hManifest->{$strName}{link_destination}, '/') != 0 and then fails later. It WILL fail "destination must not be in
@@ -536,11 +563,8 @@ sub run
testFileRemove("${strTblSpcPath}/${strTblspcId}");
# Reload the manifest otherwise it will contain invalid data from the above exception tests
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
# Set the required db catalog version for tablespaces
$oManifest->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef, $iDbCatalogVersion);
$oManifestExpected->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef, $iDbCatalogVersion);
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
# Create a valid symlink pg_tblspc/1 to tablespace/ts1/1 directory
my $strTablespaceOid = '1';
@@ -594,11 +618,13 @@ sub run
# Reload the manifest with version < 9.0
#---------------------------------------------------------------------------------------------------------------------------
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_84});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_84,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_84)});
# Catalog not stored in < 9.0
$oManifestExpected->remove(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG);
$oManifestExpected->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_84);
$oManifestExpected->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef,
$self->dbCatalogVersion(PG_VERSION_84));
# Add unskip directories
$oManifestExpected->set(MANIFEST_SECTION_TARGET_FILE, MANIFEST_PATH_PGDYNSHMEM . '/' . BOGUS,
@@ -647,7 +673,8 @@ sub run
################################################################################################################################
if ($self->begin('get/set'))
{
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
# SubKey required but has not been set
#---------------------------------------------------------------------------------------------------------------------------
@@ -715,17 +742,15 @@ sub run
# repoPathGet - fully qualified tablespace target
#---------------------------------------------------------------------------------------------------------------------------
# Set the catalog for the DB since that is what is expected to be returned
$oManifest->numericSet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG, undef, $iDbCatalogVersion);
$self->testResult(sub {$oManifest->tablespacePathGet()}, "PG_" . PG_VERSION_94 . "_" . $iDbCatalogVersion,
'tablespacePathGet()');
$self->testResult(sub {$oManifest->tablespacePathGet()}, "PG_" . PG_VERSION_94 . "_" .
$self->dbCatalogVersion(PG_VERSION_94), 'tablespacePathGet()');
$oManifest->set(MANIFEST_SECTION_BACKUP_TARGET, $strTablespace, MANIFEST_SUBKEY_TABLESPACE_ID, $strTablespaceId);
$oManifest->set(MANIFEST_SECTION_BACKUP_TARGET, $strTablespace, MANIFEST_SUBKEY_TABLESPACE_NAME, $strTablespaceName);
$oManifest->set(MANIFEST_SECTION_BACKUP_TARGET, $strTablespace, MANIFEST_SUBKEY_TYPE, MANIFEST_VALUE_LINK);
$self->testResult(sub {$oManifest->repoPathGet($strTablespace, BOGUS)}, $strTablespace . "/PG_" . PG_VERSION_94 . "_" .
$iDbCatalogVersion . "/" . BOGUS, 'repoPathGet() - tablespace valid with subpath');
$self->dbCatalogVersion(PG_VERSION_94) . "/" . BOGUS, 'repoPathGet() - tablespace valid with subpath');
# Set the DB version to < 9.0 - there is no special sudirectory in earlier PG versions
$oManifest->set(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION, undef, PG_VERSION_84);
@@ -749,7 +774,8 @@ sub run
################################################################################################################################
if ($self->begin('isTarget - exceptions'))
{
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
# Target not defined
#---------------------------------------------------------------------------------------------------------------------------
@@ -770,7 +796,8 @@ sub run
{
# dbVersion, xactPath and walPath - PG < 10
#---------------------------------------------------------------------------------------------------------------------------
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
$self->testResult(sub {$oManifest->dbVersion()}, PG_VERSION_94, 'dbVersion < 10');
$self->testResult(sub {$oManifest->xactPath()}, 'pg_clog', ' xactPath - pg_clog');
@@ -778,7 +805,8 @@ sub run
# dbVersion, xactPath and walPath - PG >= 10
#---------------------------------------------------------------------------------------------------------------------------
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_10});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_10,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_10)});
$self->testResult(sub {$oManifest->dbVersion()}, PG_VERSION_10, 'dbVersion >= 10');
$self->testResult(sub {$oManifest->xactPath()}, 'pg_xact', ' xactPath - pg_xact');
@@ -788,7 +816,8 @@ sub run
################################################################################################################################
if ($self->begin('validate()'))
{
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
# Set a target:file with only a timestamp - fail size not set
#---------------------------------------------------------------------------------------------------------------------------
@@ -816,7 +845,8 @@ sub run
################################################################################################################################
if ($self->begin('future file and last manifest'))
{
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
# Create expected manifest from base
my $oManifestExpected = dclone($oManifestBase);
@@ -861,7 +891,8 @@ sub run
$lTime);
# Create a new manifest
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
$oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
$self->testResult(sub {$oManifest->build(storageDb(), $self->{strDbPath}, $oLastManifest, true)}, "[undef]",
'last manifest future timestamp warning', {strLogExpect =>
@@ -957,7 +988,8 @@ sub run
################################################################################################################################
if ($self->begin('fileAdd()'))
{
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94});
my $oManifest = new pgBackRest::Manifest($strBackupManifestFile, {bLoad => false, strDbVersion => PG_VERSION_94,
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_94)});
my $oManifestExpected = dclone($oManifestBase);
$oManifest->build(storageDb(), $self->{strDbPath}, undef, true);