2017-04-03 16:42:55 +02:00
|
|
|
####################################################################################################################################
|
2017-08-04 22:10:51 +02:00
|
|
|
# Mock Stanza Module Tests
|
2017-04-03 16:42:55 +02:00
|
|
|
####################################################################################################################################
|
2017-08-04 22:10:51 +02:00
|
|
|
package pgBackRestTest::Module::Mock::MockStanzaTest;
|
2017-05-12 22:43:04 +02:00
|
|
|
use parent 'pgBackRestTest::Env::HostEnvTest';
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
|
2017-06-21 14:02:21 +02:00
|
|
|
use pgBackRest::Archive::Info;
|
2017-05-15 22:01:00 +02:00
|
|
|
use pgBackRest::Backup::Info;
|
2017-04-03 16:42:55 +02:00
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::Wait;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::DbVersion;
|
2017-04-03 16:42:55 +02:00
|
|
|
use pgBackRest::InfoCommon;
|
|
|
|
use pgBackRest::Manifest;
|
2017-08-04 22:10:51 +02:00
|
|
|
use pgBackRest::Storage::Base;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Storage::Helper;
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::HostEnvTest;
|
2017-04-03 16:42:55 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRestTest::Common::FileTest;
|
2017-04-03 16:42:55 +02:00
|
|
|
use pgBackRestTest::Common::RunTest;
|
2019-02-24 07:42:41 +02:00
|
|
|
use pgBackRestTest::Common::VmTest;
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2019-02-24 07:42:41 +02:00
|
|
|
foreach my $rhRun
|
|
|
|
(
|
2020-03-06 21:41:03 +02:00
|
|
|
{vm => VM1, remote => false, s3 => false, encrypt => true, compress => GZ},
|
|
|
|
{vm => VM1, remote => true, s3 => true, encrypt => false, compress => GZ},
|
|
|
|
{vm => VM2, remote => false, s3 => true, encrypt => true, compress => GZ},
|
|
|
|
{vm => VM2, remote => true, s3 => false, encrypt => false, compress => GZ},
|
|
|
|
{vm => VM3, remote => false, s3 => false, encrypt => false, compress => GZ},
|
|
|
|
{vm => VM3, remote => true, s3 => true, encrypt => true, compress => GZ},
|
|
|
|
{vm => VM4, remote => false, s3 => true, encrypt => false, compress => GZ},
|
|
|
|
{vm => VM4, remote => true, s3 => false, encrypt => true, compress => GZ},
|
2019-02-24 07:42:41 +02:00
|
|
|
)
|
2017-06-12 16:52:32 +02:00
|
|
|
{
|
2019-02-24 07:42:41 +02:00
|
|
|
# Only run tests for this vm
|
2019-11-02 11:35:48 +02:00
|
|
|
next if ($rhRun->{vm} ne vmTest($self->vm()));
|
2019-02-24 07:42:41 +02:00
|
|
|
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
my $bRemote = $rhRun->{remote};
|
|
|
|
my $bS3 = $rhRun->{s3};
|
|
|
|
my $bEncrypt = $rhRun->{encrypt};
|
2020-03-06 21:41:03 +02:00
|
|
|
my $strCompressType = $rhRun->{compress};
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
2020-03-06 21:41:03 +02:00
|
|
|
if (!$self->begin("remote ${bRemote}, s3 ${bS3}, enc ${bEncrypt}, cmp ${strCompressType}")) {next}
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Create hosts, file object, and config
|
2017-06-12 16:52:32 +02:00
|
|
|
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3) = $self->setup(
|
2020-03-06 21:41:03 +02:00
|
|
|
true, $self->expect(), {bHostBackup => $bRemote, bS3 => $bS3, bRepoEncrypt => $bEncrypt,
|
|
|
|
strCompressType => $strCompressType});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
# Archive and backup info file names
|
|
|
|
my $strArchiveInfoFile = $oHostBackup->repoArchivePath(ARCHIVE_INFO_FILE);
|
|
|
|
my $strArchiveInfoCopyFile = $oHostBackup->repoArchivePath(ARCHIVE_INFO_FILE . INI_COPY_EXT);
|
|
|
|
my $strArchiveInfoOldFile = "${strArchiveInfoFile}.old";
|
|
|
|
my $strArchiveInfoCopyOldFile = "${strArchiveInfoCopyFile}.old";
|
|
|
|
|
|
|
|
my $strBackupInfoFile = $oHostBackup->repoBackupPath(FILE_BACKUP_INFO);
|
|
|
|
my $strBackupInfoCopyFile = $oHostBackup->repoBackupPath(FILE_BACKUP_INFO . INI_COPY_EXT);
|
|
|
|
my $strBackupInfoOldFile = "${strBackupInfoFile}.old";
|
|
|
|
my $strBackupInfoCopyOldFile = "${strBackupInfoCopyFile}.old";
|
|
|
|
|
2017-08-04 22:10:51 +02:00
|
|
|
# Create the stanza
|
2019-08-21 22:26:28 +02:00
|
|
|
$oHostBackup->stanzaCreate('fail on missing control file', {iExpectedExitStatus => ERROR_FILE_MISSING,
|
2020-03-09 23:41:59 +02:00
|
|
|
strOptionalParam => '--no-online --log-level-file=info'});
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Generate pg_control for stanza-create
|
2020-03-06 21:10:09 +02:00
|
|
|
storageTest()->pathCreate(($oHostDbMaster->dbBasePath() . '/' . DB_PATH_GLOBAL), {bCreateParent => true});
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_93);
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-08-04 22:10:51 +02:00
|
|
|
# Fail stanza upgrade before stanza-create has been performed
|
2017-04-03 16:42:55 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$oHostBackup->stanzaUpgrade('fail on stanza not initialized since archive.info is missing',
|
2020-03-09 23:41:59 +02:00
|
|
|
{iExpectedExitStatus => ERROR_FILE_MISSING, strOptionalParam => '--no-online'});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
# Create the stanza successfully without force
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->stanzaCreate('successfully create the stanza', {strOptionalParam => '--no-online'});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2018-02-01 21:12:03 +02:00
|
|
|
# Rerun stanza-create and confirm it does not fail
|
2017-11-06 19:51:12 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->stanzaCreate(
|
2018-02-01 21:12:03 +02:00
|
|
|
'do not fail on rerun of stanza-create - info files exist and DB section ok',
|
2020-03-09 23:41:59 +02:00
|
|
|
{strOptionalParam => '--no-online'});
|
2017-11-06 19:51:12 +02:00
|
|
|
|
|
|
|
# Stanza Create fails when not using force - database mismatch with pg_control file
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Change the database version by copying a new pg_control file
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_94);
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
$oHostBackup->stanzaCreate('fail on database mismatch and warn force option deprecated',
|
2020-03-09 23:41:59 +02:00
|
|
|
{iExpectedExitStatus => ERROR_FILE_INVALID, strOptionalParam => '--no-online --force'});
|
2017-11-06 19:51:12 +02:00
|
|
|
|
|
|
|
# Restore pg_control
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_93);
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Perform a stanza upgrade which will indicate already up to date
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->stanzaUpgrade('already up to date', {strOptionalParam => '--no-online'});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-09-01 18:29:34 +02:00
|
|
|
# Create the wal path
|
|
|
|
my $strWalPath = $oHostDbMaster->dbBasePath() . '/pg_xlog';
|
2020-03-06 21:10:09 +02:00
|
|
|
storageTest()->pathCreate("${strWalPath}/archive_status", {bCreateParent => true});
|
2017-08-04 22:10:51 +02:00
|
|
|
|
|
|
|
# Stanza Create fails - missing archive.info from non-empty archive dir
|
2017-04-03 16:42:55 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-08-04 22:10:51 +02:00
|
|
|
# Generate WAL then push to get valid archive data in the archive directory
|
2017-11-19 03:02:54 +02:00
|
|
|
my $strArchiveFile = $self->walSegment(1, 1, 1);
|
|
|
|
my $strSourceFile = $self->walGenerate($strWalPath, PG_VERSION_93, 1, $strArchiveFile);
|
|
|
|
|
2017-08-04 22:10:51 +02:00
|
|
|
my $strCommand = $oHostDbMaster->backrestExe() . ' --config=' . $oHostDbMaster->backrestConfig() .
|
|
|
|
' --stanza=db archive-push';
|
|
|
|
$oHostDbMaster->executeSimple($strCommand . " ${strSourceFile}", {oLogTest => $self->expect()});
|
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
# With data existing in the archive dir, move the info files and confirm failure
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoFile, $strArchiveInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyFile, $strArchiveInfoCopyOldFile, {bRecurse => false});
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2019-02-24 07:42:41 +02:00
|
|
|
if (!$bEncrypt)
|
2017-11-06 19:51:12 +02:00
|
|
|
{
|
|
|
|
$oHostBackup->stanzaCreate('fail on archive info file missing from non-empty dir',
|
2020-03-09 23:41:59 +02:00
|
|
|
{iExpectedExitStatus => ERROR_FILE_MISSING, strOptionalParam => '--no-online'});
|
2017-11-06 19:51:12 +02:00
|
|
|
}
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
# Restore info files from copy
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoOldFile, $strArchiveInfoFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyOldFile, $strArchiveInfoCopyFile, {bRecurse => false});
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2017-11-17 00:18:51 +02:00
|
|
|
# Just before upgrading push one last WAL on the old version to ensure it can be retrieved later
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-11-19 03:02:54 +02:00
|
|
|
$strArchiveFile = $self->walSegment(1, 1, 2);
|
|
|
|
$strSourceFile = $self->walGenerate($strWalPath, PG_VERSION_93, 1, $strArchiveFile);
|
2017-11-17 00:18:51 +02:00
|
|
|
$oHostDbMaster->executeSimple($strCommand . " ${strSourceFile}", {oLogTest => $self->expect()});
|
|
|
|
|
|
|
|
# Fail on archive push due to mismatch of DB since stanza not upgraded
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-11-19 03:02:54 +02:00
|
|
|
my $strArchiveTestFile = $self->testPath() . '/test-wal';
|
|
|
|
storageTest()->put($strArchiveTestFile, $self->walGenerateContent(PG_VERSION_94));
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Upgrade the DB by copying new pg_control
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_94);
|
2020-03-06 21:10:09 +02:00
|
|
|
forceStorageMode(storageTest(), $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL, '600');
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Fail on attempt to push an archive
|
2017-11-19 03:02:54 +02:00
|
|
|
$oHostDbMaster->archivePush($strWalPath, $strArchiveTestFile, 1, ERROR_ARCHIVE_MISMATCH);
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Perform a successful stanza upgrade noting additional history lines in info files for new version of the database
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2019-08-21 22:26:28 +02:00
|
|
|
# Save a pre-upgrade copy of archive info fo testing db-id mismatch
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyFile, $strArchiveInfoCopyOldFile, {bRecurse => false});
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->stanzaUpgrade('successful upgrade creates additional history', {strOptionalParam => '--no-online'});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-11-17 00:18:51 +02:00
|
|
|
# Make sure that WAL from the old version can still be retrieved
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-11-19 03:02:54 +02:00
|
|
|
# Generate the old pg_control so it looks like the original db has been restored
|
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_93);
|
2017-11-17 00:18:51 +02:00
|
|
|
|
|
|
|
# Attempt to get the last archive log that was pushed to this repo
|
|
|
|
$oHostDbMaster->executeSimple(
|
|
|
|
$oHostDbMaster->backrestExe() . ' --config=' . $oHostDbMaster->backrestConfig() .
|
|
|
|
" --stanza=db archive-get ${strArchiveFile} " . $oHostDbMaster->dbBasePath() . '/pg_xlog/RECOVERYXLOG',
|
|
|
|
{oLogTest => $self->expect()});
|
|
|
|
|
|
|
|
# Copy the new pg_control back so the tests can continue with the upgraded stanza
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_94);
|
2020-03-06 21:10:09 +02:00
|
|
|
forceStorageMode(storageTest(), $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL, '600');
|
2017-11-17 00:18:51 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# After stanza upgrade, make sure archives are pushed to the new db verion-id directory (9.4-2)
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Push a WAL segment so have a valid file in the latest DB archive dir only
|
2017-11-19 03:02:54 +02:00
|
|
|
$oHostDbMaster->archivePush($strWalPath, $strArchiveTestFile, 1);
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->testResult(
|
2020-03-09 23:41:59 +02:00
|
|
|
sub {storageRepo()->list($oHostBackup->repoArchivePath(PG_VERSION_94 . '-2/0000000100000001'))},
|
2020-03-06 21:41:03 +02:00
|
|
|
'000000010000000100000001-' . $self->walGenerateContentChecksum(PG_VERSION_94) . ".${strCompressType}",
|
2017-04-03 16:42:55 +02:00
|
|
|
'check that WAL is in the archive at -2');
|
|
|
|
|
|
|
|
# Create the tablespace directory and perform a backup
|
2019-08-21 22:26:28 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbBasePath() . '/' . DB_PATH_PGTBLSPC);
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->backup(
|
2020-03-09 23:41:59 +02:00
|
|
|
'full', 'create first full backup ', {strOptionalParam => '--repo1-retention-full=2 --no-online'}, false);
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
# Upgrade the stanza
|
2017-08-04 22:10:51 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-04-03 16:42:55 +02:00
|
|
|
# Copy pg_control for 9.5
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_95);
|
2020-03-06 21:10:09 +02:00
|
|
|
forceStorageMode(storageTest(), $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL, '600');
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->stanzaUpgrade('successfully upgrade', {strOptionalParam => '--no-online'});
|
2019-08-21 22:26:28 +02:00
|
|
|
|
|
|
|
# Copy archive.info and restore really old version
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoFile, $strArchiveInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyOldFile, $strArchiveInfoFile, {bRecurse => false});
|
|
|
|
|
|
|
|
# Confirm versions
|
2020-03-09 23:41:59 +02:00
|
|
|
my $oArchiveInfo = new pgBackRest::Archive::Info($oHostBackup->repoArchivePath());
|
|
|
|
my $oBackupInfo = new pgBackRest::Backup::Info($oHostBackup->repoBackupPath());
|
2019-08-26 18:05:36 +02:00
|
|
|
$self->testResult(sub {$oArchiveInfo->test(INFO_ARCHIVE_SECTION_DB, INFO_ARCHIVE_KEY_DB_VERSION, undef,
|
2019-08-21 22:26:28 +02:00
|
|
|
PG_VERSION_93)}, true, 'archive at old pg version');
|
|
|
|
$self->testResult(sub {$oBackupInfo->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_DB_VERSION, undef,
|
|
|
|
PG_VERSION_95)}, true, 'backup at new pg version');
|
2019-06-24 17:59:44 +02:00
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->stanzaUpgrade(
|
2020-03-09 23:41:59 +02:00
|
|
|
'upgrade fails with mismatched db-ids', {iExpectedExitStatus => ERROR_FILE_INVALID, strOptionalParam => '--no-online'});
|
2019-08-21 22:26:28 +02:00
|
|
|
|
|
|
|
# Restore archive.info
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoOldFile, $strArchiveInfoFile, {bRecurse => false});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2019-10-11 18:38:03 +02:00
|
|
|
# Push a WAL and create a backup in the new DB to confirm diff changed to full
|
2017-04-03 16:42:55 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-11-19 03:02:54 +02:00
|
|
|
storageTest()->put($strArchiveTestFile, $self->walGenerateContent(PG_VERSION_95));
|
|
|
|
$oHostDbMaster->archivePush($strWalPath, $strArchiveTestFile, 1);
|
2017-04-07 01:36:37 +02:00
|
|
|
|
|
|
|
# Test backup is changed from type=DIFF to FULL (WARN message displayed)
|
2020-03-09 23:41:59 +02:00
|
|
|
my $oExecuteBackup = $oHostBackup->backupBegin(
|
|
|
|
'diff', 'diff changed to full backup', {strOptionalParam => '--repo1-retention-full=2 --no-online'});
|
2017-04-07 01:36:37 +02:00
|
|
|
$oHostBackup->backupEnd('full', $oExecuteBackup, undef, false);
|
|
|
|
|
2018-01-03 19:23:33 +02:00
|
|
|
# Delete the stanza
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$oHostBackup->stanzaDelete('fail on missing stop file', {iExpectedExitStatus => ERROR_FILE_MISSING});
|
|
|
|
|
|
|
|
$oHostBackup->stop({strStanza => $self->stanza()});
|
|
|
|
$oHostBackup->stanzaDelete('successfully delete the stanza');
|
2017-04-03 16:42:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|