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;
|
|
|
|
use pgBackRest::Config::Config;
|
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-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
2017-08-04 22:10:51 +02:00
|
|
|
use pgBackRest::Storage::Base;
|
|
|
|
use pgBackRest::Storage::Filter::Gzip;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Storage::Helper;
|
2017-04-03 16:42:55 +02:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Archive and backup info file names
|
|
|
|
my $strArchiveInfoFile = STORAGE_REPO_ARCHIVE . qw{/} . ARCHIVE_INFO_FILE;
|
|
|
|
my $strArchiveInfoCopyFile = STORAGE_REPO_ARCHIVE . qw{/} . ARCHIVE_INFO_FILE . INI_COPY_EXT;
|
|
|
|
my $strArchiveInfoOldFile = "${strArchiveInfoFile}.old";
|
|
|
|
my $strArchiveInfoCopyOldFile = "${strArchiveInfoCopyFile}.old";
|
|
|
|
|
|
|
|
my $strBackupInfoFile = STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO;
|
|
|
|
my $strBackupInfoCopyFile = STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO . INI_COPY_EXT;
|
|
|
|
my $strBackupInfoOldFile = "${strBackupInfoFile}.old";
|
|
|
|
my $strBackupInfoCopyOldFile = "${strBackupInfoCopyFile}.old";
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bS3 (false, true)
|
|
|
|
{
|
2017-08-04 22:10:51 +02:00
|
|
|
foreach my $bRemote ($bS3 ? (false) : (false, true))
|
2017-04-03 16:42:55 +02:00
|
|
|
{
|
2017-11-06 19:51:12 +02:00
|
|
|
my $bRepoEncrypt = $bRemote && !$bS3 ? true : false;
|
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$self->begin("remote $bRemote, s3 $bS3, enc ${bRepoEncrypt}")) {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(
|
2017-11-06 19:51:12 +02:00
|
|
|
true, $self->expect(), {bHostBackup => $bRemote, bS3 => $bS3, bRepoEncrypt => $bRepoEncrypt});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-08-04 22:10:51 +02:00
|
|
|
# Create the stanza
|
|
|
|
$oHostBackup->stanzaCreate('fail on missing control file', {iExpectedExitStatus => ERROR_FILE_OPEN,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Generate pg_control for stanza-create
|
2017-08-04 22:10:51 +02:00
|
|
|
storageDb()->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',
|
2017-08-25 22:47:47 +02:00
|
|
|
{iExpectedExitStatus => ERROR_FILE_MISSING, strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
# Create the stanza successfully without force
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$oHostBackup->stanzaCreate('successfully create the stanza', {strOptionalParam => '--no-' . cfgOptionName(CFGOPT_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',
|
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_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
|
|
|
|
|
|
|
$oHostBackup->stanzaCreate('fail on database mismatch without force option',
|
|
|
|
{iExpectedExitStatus => ERROR_FILE_INVALID, strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
|
|
|
|
|
|
|
# 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
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->stanzaUpgrade('already up to date', {strOptionalParam => '--no-' . cfgOptionName(CFGOPT_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';
|
2017-11-19 03:02:54 +02:00
|
|
|
storageDb()->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()});
|
|
|
|
|
|
|
|
# With data existing in the archive dir, remove the info files and confirm failure
|
2017-11-06 19:51:12 +02:00
|
|
|
if ($bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoFile, $strArchiveInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyFile, $strArchiveInfoCopyOldFile, {bRecurse => false});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
|
|
|
|
}
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$bRepoEncrypt)
|
|
|
|
{
|
|
|
|
$oHostBackup->stanzaCreate('fail on archive info file missing from non-empty dir',
|
|
|
|
{iExpectedExitStatus => ERROR_FILE_MISSING, strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
|
|
|
}
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-08-04 22:10:51 +02:00
|
|
|
# Stanza Create fails using force - failure to unzip compressed file
|
2017-04-03 16:42:55 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-08-04 22:10:51 +02:00
|
|
|
# S3 doesn't support filesystem-style permissions so skip these tests
|
|
|
|
if (!$bS3)
|
|
|
|
{
|
|
|
|
# Change the permissions of the archive file so it cannot be read
|
|
|
|
forceStorageMode(
|
|
|
|
storageRepo(), STORAGE_REPO_ARCHIVE . qw{/} . PG_VERSION_93 . '-1/' . substr($strArchiveFile, 0, 16) . '/*.' .
|
|
|
|
COMPRESS_EXT,
|
|
|
|
'220');
|
|
|
|
|
|
|
|
# Force creation of the info file but fail on gunzip
|
|
|
|
$oHostBackup->stanzaCreate('gunzip fail on forced stanza-create',
|
2017-08-25 22:47:47 +02:00
|
|
|
{iExpectedExitStatus => ERROR_FILE_OPEN, strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' .
|
|
|
|
cfgOptionName(CFGOPT_FORCE)});
|
2017-08-04 22:10:51 +02:00
|
|
|
|
|
|
|
# Change permissions back
|
|
|
|
forceStorageMode(
|
|
|
|
storageRepo(), STORAGE_REPO_ARCHIVE . qw{/} . PG_VERSION_93 . '-1/' . substr($strArchiveFile, 0, 16) . '/*.' .
|
|
|
|
COMPRESS_EXT,
|
|
|
|
'640');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Stanza Create succeeds when using force - recreates archive.info from compressed archive file
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Force creation of archive info from the gz file
|
|
|
|
$oHostBackup->stanzaCreate('force create archive.info from gz file',
|
2017-11-06 19:51:12 +02:00
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE),
|
|
|
|
iExpectedExitStatus => $bRepoEncrypt ? ERROR_FILE_MISSING : undef});
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2018-02-01 21:12:03 +02:00
|
|
|
if (!$bRepoEncrypt)
|
|
|
|
{
|
|
|
|
$self->testResult(sub {storageRepo()->exists($strArchiveInfoFile)}, true, " archive.info file was created");
|
|
|
|
}
|
2017-08-04 22:10:51 +02:00
|
|
|
|
|
|
|
# Stanza Create succeeds when using force - recreates archive.info from uncompressed archive file
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Unzip the archive file and recreate the archive.info file from it
|
2017-11-19 03:02:54 +02:00
|
|
|
my $strArchiveTest = PG_VERSION_93 . "-1/${strArchiveFile}-" . $self->walGenerateContentChecksum(PG_VERSION_93);
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageMode(
|
|
|
|
storageRepo(), dirname(storageRepo()->pathGet(STORAGE_REPO_ARCHIVE . "/${strArchiveTest}.gz")), 'g+w',
|
|
|
|
{bRecursive => true});
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
storageRepo()->copy(
|
|
|
|
storageRepo()->openRead(
|
|
|
|
STORAGE_REPO_ARCHIVE . "/${strArchiveTest}.gz",
|
|
|
|
{rhyFilter => [{strClass => STORAGE_FILTER_GZIP, rxyParam => [{strCompressType => STORAGE_DECOMPRESS}]}]}),
|
|
|
|
STORAGE_REPO_ARCHIVE . "/${strArchiveTest}");
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oHostBackup->stanzaCreate('force create archive.info from uncompressed file',
|
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
|
|
|
|
}
|
2017-08-04 22:10:51 +02:00
|
|
|
|
|
|
|
# Stanza Create succeeds when using force - missing archive file
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Remove the uncompressed WAL archive file and archive.info
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageRemove(storageRepo(), STORAGE_REPO_ARCHIVE . "/${strArchiveTest}");
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oHostBackup->stanzaCreate('force with missing WAL archive file',
|
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
|
|
|
|
}
|
2017-08-04 22:10:51 +02:00
|
|
|
|
|
|
|
# Stanza Create succeeds when using force - missing archive directory
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Remove the WAL archive directory
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageRemove(
|
|
|
|
storageRepo(),
|
|
|
|
STORAGE_REPO_ARCHIVE . qw{/} . PG_VERSION_93 . '-1/' . substr($strArchiveFile, 0, 16), {bRecurse => true});
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
|
|
|
|
|
|
|
|
$oHostBackup->stanzaCreate('force with missing WAL archive directory',
|
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
|
|
|
|
}
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Encrypted info files could not be reconstructed above so just copy them back
|
|
|
|
if ($bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoOldFile, $strArchiveInfoFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyOldFile, $strArchiveInfoCopyFile, {bRecurse => false});
|
|
|
|
}
|
|
|
|
|
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);
|
2017-06-09 23:51:41 +02:00
|
|
|
forceStorageMode(storageDb(), $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
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-08-04 22:10:51 +02:00
|
|
|
$oHostBackup->stanzaUpgrade('successful upgrade creates additional history', {strOptionalParam => '--no-' .
|
2017-08-25 22:47:47 +02:00
|
|
|
cfgOptionName(CFGOPT_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);
|
2017-11-17 00:18:51 +02:00
|
|
|
forceStorageMode(storageDb(), $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL, '600');
|
|
|
|
|
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(
|
2017-06-09 23:51:41 +02:00
|
|
|
sub {storageRepo()->list(STORAGE_REPO_ARCHIVE . qw{/} . PG_VERSION_94 . '-2/0000000100000001')},
|
2017-11-19 03:02:54 +02:00
|
|
|
'000000010000000100000001-' . $self->walGenerateContentChecksum(PG_VERSION_94) . '.' . COMPRESS_EXT,
|
2017-04-03 16:42:55 +02:00
|
|
|
'check that WAL is in the archive at -2');
|
|
|
|
|
|
|
|
# Create a DB history mismatch between the info files
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Remove the archive info file and force reconstruction
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
|
|
|
|
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oHostBackup->stanzaCreate('use force to recreate the stanza producing mismatched info history but same current db-id',
|
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
|
|
|
|
}
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Create a DB-ID mismatch between the info files
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageRemove(storageRepo(), $strBackupInfoFile);
|
|
|
|
forceStorageRemove(storageRepo(), $strBackupInfoCopyFile);
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oHostBackup->stanzaCreate('use force to recreate the stanza producing mismatched db-id',
|
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
|
|
|
|
}
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Confirm successful backup at db-1 although archive at db-2
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Create the tablespace directory and perform a backup
|
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(
|
|
|
|
'full', 'create first full backup ',
|
2018-02-19 22:07:24 +02:00
|
|
|
{strOptionalParam => '--repo1-retention-full=2 --no-' . cfgOptionName(CFGOPT_ONLINE) . ' --log-level-console=detail'},
|
|
|
|
false);
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-08-04 22:10:51 +02:00
|
|
|
# Stanza Create fails when not using force - no backup.info but backup exists
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
2017-11-06 19:51:12 +02:00
|
|
|
if ($bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoFile, $strBackupInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoCopyFile, $strBackupInfoCopyOldFile, {bRecurse => false});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forceStorageRemove(storageRepo(), $strBackupInfoFile);
|
|
|
|
forceStorageRemove(storageRepo(), $strBackupInfoCopyFile);
|
|
|
|
}
|
2017-08-04 22:10:51 +02:00
|
|
|
|
|
|
|
$oHostBackup->stanzaCreate('fail no force to recreate the stanza from backups',
|
2017-08-25 22:47:47 +02:00
|
|
|
{iExpectedExitStatus => ERROR_FILE_MISSING, strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
2017-08-04 22:10:51 +02:00
|
|
|
|
|
|
|
# Stanza Create succeeds using force - reconstruct backup.info from backup
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$oHostBackup->stanzaCreate('use force to recreate the stanza from backups',
|
2017-11-06 19:51:12 +02:00
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE),
|
|
|
|
iExpectedExitStatus => $bRepoEncrypt ? ERROR_FILE_MISSING : undef});
|
|
|
|
|
|
|
|
# Encrypted info files could not be reconstructed above so just copy them back
|
|
|
|
if ($bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoOldFile, $strBackupInfoFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoCopyOldFile, $strBackupInfoCopyFile, {bRecurse => false});
|
|
|
|
}
|
2017-08-04 22:10:51 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# 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)
|
2017-06-09 23:51:41 +02:00
|
|
|
forceStorageMode(storageRepo(), STORAGE_REPO_ARCHIVE, '770');
|
|
|
|
storageRepo()->pathCreate(STORAGE_REPO_ARCHIVE . '/10.0-3/0000000100000001', {bCreateParent => true});
|
2017-11-19 03:02:54 +02:00
|
|
|
storageRepo()->put(
|
2017-11-06 19:51:12 +02:00
|
|
|
storageRepo()->openWrite(
|
|
|
|
STORAGE_REPO_ARCHIVE . '/10.0-3/0000000100000001/000000010000000100000001',
|
2017-11-19 03:02:54 +02:00
|
|
|
{strCipherPass => $oHostBackup->cipherPassArchive()}),
|
|
|
|
$self->walGenerateContent(PG_VERSION_94));
|
2017-06-09 23:51:41 +02:00
|
|
|
forceStorageOwner(storageRepo(), STORAGE_REPO_ARCHIVE . '/10.0-3', $oHostBackup->userGet(), {bRecurse => true});
|
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);
|
2017-06-09 23:51:41 +02:00
|
|
|
forceStorageMode(storageDb(), $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL, '600');
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->stanzaUpgrade(
|
|
|
|
'successfully upgrade with XX.Y-Z', {strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-04-07 01:36:37 +02:00
|
|
|
# Push a WAL and create a backup in the new DB to confirm diff changed to full and info command displays the JSON correctly
|
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)
|
|
|
|
my $oExecuteBackup = $oHostBackup->backupBegin('diff', 'diff changed to full backup',
|
2018-02-19 22:07:24 +02:00
|
|
|
{strOptionalParam => '--repo1-retention-full=2 --no-' . cfgOptionName(CFGOPT_ONLINE) . ' --log-level-console=detail'});
|
2017-04-07 01:36:37 +02:00
|
|
|
$oHostBackup->backupEnd('full', $oExecuteBackup, undef, false);
|
|
|
|
|
|
|
|
# Confirm info command displays the JSON correctly
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostDbMaster->info('db upgraded - db-1 and db-2 listed', {strOutput => CFGOPTVAL_INFO_OUTPUT_JSON});
|
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
|
|
|
}
|
2017-06-12 16:52:32 +02:00
|
|
|
}
|
2017-04-03 16:42:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|