2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-06-20 00:55:00 +02:00
|
|
|
# Test All Commands On PostgreSQL Clusters
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-06-20 00:55:00 +02:00
|
|
|
package pgBackRestTest::Module::Real::RealAllTest;
|
2017-05-12 22:43:04 +02:00
|
|
|
use parent 'pgBackRestTest::Env::HostEnvTest';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
|
2020-03-10 21:41:56 +02:00
|
|
|
use pgBackRestDoc::Common::Exception;
|
|
|
|
use pgBackRestDoc::Common::Ini;
|
|
|
|
use pgBackRestDoc::Common::Log;
|
2020-03-10 23:57:02 +02:00
|
|
|
use pgBackRestDoc::ProjectInfo;
|
2020-03-10 21:12:44 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Common::DbVersion;
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::FileTest;
|
|
|
|
use pgBackRestTest::Common::RunTest;
|
2017-06-21 22:07:13 +02:00
|
|
|
use pgBackRestTest::Common::VmTest;
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Common::Storage;
|
|
|
|
use pgBackRestTest::Common::StoragePosix;
|
|
|
|
use pgBackRestTest::Common::StorageRepo;
|
|
|
|
use pgBackRestTest::Common::Wait;
|
|
|
|
use pgBackRestTest::Env::ArchiveInfo;
|
|
|
|
use pgBackRestTest::Env::BackupInfo;
|
|
|
|
use pgBackRestTest::Env::InfoCommon;
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostBaseTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostDbTest;
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostDbTest;
|
2017-06-21 22:07:13 +02:00
|
|
|
use pgBackRestTest::Env::HostEnvTest;
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Env::Manifest;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2020-03-06 14:21:17 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Backup advisory lock
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant DB_BACKUP_ADVISORY_LOCK => '12340078987004321';
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2020-03-10 20:45:27 +02:00
|
|
|
# Should the test use lz4 compression?
|
|
|
|
my $bLz4Compress = true;
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bS3 (false, true)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bHostBackup ($bS3 ? (true) : (false, true))
|
|
|
|
{
|
2017-06-21 22:07:13 +02:00
|
|
|
# Standby should only be tested for pg versions that support it
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bHostStandby ($bS3 ? (false) : (false, true))
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-06-21 22:07:13 +02:00
|
|
|
# Master and standby backup destinations on need to be tested on one db version since it is not version specific
|
2016-12-23 15:22:59 +02:00
|
|
|
foreach my $strBackupDestination (
|
2017-06-12 16:52:32 +02:00
|
|
|
$bS3 || $bHostBackup ? (HOST_BACKUP) : $bHostStandby ? (HOST_DB_MASTER, HOST_DB_STANDBY) : (HOST_DB_MASTER))
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2020-03-10 20:45:27 +02:00
|
|
|
my $strCompressType = $bHostBackup && !$bHostStandby ? (vmWithLz4($self->vm()) && $bLz4Compress ? LZ4 : GZ) : NONE;
|
2020-03-06 21:41:03 +02:00
|
|
|
my $bRepoEncrypt = ($strCompressType ne NONE && !$bS3) ? true : false;
|
2017-06-21 22:07:13 +02:00
|
|
|
|
2020-03-10 20:45:27 +02:00
|
|
|
# If compression was used then switch it for the next test that uses compression
|
|
|
|
if ($strCompressType ne NONE)
|
|
|
|
{
|
|
|
|
$bLz4Compress = !$bLz4Compress;
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
2017-11-15 00:16:39 +02:00
|
|
|
my $hyVm = vmGet();
|
|
|
|
my $strDbVersionMostRecent = ${$hyVm->{$self->vm()}{&VM_DB_TEST}}[-1];
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
next if (!$self->begin(
|
2020-03-06 21:41:03 +02:00
|
|
|
"bkp ${bHostBackup}, sby ${bHostStandby}, dst ${strBackupDestination}, cmp ${strCompressType}, s3 ${bS3}, " .
|
2017-11-06 19:51:12 +02:00
|
|
|
"enc ${bRepoEncrypt}",
|
2017-11-15 00:16:39 +02:00
|
|
|
# Use the most recent db version on the expect vm for expect testing
|
|
|
|
$self->vm() eq VM_EXPECT && $self->pgVersion() eq $strDbVersionMostRecent));
|
2017-06-21 22:07:13 +02:00
|
|
|
|
|
|
|
# Skip when s3 and host backup tests when there is more than one version of pg being tested and this is not the last one
|
2017-11-15 00:16:39 +02:00
|
|
|
if (($bS3 || $bHostBackup) && (@{$hyVm->{$self->vm()}{&VM_DB_TEST}} > 1 && $strDbVersionMostRecent ne $self->pgVersion()))
|
2017-06-21 22:07:13 +02:00
|
|
|
{
|
2017-11-15 00:16:39 +02:00
|
|
|
&log(INFO, "skipped - this test is run this OS using PG ${strDbVersionMostRecent}");
|
2017-06-21 22:07:13 +02:00
|
|
|
next;
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
# Skip hot standby tests if the system does not support hot standby
|
2016-12-23 15:22:59 +02:00
|
|
|
if ($bHostStandby && $self->pgVersion() < PG_VERSION_HOT_STANDBY)
|
|
|
|
{
|
|
|
|
&log(INFO, 'skipped - this version of PostgreSQL does not support hot standby');
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
# Skip backup destinations other than backup host when standby except for one arbitrary db version
|
|
|
|
if ($bHostStandby && $strBackupDestination ne HOST_BACKUP && $self->pgVersion() ne PG_VERSION_96)
|
|
|
|
{
|
2017-06-27 21:48:34 +02:00
|
|
|
&log(INFO, 'skipped - standby with backup destination other than backup host is tested on PG ' . PG_VERSION_96);
|
2017-06-21 22:07:13 +02:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Create hosts, file object, and config
|
2017-06-12 16:52:32 +02:00
|
|
|
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3) = $self->setup(
|
2016-12-23 15:22:59 +02:00
|
|
|
false, $self->expect(),
|
|
|
|
{bHostBackup => $bHostBackup, bStandby => $bHostStandby, strBackupDestination => $strBackupDestination,
|
2020-03-06 21:41:03 +02:00
|
|
|
strCompressType => $strCompressType, bArchiveAsync => false, bS3 => $bS3, bRepoEncrypt => $bRepoEncrypt});
|
2017-09-01 18:29:34 +02:00
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
# Only perform extra tests on certain runs to save time
|
|
|
|
my $bTestLocal = $self->runCurrent() == 1;
|
|
|
|
my $bTestExtra =
|
|
|
|
$bTestLocal || $self->runCurrent() == 4 || ($self->runCurrent() == 6 && $self->pgVersion() eq PG_VERSION_96);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
# If S3 set process max to 2. This seems like the best place for parallel testing since it will help speed S3 processing
|
|
|
|
# without slowing down the other tests too much.
|
|
|
|
if ($bS3)
|
|
|
|
{
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {'process-max' => 2}});
|
|
|
|
$oHostDbMaster->configUpdate({&CFGDEF_SECTION_GLOBAL => {'process-max' => 2}});
|
2017-06-21 22:07:13 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterCreate();
|
|
|
|
|
|
|
|
# Create the stanza
|
|
|
|
$oHostBackup->stanzaCreate('main create stanza info files');
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Get passphrase to access the Manifest file from backup.info - returns undefined if repo not encrypted
|
|
|
|
my $strCipherPass =
|
2020-03-10 21:12:44 +02:00
|
|
|
(new pgBackRestTest::Env::BackupInfo($oHostBackup->repoBackupPath()))->cipherPassSub();
|
2017-11-06 19:51:12 +02:00
|
|
|
|
|
|
|
# Create a manifest with the pg version to get version-specific paths
|
2020-03-10 21:12:44 +02:00
|
|
|
my $oManifest = new pgBackRestTest::Env::Manifest(BOGUS, {bLoad => false, strDbVersion => $self->pgVersion(),
|
2018-07-16 23:25:15 +02:00
|
|
|
iDbCatalogVersion => $self->dbCatalogVersion($self->pgVersion()),
|
2017-11-06 19:51:12 +02:00
|
|
|
strCipherPass => $strCipherPass, strCipherPassSub => $bRepoEncrypt ? ENCRYPTION_KEY_BACKUPSET : undef});
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Static backup parameters
|
|
|
|
my $fTestDelay = 1;
|
|
|
|
|
|
|
|
# Restore test string
|
|
|
|
my $strDefaultMessage = 'default';
|
|
|
|
my $strFullMessage = 'full';
|
|
|
|
my $strStandbyMessage = 'standby';
|
|
|
|
my $strIncrMessage = 'incr';
|
|
|
|
my $strTimeMessage = 'time';
|
|
|
|
my $strXidMessage = 'xid';
|
|
|
|
my $strNameMessage = 'name';
|
2019-09-27 19:37:59 +02:00
|
|
|
my $strTimelineMessage = 'timeline';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create two new databases
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute('create database test1', {bAutoCommit => true});
|
|
|
|
$oHostDbMaster->sqlExecute('create database test2', {bAutoCommit => true});
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Test check command and stanza create
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($bTestExtra)
|
|
|
|
{
|
2017-12-04 00:08:49 +02:00
|
|
|
# In this section the same comment can be used multiple times so make it a variable that can be set once and reused
|
|
|
|
my $strComment = undef;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
# Archive and backup info file names
|
2020-03-09 23:41:59 +02:00
|
|
|
my $strArchiveInfoFile = $oHostBackup->repoArchivePath(ARCHIVE_INFO_FILE);
|
|
|
|
my $strArchiveInfoCopyFile = $oHostBackup->repoArchivePath(ARCHIVE_INFO_FILE . INI_COPY_EXT);
|
2019-08-21 22:26:28 +02:00
|
|
|
my $strArchiveInfoOldFile = "${strArchiveInfoFile}.old";
|
|
|
|
my $strArchiveInfoCopyOldFile = "${strArchiveInfoCopyFile}.old";
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
my $strBackupInfoFile = $oHostBackup->repoBackupPath(FILE_BACKUP_INFO);
|
|
|
|
my $strBackupInfoCopyFile = $oHostBackup->repoBackupPath(FILE_BACKUP_INFO . INI_COPY_EXT);
|
2019-08-21 22:26:28 +02:00
|
|
|
my $strBackupInfoOldFile = "${strBackupInfoFile}.old";
|
|
|
|
my $strBackupInfoCopyOldFile = "${strBackupInfoCopyFile}.old";
|
|
|
|
|
|
|
|
# Move the archive.info files to simulate missing file
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoFile, $strArchiveInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyFile, $strArchiveInfoCopyOldFile, {bRecurse => false});
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->check(
|
|
|
|
'fail on missing archive.info file',
|
|
|
|
{iTimeout => 0.1, iExpectedExitStatus => ERROR_FILE_MISSING});
|
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
# Backup.info was created earlier so restore archive info files
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoOldFile, $strArchiveInfoFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyOldFile, $strArchiveInfoCopyFile, {bRecurse => false});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Check ERROR_ARCHIVE_DISABLED error
|
|
|
|
$strComment = 'fail on archive_mode=off';
|
|
|
|
$oHostDbMaster->clusterRestart({bIgnoreLogError => true, bArchiveEnabled => false});
|
|
|
|
|
2017-12-04 00:08:49 +02:00
|
|
|
$oHostBackup->backup(CFGOPTVAL_BACKUP_TYPE_FULL, $strComment, {iExpectedExitStatus => ERROR_ARCHIVE_DISABLED});
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_ARCHIVE_DISABLED});
|
|
|
|
|
|
|
|
# If running the remote tests then also need to run check locally
|
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
|
|
|
$oHostBackup->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_ARCHIVE_DISABLED});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check ERROR_ARCHIVE_COMMAND_INVALID error
|
|
|
|
$strComment = 'fail on invalid archive_command';
|
|
|
|
$oHostDbMaster->clusterRestart({bIgnoreLogError => true, bArchive => false});
|
|
|
|
|
2017-12-04 00:08:49 +02:00
|
|
|
$oHostBackup->backup(CFGOPTVAL_BACKUP_TYPE_FULL, $strComment, {iExpectedExitStatus => ERROR_ARCHIVE_COMMAND_INVALID});
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_ARCHIVE_COMMAND_INVALID});
|
|
|
|
|
|
|
|
# If running the remote tests then also need to run check locally
|
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
|
|
|
$oHostBackup->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_ARCHIVE_COMMAND_INVALID});
|
|
|
|
}
|
|
|
|
|
|
|
|
# When archive-check=n then ERROR_ARCHIVE_TIMEOUT will be raised instead of ERROR_ARCHIVE_COMMAND_INVALID
|
|
|
|
# ??? But maybe we should error with the fact that that option is not valid
|
|
|
|
$strComment = 'fail on archive timeout when archive-check=n';
|
|
|
|
$oHostDbMaster->check(
|
|
|
|
$strComment,
|
|
|
|
{iTimeout => 0.1, iExpectedExitStatus => ERROR_ARCHIVE_TIMEOUT, strOptionalParam => '--no-archive-check'});
|
|
|
|
|
|
|
|
# Stop the cluster ignoring any errors in the postgresql log
|
|
|
|
$oHostDbMaster->clusterStop({bIgnoreLogError => true});
|
|
|
|
|
|
|
|
# Providing a sufficient archive-timeout, verify that the check command runs successfully.
|
|
|
|
$strComment = 'verify success';
|
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
|
|
|
$oHostDbMaster->check($strComment, {iTimeout => 5});
|
|
|
|
|
|
|
|
# If running the remote tests then also need to run check locally
|
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
|
|
|
$oHostBackup->check($strComment, {iTimeout => 5});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check archive mismatch due to upgrade error
|
|
|
|
$strComment = 'fail on archive mismatch after upgrade';
|
|
|
|
|
|
|
|
# load the archive info file and munge it for testing by breaking the database version
|
|
|
|
$oHostBackup->infoMunge(
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->repoArchivePath(ARCHIVE_INFO_FILE),
|
2019-10-09 00:04:09 +02:00
|
|
|
{&INFO_ARCHIVE_SECTION_DB => {&INFO_ARCHIVE_KEY_DB_VERSION => '8.0'},
|
|
|
|
&INFO_ARCHIVE_SECTION_DB_HISTORY => {1 => {&INFO_ARCHIVE_KEY_DB_VERSION => '8.0'}}});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2019-10-09 00:04:09 +02:00
|
|
|
$oHostDbMaster->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_FILE_INVALID});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# If running the remote tests then also need to run check locally
|
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
2019-10-09 00:04:09 +02:00
|
|
|
$oHostBackup->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_FILE_INVALID});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Restore the file to its original condition
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->infoRestore($oHostBackup->repoArchivePath(ARCHIVE_INFO_FILE));
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Check archive_timeout error when WAL segment is not found
|
|
|
|
$strComment = 'fail on archive timeout';
|
|
|
|
|
|
|
|
$oHostDbMaster->clusterRestart({bIgnoreLogError => true, bArchiveInvalid => true});
|
|
|
|
$oHostDbMaster->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_ARCHIVE_TIMEOUT});
|
|
|
|
|
|
|
|
# If running the remote tests then also need to run check locally
|
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
|
|
|
$oHostBackup->check($strComment, {iTimeout => 0.1, iExpectedExitStatus => ERROR_ARCHIVE_TIMEOUT});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restart the cluster ignoring any errors in the postgresql log
|
|
|
|
$oHostDbMaster->clusterRestart({bIgnoreLogError => true});
|
|
|
|
|
|
|
|
# With a valid archive info, create the backup.info file by running a backup then munge the backup.info file.
|
|
|
|
# Check backup mismatch error
|
|
|
|
$strComment = 'fail on backup info mismatch';
|
|
|
|
|
|
|
|
# Load the backup.info file and munge it for testing by breaking the database version and system id
|
|
|
|
$oHostBackup->infoMunge(
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->repoBackupPath(FILE_BACKUP_INFO),
|
2016-12-23 15:22:59 +02:00
|
|
|
{&INFO_BACKUP_SECTION_DB =>
|
2019-10-09 00:04:09 +02:00
|
|
|
{&INFO_BACKUP_KEY_DB_VERSION => '8.0', &INFO_BACKUP_KEY_SYSTEM_ID => 6999999999999999999},
|
|
|
|
&INFO_BACKUP_SECTION_DB_HISTORY =>
|
|
|
|
{1 => {&INFO_BACKUP_KEY_DB_VERSION => '8.0', &INFO_BACKUP_KEY_SYSTEM_ID => 6999999999999999999}}});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Run the test
|
2019-10-09 00:04:09 +02:00
|
|
|
$oHostDbMaster->check($strComment, {iTimeout => 5, iExpectedExitStatus => ERROR_FILE_INVALID});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# If running the remote tests then also need to run check locally
|
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
2019-10-09 00:04:09 +02:00
|
|
|
$oHostBackup->check($strComment, {iTimeout => 5, iExpectedExitStatus => ERROR_FILE_INVALID});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Restore the file to its original condition
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->infoRestore($oHostBackup->repoBackupPath(FILE_BACKUP_INFO));
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2019-10-09 00:04:09 +02:00
|
|
|
# ??? Removed temporarily until manifest build can be brought back into the check command
|
2017-12-13 18:16:27 +02:00
|
|
|
# Create a directory in pg_data location that is only readable by root to ensure manifest->build is called by check
|
2019-10-09 00:04:09 +02:00
|
|
|
# my $strDir = $oHostDbMaster->dbBasePath() . '/rootreaddir';
|
|
|
|
# executeTest('sudo mkdir ' . $strDir);
|
|
|
|
# executeTest("sudo chown root:root ${strDir}");
|
|
|
|
# executeTest("sudo chmod 400 ${strDir}");
|
|
|
|
#
|
|
|
|
# $strComment = 'confirm master manifest->build executed';
|
|
|
|
# $oHostDbMaster->check($strComment, {iTimeout => 5, iExpectedExitStatus => ERROR_PATH_OPEN});
|
|
|
|
# executeTest("sudo rmdir ${strDir}");
|
2017-12-13 18:16:27 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Providing a sufficient archive-timeout, verify that the check command runs successfully now with valid
|
|
|
|
# archive.info and backup.info files
|
|
|
|
$strComment = 'verify success after backup';
|
|
|
|
|
|
|
|
$oHostDbMaster->check($strComment, {iTimeout => 5});
|
|
|
|
|
|
|
|
# If running the remote tests then also need to run check locally
|
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
|
|
|
$oHostBackup->check($strComment, {iTimeout => 5});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restart the cluster ignoring any errors in the postgresql log
|
|
|
|
$oHostDbMaster->clusterRestart({bIgnoreLogError => true});
|
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Stanza Create
|
2016-12-23 15:22:59 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2019-08-21 22:26:28 +02:00
|
|
|
# With data existing in the archive and backup directory, move info files and confirm failure
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoFile, $strArchiveInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strArchiveInfoCopyFile, $strArchiveInfoCopyOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoFile, $strBackupInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoCopyFile, $strBackupInfoCopyOldFile, {bRecurse => false});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
$oHostBackup->stanzaCreate(
|
|
|
|
'fail on backup info file missing from non-empty dir', {iExpectedExitStatus => ERROR_PATH_NOT_EMPTY});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2018-02-04 01:27:38 +02:00
|
|
|
# Change the database version by copying a new pg_control file to a new pg-path to use for db mismatch test
|
2020-03-06 21:10:09 +02:00
|
|
|
storageTest()->pathCreate(
|
2017-06-09 23:51:41 +02:00
|
|
|
$oHostDbMaster->dbPath() . '/testbase/' . DB_PATH_GLOBAL,
|
|
|
|
{strMode => '0700', bIgnoreExists => true, bCreateParent => true});
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate(
|
|
|
|
$oHostDbMaster->dbPath() . '/testbase', $self->pgVersion() eq PG_VERSION_94 ? PG_VERSION_95 : PG_VERSION_94);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
# Run stanza-create online to confirm proper handling of configValidation error against new pg-path
|
|
|
|
$oHostBackup->stanzaCreate('fail on database mismatch with directory',
|
2020-03-09 23:41:59 +02:00
|
|
|
{strOptionalParam => ' --pg1-path=' . $oHostDbMaster->dbPath() . '/testbase/',
|
|
|
|
iExpectedExitStatus => ERROR_DB_MISMATCH});
|
2019-08-21 22:26:28 +02:00
|
|
|
|
|
|
|
# Remove the directories to be able to create the stanza
|
2020-03-09 23:41:59 +02:00
|
|
|
forceStorageRemove(storageRepo(), $oHostBackup->repoBackupPath(), {bRecurse => true});
|
|
|
|
forceStorageRemove(storageRepo(), $oHostBackup->repoArchivePath(), {bRecurse => true});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Stanza Upgrade - tests configValidate code - all other tests in synthetic integration tests
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2019-08-21 22:26:28 +02:00
|
|
|
# Run stanza-create offline to create files needing to be upgraded (using new pg-path)
|
2017-04-03 16:42:55 +02:00
|
|
|
$oHostBackup->stanzaCreate('successfully create stanza files to be upgraded',
|
2020-03-09 23:41:59 +02:00
|
|
|
{strOptionalParam => ' --pg1-path=' . $oHostDbMaster->dbPath() . '/testbase/ --no-online --force'});
|
2020-03-10 21:12:44 +02:00
|
|
|
my $oArchiveInfo = new pgBackRestTest::Env::ArchiveInfo($oHostBackup->repoArchivePath());
|
|
|
|
my $oBackupInfo = new pgBackRestTest::Env::BackupInfo($oHostBackup->repoBackupPath());
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Read info files to confirm the files were created with a different database version
|
|
|
|
if ($self->pgVersion() eq PG_VERSION_94)
|
|
|
|
{
|
2019-08-26 18:05:36 +02:00
|
|
|
$self->testResult(sub {$oArchiveInfo->test(INFO_ARCHIVE_SECTION_DB, INFO_ARCHIVE_KEY_DB_VERSION, undef,
|
2018-02-04 01:27:38 +02:00
|
|
|
PG_VERSION_95)}, true, 'archive upgrade forced with pg mismatch');
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->testResult(sub {$oBackupInfo->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_DB_VERSION, undef,
|
2018-02-04 01:27:38 +02:00
|
|
|
PG_VERSION_95)}, true, 'backup upgrade forced with pg mismatch');
|
2017-04-03 16:42:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-26 18:05:36 +02:00
|
|
|
$self->testResult(sub {$oArchiveInfo->test(INFO_ARCHIVE_SECTION_DB, INFO_ARCHIVE_KEY_DB_VERSION, undef,
|
2018-02-04 01:27:38 +02:00
|
|
|
PG_VERSION_94)}, true, 'archive create forced with pg mismatch in prep for stanza-upgrade');
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->testResult(sub {$oBackupInfo->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_DB_VERSION, undef,
|
2018-02-04 01:27:38 +02:00
|
|
|
PG_VERSION_94)}, true, 'backup create forced with pg mismatch in prep for stanza-upgrade');
|
2017-04-03 16:42:55 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2018-02-04 01:27:38 +02:00
|
|
|
# Run stanza-upgrade online with the default pg-path to correct the info files
|
2017-04-03 16:42:55 +02:00
|
|
|
$oHostBackup->stanzaUpgrade('upgrade stanza files online');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Reread the info files and confirm the result
|
2020-03-10 21:12:44 +02:00
|
|
|
$oArchiveInfo = new pgBackRestTest::Env::ArchiveInfo($oHostBackup->repoArchivePath());
|
|
|
|
$oBackupInfo = new pgBackRestTest::Env::BackupInfo($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,
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->pgVersion())}, true, 'archive upgrade online corrects db');
|
|
|
|
$self->testResult(sub {$oBackupInfo->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_DB_VERSION, undef,
|
|
|
|
$self->pgVersion())}, true, 'backup upgrade online corrects db');
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Full backup
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Create the table where test messages will be stored
|
|
|
|
$oHostDbMaster->sqlExecute("create table test (message text not null)");
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->sqlExecute("insert into test values ('$strDefaultMessage')");
|
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# Acquire the backup advisory lock so it looks like a backup is running
|
|
|
|
if (!$oHostDbMaster->sqlSelectOne('select pg_try_advisory_lock(' . DB_BACKUP_ADVISORY_LOCK . ')'))
|
|
|
|
{
|
|
|
|
confess 'unable to acquire advisory lock for testing';
|
|
|
|
}
|
|
|
|
|
2017-12-04 00:08:49 +02:00
|
|
|
$oHostBackup->backup(
|
|
|
|
CFGOPTVAL_BACKUP_TYPE_FULL, 'fail on backup lock exists', {iExpectedExitStatus => ERROR_LOCK_ACQUIRE});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Release the backup advisory lock so the next backup will succeed
|
|
|
|
if (!$oHostDbMaster->sqlSelectOne('select pg_advisory_unlock(' . DB_BACKUP_ADVISORY_LOCK . ')'))
|
|
|
|
{
|
|
|
|
confess 'unable to release advisory lock';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strFullMessage'");
|
|
|
|
|
|
|
|
# Required to set hint bits to be sent to the standby to make the heap match on both sides
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $strFullMessage);
|
|
|
|
|
2019-11-26 18:32:12 +02:00
|
|
|
my $strFullBackup = $oHostBackup->backup(
|
|
|
|
CFGOPTVAL_BACKUP_TYPE_FULL, 'update during backup',
|
2020-03-09 23:41:59 +02:00
|
|
|
{strOptionalParam => ' --buffer-size=16384'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
# Enabled async archiving
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {'archive-async' => 'y'}});
|
2017-06-21 22:07:13 +02:00
|
|
|
|
2019-08-26 18:05:36 +02:00
|
|
|
# Kick out a bunch of archive logs to exercise async archiving. Only do this when compressed and remote to slow it
|
2016-12-23 15:22:59 +02:00
|
|
|
# down enough to make it evident that the async process is working.
|
2020-03-06 21:41:03 +02:00
|
|
|
if ($bTestExtra && $strCompressType ne NONE && $strBackupDestination eq HOST_BACKUP)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-09-01 18:29:34 +02:00
|
|
|
&log(INFO, ' multiple wal switches to exercise async archiving');
|
|
|
|
$oHostDbMaster->sqlExecute("create table wal_activity (id int)");
|
|
|
|
$oHostDbMaster->sqlWalRotate();
|
|
|
|
$oHostDbMaster->sqlExecute("insert into wal_activity values (1)");
|
|
|
|
$oHostDbMaster->sqlWalRotate();
|
|
|
|
$oHostDbMaster->sqlExecute("insert into wal_activity values (2)");
|
|
|
|
$oHostDbMaster->sqlWalRotate();
|
|
|
|
$oHostDbMaster->sqlExecute("insert into wal_activity values (3)");
|
|
|
|
$oHostDbMaster->sqlWalRotate();
|
|
|
|
$oHostDbMaster->sqlExecute("insert into wal_activity values (4)");
|
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Setup replica
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($bHostStandby)
|
|
|
|
{
|
|
|
|
my %oRemapHash;
|
|
|
|
$oRemapHash{&MANIFEST_TARGET_PGDATA} = $oHostDbStandby->dbBasePath();
|
|
|
|
|
|
|
|
if ($oHostDbStandby->pgVersion() >= PG_VERSION_92)
|
|
|
|
{
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbStandby->linkRemap($oManifest->walPath(), $oHostDbStandby->dbPath() . '/' . $oManifest->walPath());
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oHostDbStandby->restore(
|
2020-03-09 23:41:59 +02:00
|
|
|
'restore backup on replica', 'latest',
|
2019-09-26 23:39:45 +02:00
|
|
|
{rhRemapHash => \%oRemapHash, strType => CFGOPTVAL_RESTORE_TYPE_STANDBY,
|
2017-12-04 00:08:49 +02:00
|
|
|
strOptionalParam =>
|
2019-09-26 23:39:45 +02:00
|
|
|
' --recovery-option="primary_conninfo=host=' . HOST_DB_MASTER .
|
2017-12-04 00:08:49 +02:00
|
|
|
' port=' . $oHostDbMaster->pgPort() . ' user=replicator"'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbStandby->clusterStart({bHotStandby => true});
|
|
|
|
|
|
|
|
# Make sure streaming replication is on
|
|
|
|
$oHostDbMaster->sqlSelectOneTest(
|
|
|
|
"select client_addr || '-' || state from pg_stat_replication", $oHostDbStandby->ipGet() . '/32-streaming');
|
|
|
|
|
|
|
|
# Check that the cluster was restored properly
|
|
|
|
$oHostDbStandby->sqlSelectOneTest('select message from test', $strFullMessage);
|
|
|
|
|
|
|
|
# Update message for standby
|
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strStandbyMessage'");
|
|
|
|
|
2017-09-01 01:15:44 +02:00
|
|
|
if ($oHostDbStandby->pgVersion() >= PG_VERSION_BACKUP_STANDBY)
|
|
|
|
{
|
2018-02-04 01:27:38 +02:00
|
|
|
# If there is only a master and a replica and the replica is the backup destination, then if pg2-host and pg3-host
|
2017-09-01 01:15:44 +02:00
|
|
|
# are BOGUS, confirm failure to reach the master
|
|
|
|
if (!$bHostBackup && $bHostStandby && $strBackupDestination eq HOST_DB_STANDBY)
|
|
|
|
{
|
|
|
|
my $strStandbyBackup = $oHostBackup->backup(
|
|
|
|
CFGOPTVAL_BACKUP_TYPE_FULL, 'backup from standby, failure to reach master',
|
2020-03-09 23:41:59 +02:00
|
|
|
{bStandby => true, iExpectedExitStatus => ERROR_DB_CONNECT, strOptionalParam => '--pg8-host=' . BOGUS});
|
2017-09-01 01:15:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my $strStandbyBackup = $oHostBackup->backup(
|
|
|
|
CFGOPTVAL_BACKUP_TYPE_FULL, 'backup from standby, failure to access at least one standby',
|
2020-03-09 23:41:59 +02:00
|
|
|
{bStandby => true, iExpectedExitStatus => ERROR_DB_CONNECT, strOptionalParam => '--pg8-host=' . BOGUS});
|
2017-09-01 01:15:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
my $strStandbyBackup = $oHostBackup->backup(
|
2017-08-25 22:47:47 +02:00
|
|
|
CFGOPTVAL_BACKUP_TYPE_FULL, 'backup from standby',
|
2016-12-23 15:22:59 +02:00
|
|
|
{bStandby => true,
|
|
|
|
iExpectedExitStatus => $oHostDbStandby->pgVersion() >= PG_VERSION_BACKUP_STANDBY ? undef : ERROR_CONFIG,
|
2020-03-09 23:41:59 +02:00
|
|
|
strOptionalParam => '--repo1-retention-full=1'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
if ($oHostDbStandby->pgVersion() >= PG_VERSION_BACKUP_STANDBY)
|
|
|
|
{
|
|
|
|
$strFullBackup = $strStandbyBackup;
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:04:09 +02:00
|
|
|
# ??? Removed temporarily until manifest build can be brought back into the check command
|
|
|
|
# # Create a directory in pg_data location that is only readable by root to ensure manifest->build is called by check
|
|
|
|
# my $strDir = $oHostDbStandby->dbBasePath() . '/rootreaddir';
|
|
|
|
# executeTest('sudo mkdir ' . $strDir);
|
|
|
|
# executeTest("sudo chown root:root ${strDir}");
|
|
|
|
# executeTest("sudo chmod 400 ${strDir}");
|
|
|
|
#
|
|
|
|
# my $strComment = 'confirm standby manifest->build executed';
|
|
|
|
#
|
|
|
|
# # If there is an invalid host, the final error returned from check will be the inability to resolve the name which is
|
|
|
|
# # an open error instead of a read error
|
|
|
|
# if (!$oHostDbStandby->bogusHost())
|
|
|
|
# {
|
|
|
|
# $oHostDbStandby->check($strComment, {iTimeout => 5, iExpectedExitStatus => ERROR_PATH_OPEN});
|
|
|
|
# }
|
|
|
|
# else
|
|
|
|
# {
|
|
|
|
# $oHostDbStandby->check($strComment, {iTimeout => 5, iExpectedExitStatus => ERROR_FILE_READ});
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# # Remove the directory in pg_data location that is only readable by root
|
|
|
|
# executeTest("sudo rmdir ${strDir}");
|
2017-12-13 18:16:27 +02:00
|
|
|
|
|
|
|
# Confirm the check command runs without error on a standby (when a bogus host is not configured)
|
2018-03-20 01:54:03 +02:00
|
|
|
if (!$oHostDbStandby->bogusHost())
|
2017-12-13 18:16:27 +02:00
|
|
|
{
|
|
|
|
$oHostDbStandby->check('verify check command on standby');
|
|
|
|
}
|
2017-07-24 13:57:47 +02:00
|
|
|
|
2019-08-26 18:05:36 +02:00
|
|
|
# Shutdown the standby before creating tablespaces (this will error since paths are different)
|
2017-07-24 13:57:47 +02:00
|
|
|
$oHostDbStandby->clusterStop({bIgnoreLogError => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Execute stop and make sure the backup fails
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Restart the cluster to check for any errors before continuing since the stop tests will definitely create errors and
|
|
|
|
# the logs will to be deleted to avoid causing issues further down the line.
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestExtra && !$bS3)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$oHostDbMaster->clusterRestart();
|
|
|
|
|
|
|
|
$oHostDbMaster->stop();
|
|
|
|
|
2019-12-14 00:14:26 +02:00
|
|
|
$oHostBackup->backup(
|
|
|
|
CFGOPTVAL_BACKUP_TYPE_INCR, 'attempt backup when stopped',
|
|
|
|
{iExpectedExitStatus => $oHostBackup == $oHostDbMaster ? ERROR_STOP : ERROR_DB_CONNECT});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->start();
|
|
|
|
}
|
|
|
|
|
2020-01-30 23:38:05 +02:00
|
|
|
# Setup the time targets
|
2016-12-23 15:22:59 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strTimeMessage'");
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2020-01-30 23:38:05 +02:00
|
|
|
my $strTimeTarget = $oHostDbMaster->sqlSelectOne("select current_timestamp");
|
2016-12-23 15:22:59 +02:00
|
|
|
&log(INFO, " time target is ${strTimeTarget}");
|
|
|
|
|
|
|
|
# Incr backup - fail on archive_mode=always when version >= 9.5
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal && $oHostDbMaster->pgVersion() >= PG_VERSION_95)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# Set archive_mode=always
|
|
|
|
$oHostDbMaster->clusterRestart({bArchiveAlways => true});
|
|
|
|
|
2017-12-04 00:08:49 +02:00
|
|
|
$oHostBackup->backup(
|
|
|
|
CFGOPTVAL_BACKUP_TYPE_INCR, 'fail on archive_mode=always', {iExpectedExitStatus => ERROR_FEATURE_NOT_SUPPORTED});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Reset the cluster to a normal state so the next test will work
|
|
|
|
$oHostDbMaster->clusterRestart();
|
|
|
|
}
|
|
|
|
|
|
|
|
# Incr backup
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Create a tablespace directory
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->tablespacePath(1), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Also create it on the standby so replay won't fail
|
|
|
|
if (defined($oHostDbStandby))
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbStandby->tablespacePath(1), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oHostDbMaster->sqlExecute(
|
|
|
|
"create tablespace ts1 location '" . $oHostDbMaster->tablespacePath(1) . "'", {bAutoCommit => true});
|
2017-06-27 22:47:40 +02:00
|
|
|
$oHostDbMaster->sqlExecute("alter table test set tablespace ts1");
|
|
|
|
|
|
|
|
# Create a table in the tablespace that will not be modified again to be sure it does get full page writes in the WAL later
|
|
|
|
$oHostDbMaster->sqlExecute("create table test_exists (id int) tablespace ts1", {bCommit => true, bCheckPoint => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create a table in the tablespace
|
|
|
|
$oHostDbMaster->sqlExecute("create table test_remove (id int)");
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strDefaultMessage'");
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2018-01-30 23:13:54 +02:00
|
|
|
# Create a database in the tablespace and a table to check
|
|
|
|
$oHostDbMaster->sqlExecute("create database test3 with tablespace ts1", {bAutoCommit => true});
|
|
|
|
$oHostDbMaster->sqlExecute(
|
|
|
|
'create table test3_exists (id int);' .
|
|
|
|
'insert into test3_exists values (1);',
|
|
|
|
{strDb => 'test3', bAutoCommit => true});
|
|
|
|
|
|
|
|
if ($bTestLocal)
|
|
|
|
{
|
|
|
|
# Create a table in test1 to check - test1 will not be restored
|
|
|
|
$oHostDbMaster->sqlExecute(
|
|
|
|
'create table test1_zeroed (id int);' .
|
|
|
|
'insert into test1_zeroed values (1);',
|
|
|
|
{strDb => 'test1', bAutoCommit => true});
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Start a backup so the next backup has to restart it. This test is not required for PostgreSQL >= 9.6 since backups
|
2019-08-26 18:05:36 +02:00
|
|
|
# are run in non-exclusive mode.
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal && $oHostDbMaster->pgVersion() >= PG_VERSION_93 && $oHostDbMaster->pgVersion() < PG_VERSION_96)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlSelectOne("select pg_start_backup('test backup that will cause an error', true)");
|
|
|
|
|
|
|
|
# Verify that an error is returned if the backup is already running
|
2017-12-04 00:08:49 +02:00
|
|
|
$oHostBackup->backup(
|
|
|
|
CFGOPTVAL_BACKUP_TYPE_INCR, 'fail on backup already running', {iExpectedExitStatus => ERROR_DB_QUERY});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restart the cluster ignoring any errors in the postgresql log
|
|
|
|
$oHostDbMaster->clusterRestart({bIgnoreLogError => true});
|
|
|
|
|
|
|
|
# Start a new backup to make the next test restart it
|
|
|
|
$oHostDbMaster->sqlSelectOne("select pg_start_backup('test backup that will be restarted', true)");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Drop a table
|
|
|
|
$oHostDbMaster->sqlExecute('drop table test_remove');
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strIncrMessage'", {bCommit => true});
|
|
|
|
|
2019-11-26 18:32:12 +02:00
|
|
|
# Exercise --delta checksum option
|
|
|
|
my $strIncrBackup = $oHostBackup->backup(
|
2020-03-09 23:41:59 +02:00
|
|
|
CFGOPTVAL_BACKUP_TYPE_INCR, 'update during backup', {strOptionalParam => '--stop-auto --buffer-size=32768 --delta'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2018-03-20 01:54:03 +02:00
|
|
|
# Ensure the check command runs properly with a tablespace unless there is a bogus host
|
|
|
|
if (!$oHostBackup->bogusHost())
|
|
|
|
{
|
|
|
|
$oHostBackup->check( 'check command with tablespace', {iTimeout => 5});
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Setup the xid target
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strXidTarget = undef;
|
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strXidMessage'", {bCommit => false});
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2016-12-23 15:22:59 +02:00
|
|
|
$strXidTarget = $oHostDbMaster->sqlSelectOne("select txid_current()");
|
|
|
|
$oHostDbMaster->sqlCommit();
|
|
|
|
&log(INFO, " xid target is ${strXidTarget}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Setup the name target
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strNameTarget = 'backrest';
|
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strNameMessage'", {bCommit => true});
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
if ($oHostDbMaster->pgVersion() >= PG_VERSION_91)
|
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute("select pg_create_restore_point('${strNameTarget}')");
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, " name target is ${strNameTarget}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a table and data in database test2
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2018-01-30 23:13:54 +02:00
|
|
|
|
|
|
|
# Initialize variables for SHA1 and path of the pg_filenode.map for the database that will not be restored
|
|
|
|
my $strDb1TablePath;
|
|
|
|
my $strDb1TableSha1;
|
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute(
|
|
|
|
'create table test (id int);' .
|
|
|
|
'insert into test values (1);' .
|
|
|
|
'create table test_ts1 (id int) tablespace ts1;' .
|
|
|
|
'insert into test_ts1 values (2);',
|
|
|
|
{strDb => 'test2', bAutoCommit => true});
|
2018-01-30 23:13:54 +02:00
|
|
|
|
2017-09-01 18:29:34 +02:00
|
|
|
$oHostDbMaster->sqlWalRotate();
|
2018-01-30 23:13:54 +02:00
|
|
|
|
|
|
|
# Get the SHA1 and path of the table for the database that will not be restored
|
|
|
|
$strDb1TablePath = $oHostDbMaster->dbBasePath(). "/base/" .
|
|
|
|
$oHostDbMaster->sqlSelectOne("select oid from pg_database where datname='test1'") . "/" .
|
|
|
|
$oHostDbMaster->sqlSelectOne("select relfilenode from pg_class where relname='test1_zeroed'", {strDb => 'test1'});
|
|
|
|
$strDb1TableSha1 = storageTest()->hashSize($strDb1TablePath);
|
2017-06-21 22:07:13 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restore (type = default)
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# Expect failure because postmaster.pid exists
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostDbMaster->restore('postmaster running', 'latest', {iExpectedExitStatus => ERROR_POSTMASTER_RUNNING});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# Expect failure because db path is not empty
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostDbMaster->restore('path not empty', 'latest', {iExpectedExitStatus => ERROR_PATH_NOT_EMPTY});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Drop and recreate db path
|
|
|
|
testPathRemove($oHostDbMaster->dbBasePath());
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbBasePath(), {strMode => '0700'});
|
2017-09-01 18:29:34 +02:00
|
|
|
testPathRemove($oHostDbMaster->dbPath() . qw{/} . $oManifest->walPath());
|
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbPath() . qw{/} . $oManifest->walPath(), {strMode => '0700'});
|
2016-12-23 15:22:59 +02:00
|
|
|
testPathRemove($oHostDbMaster->tablespacePath(1));
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->tablespacePath(1), {strMode => '0700'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Now the restore should work
|
|
|
|
$oHostDbMaster->restore(
|
2020-03-09 23:41:59 +02:00
|
|
|
undef, 'latest',
|
2018-01-30 23:13:54 +02:00
|
|
|
{strOptionalParam => ($bTestLocal ? ' --db-include=test2 --db-include=test3' : '') . ' --buffer-size=16384'});
|
|
|
|
|
|
|
|
# Test that the first database has not been restored since --db-include did not include test1
|
|
|
|
if ($bTestLocal)
|
|
|
|
{
|
|
|
|
my ($strSHA1, $lSize) = storageTest()->hashSize($strDb1TablePath);
|
|
|
|
|
2019-06-26 14:24:58 +02:00
|
|
|
# Create a zeroed sparse file in the test directory that is the same size as the filenode.map. We need to use the
|
|
|
|
# posix driver directly to do this because handles cannot be passed back from the C code.
|
|
|
|
my $oStorageTrunc = new pgBackRestTest::Common::Storage($self->testPath(), new pgBackRestTest::Common::StoragePosix());
|
|
|
|
|
2018-01-30 23:13:54 +02:00
|
|
|
my $strTestTable = $self->testPath() . "/testtable";
|
2019-06-26 14:24:58 +02:00
|
|
|
my $oDestinationFileIo = $oStorageTrunc->openWrite($strTestTable);
|
2018-01-30 23:13:54 +02:00
|
|
|
$oDestinationFileIo->open();
|
|
|
|
|
|
|
|
# Truncate to the original size which will create a sparse file.
|
2019-06-26 14:24:58 +02:00
|
|
|
if (!truncate($oDestinationFileIo->handle(), $lSize))
|
|
|
|
{
|
|
|
|
confess "unable to truncate '$strTestTable' with handle " . $oDestinationFileIo->handle();
|
|
|
|
}
|
2018-01-30 23:13:54 +02:00
|
|
|
$oDestinationFileIo->close();
|
|
|
|
|
|
|
|
# Confirm the test filenode.map and the database test1 filenode.map are zeroed
|
|
|
|
my ($strSHA1Test, $lSizeTest) = storageTest()->hashSize($strTestTable);
|
|
|
|
$self->testResult(sub {($strSHA1Test eq $strSHA1) && ($lSizeTest == $lSize) && ($strSHA1 ne $strDb1TableSha1)},
|
|
|
|
true, 'database test1 not restored');
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
2017-06-21 22:07:13 +02:00
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $bTestLocal ? $strNameMessage : $strIncrMessage);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2018-01-30 23:13:54 +02:00
|
|
|
# Once the cluster is back online, make sure the database & table in the tablespace exists properly
|
|
|
|
if ($bTestLocal)
|
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select id from test_ts1', 2, {strDb => 'test2'});
|
|
|
|
$oHostDbMaster->sqlDisconnect({strDb => 'test2'});
|
|
|
|
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select id from test3_exists', 1, {strDb => 'test3'});
|
|
|
|
$oHostDbMaster->sqlDisconnect({strDb => 'test3'});
|
|
|
|
}
|
|
|
|
|
2017-06-27 22:47:40 +02:00
|
|
|
# The tablespace path should exist and have files in it
|
|
|
|
my $strTablespacePath = $oHostDbMaster->tablespacePath(1);
|
|
|
|
|
|
|
|
# Version <= 8.4 always places a PG_VERSION file in the tablespace
|
|
|
|
if ($oHostDbMaster->pgVersion() <= PG_VERSION_84)
|
|
|
|
{
|
2020-03-06 21:10:09 +02:00
|
|
|
if (!storageTest()->exists("${strTablespacePath}/" . DB_FILE_PGVERSION))
|
2017-06-27 22:47:40 +02:00
|
|
|
{
|
|
|
|
confess &log(ASSERT, "unable to find '" . DB_FILE_PGVERSION . "' in tablespace path '${strTablespacePath}'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Version >= 9.0 creates a special path using the version and catalog number
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Backup info will have the catalog number
|
2020-03-10 21:41:56 +02:00
|
|
|
my $oBackupInfo = new pgBackRestDoc::Common::Ini(
|
2020-03-09 23:41:59 +02:00
|
|
|
storageRepo(), $oHostBackup->repoBackupPath(FILE_BACKUP_INFO),
|
|
|
|
{bLoad => false, strContent => ${storageRepo()->get($oHostBackup->repoBackupPath(FILE_BACKUP_INFO))}});
|
2017-06-27 22:47:40 +02:00
|
|
|
|
|
|
|
# Construct the special path
|
|
|
|
$strTablespacePath .=
|
|
|
|
'/PG_' . $oHostDbMaster->pgVersion() . qw{_} . $oBackupInfo->get(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_CATALOG);
|
|
|
|
|
|
|
|
# Check that path exists
|
2020-03-06 21:10:09 +02:00
|
|
|
if (!storageTest()->pathExists($strTablespacePath))
|
2017-06-27 22:47:40 +02:00
|
|
|
{
|
|
|
|
confess &log(ASSERT, "unable to find tablespace path '${strTablespacePath}'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure there are some files in the tablespace path (exclude PG_VERSION if <= 8.4 since that was tested above)
|
2020-03-06 21:10:09 +02:00
|
|
|
if (grep(!/^PG\_VERSION$/i, storageTest()->list($strTablespacePath)) == 0)
|
2017-06-27 22:47:40 +02:00
|
|
|
{
|
|
|
|
confess &log(ASSERT, "no files found in tablespace path '${strTablespacePath}'");
|
|
|
|
}
|
|
|
|
|
|
|
|
# This table should exist to prove that the tablespace was restored. It has not been updated since it was created so it
|
|
|
|
# should not be created by any full page writes. Once it is verified to exist it can be dropped.
|
|
|
|
$oHostDbMaster->sqlSelectOneTest("select count(*) from test_exists", 0);
|
|
|
|
$oHostDbMaster->sqlExecute('drop table test_exists');
|
|
|
|
|
2018-01-30 23:13:54 +02:00
|
|
|
# Now it should be OK to drop database test2 and test3
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute('drop database test2', {bAutoCommit => true});
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# The test table lives in ts1 so it needs to be moved or dropped
|
|
|
|
if ($oHostDbMaster->pgVersion() >= PG_VERSION_90)
|
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute('alter table test set tablespace pg_default');
|
|
|
|
}
|
|
|
|
# Drop for older versions
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oHostDbMaster->sqlExecute('drop table test');
|
|
|
|
}
|
|
|
|
|
|
|
|
# And drop the tablespace
|
2018-01-30 23:13:54 +02:00
|
|
|
$oHostDbMaster->sqlExecute('drop database test3', {bAutoCommit => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->sqlExecute("drop tablespace ts1", {bAutoCommit => true});
|
|
|
|
|
|
|
|
# Restore (restore type = immediate, inclusive)
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if (($bTestLocal || $bHostStandby) && $oHostDbMaster->pgVersion() >= PG_VERSION_94)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-12-04 00:08:49 +02:00
|
|
|
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_IMMEDIATE);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
2019-09-27 19:04:36 +02:00
|
|
|
$oHostDbMaster->restore(
|
|
|
|
undef, $strFullBackup, {bForce => true, strType => CFGOPTVAL_RESTORE_TYPE_IMMEDIATE, strTargetAction => 'promote'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
|
|
|
$oHostDbMaster->sqlSelectOneTest(
|
|
|
|
'select message from test', ($bHostStandby ? $strStandbyMessage : $strFullMessage));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restore (restore type = xid, inclusive)
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2019-09-27 16:27:07 +02:00
|
|
|
my $strRecoveryFile = undef;
|
|
|
|
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-12-04 00:08:49 +02:00
|
|
|
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_XID);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->dbBasePath() . "/*");
|
2017-09-01 18:29:34 +02:00
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->dbPath() . qw{/} . $oManifest->walPath() . '/*');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-12-04 00:08:49 +02:00
|
|
|
undef, $strIncrBackup,
|
|
|
|
{bForce => true, strType => CFGOPTVAL_RESTORE_TYPE_XID, strTarget => $strXidTarget,
|
|
|
|
strTargetAction => $oHostDbMaster->pgVersion() >= PG_VERSION_91 ? 'promote' : undef,
|
2019-10-01 19:20:43 +02:00
|
|
|
strTargetTimeline => $oHostDbMaster->pgVersion() >= PG_VERSION_12 ? 'current' : undef,
|
2017-12-04 00:08:49 +02:00
|
|
|
strOptionalParam => '--tablespace-map-all=../../tablespace', bTablespace => false});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Save recovery file to test so we can use it in the next test
|
2019-10-01 19:20:43 +02:00
|
|
|
$strRecoveryFile = $oHostDbMaster->pgVersion() >= PG_VERSION_12 ? 'postgresql.auto.conf' : DB_FILE_RECOVERYCONF;
|
2019-09-27 16:27:07 +02:00
|
|
|
|
2020-03-06 21:10:09 +02:00
|
|
|
storageTest()->copy(
|
2019-09-27 16:27:07 +02:00
|
|
|
$oHostDbMaster->dbBasePath() . qw{/} . $strRecoveryFile, $self->testPath() . qw{/} . $strRecoveryFile);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $strXidMessage);
|
|
|
|
|
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strTimelineMessage'");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restore (restore type = preserve, inclusive)
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-12-04 00:08:49 +02:00
|
|
|
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_PRESERVE);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->dbBasePath() . "/*");
|
2017-09-01 18:29:34 +02:00
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->dbPath() . qw{/} . $oManifest->walPath() . '/*');
|
2016-12-23 15:22:59 +02:00
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->tablespacePath(1) . "/*");
|
|
|
|
|
|
|
|
# Restore recovery file that was saved in last test
|
2020-03-06 21:10:09 +02:00
|
|
|
storageTest()->move($self->testPath . "/${strRecoveryFile}", $oHostDbMaster->dbBasePath() . "/${strRecoveryFile}");
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2019-10-12 15:26:19 +02:00
|
|
|
# Also touch recovery.signal when required
|
|
|
|
if ($oHostDbMaster->pgVersion() >= PG_VERSION_12)
|
|
|
|
{
|
2020-03-06 21:10:09 +02:00
|
|
|
storageTest()->put($oHostDbMaster->dbBasePath() . "/" . DB_FILE_RECOVERYSIGNAL);
|
2019-10-12 15:26:19 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostDbMaster->restore(undef, 'latest', {strType => CFGOPTVAL_RESTORE_TYPE_PRESERVE});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $strXidMessage);
|
|
|
|
|
|
|
|
$oHostDbMaster->sqlExecute("update test set message = '$strTimelineMessage'");
|
|
|
|
}
|
|
|
|
|
2020-01-30 23:38:05 +02:00
|
|
|
# Restore (restore type = time, inclusive, automatically select backup) - there is no exclusive time test because I can't
|
|
|
|
# find a way to find the exact commit time of a transaction.
|
2016-12-23 15:22:59 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-12-04 00:08:49 +02:00
|
|
|
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_TIME);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2020-03-09 23:41:59 +02:00
|
|
|
undef, 'latest',
|
2019-09-27 19:04:36 +02:00
|
|
|
{bDelta => true, strType => CFGOPTVAL_RESTORE_TYPE_TIME, strTarget => $strTimeTarget,
|
2019-10-01 19:20:43 +02:00
|
|
|
strTargetAction => $oHostDbMaster->pgVersion() >= PG_VERSION_91 ? 'promote' : undef,
|
2020-01-30 23:38:05 +02:00
|
|
|
strTargetTimeline => $oHostDbMaster->pgVersion() >= PG_VERSION_12 ? 'current' : undef,
|
|
|
|
strBackupExpected => $strFullBackup});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $strTimeMessage);
|
|
|
|
|
|
|
|
# Restore (restore type = xid, exclusive)
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-12-04 00:08:49 +02:00
|
|
|
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_XID);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-12-04 00:08:49 +02:00
|
|
|
undef, $strIncrBackup,
|
2019-09-27 19:04:36 +02:00
|
|
|
{bDelta => true, strType => CFGOPTVAL_RESTORE_TYPE_XID, strTarget => $strXidTarget, bTargetExclusive => true,
|
2019-10-01 19:20:43 +02:00
|
|
|
strTargetAction => $oHostDbMaster->pgVersion() >= PG_VERSION_91 ? 'promote' : undef,
|
|
|
|
strTargetTimeline => $oHostDbMaster->pgVersion() >= PG_VERSION_12 ? 'current' : undef});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $strIncrMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restore (restore type = name)
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal && $oHostDbMaster->pgVersion() >= PG_VERSION_91)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-12-04 00:08:49 +02:00
|
|
|
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_NAME);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2020-03-09 23:41:59 +02:00
|
|
|
undef, 'latest',
|
2019-09-27 19:04:36 +02:00
|
|
|
{bDelta => true, bForce => true, strType => CFGOPTVAL_RESTORE_TYPE_NAME, strTarget => $strNameTarget,
|
2019-10-01 19:20:43 +02:00
|
|
|
strTargetAction => 'promote',
|
|
|
|
strTargetTimeline => $oHostDbMaster->pgVersion() >= PG_VERSION_12 ? 'current' : undef});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart();
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $strNameMessage);
|
|
|
|
}
|
|
|
|
|
2019-09-27 19:37:59 +02:00
|
|
|
# Restore (restore type = default, timeline = created by type = xid, inclusive recovery)
|
2016-12-23 15:22:59 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestLocal && $oHostDbMaster->pgVersion() >= PG_VERSION_84)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-12-04 00:08:49 +02:00
|
|
|
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_DEFAULT);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStop();
|
|
|
|
|
2019-09-27 19:37:59 +02:00
|
|
|
# The timeline to use for this test is subject to change based on tests being added or removed above. The best thing
|
|
|
|
# would be to automatically grab the timeline after the restore, but since this test has been stable for a long time
|
|
|
|
# it does not seem worth the effort to automate.
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->restore(
|
2017-12-04 00:08:49 +02:00
|
|
|
undef, $strIncrBackup,
|
2019-09-26 23:39:45 +02:00
|
|
|
{bDelta => true,
|
|
|
|
strType => $oHostDbMaster->pgVersion() >= PG_VERSION_90 ?
|
|
|
|
CFGOPTVAL_RESTORE_TYPE_STANDBY : CFGOPTVAL_RESTORE_TYPE_DEFAULT,
|
|
|
|
strTargetTimeline => 4});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->clusterStart({bHotStandby => true});
|
|
|
|
$oHostDbMaster->sqlSelectOneTest('select message from test', $strTimelineMessage, {iTimeout => 120});
|
|
|
|
}
|
|
|
|
|
2017-02-03 03:44:42 +02:00
|
|
|
# Stop clusters to catch any errors in the postgres log
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-07-24 13:57:47 +02:00
|
|
|
$oHostDbMaster->clusterStop();
|
2017-02-03 03:44:42 +02:00
|
|
|
|
|
|
|
# Test no-online backups
|
2016-12-23 15:22:59 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-21 22:07:13 +02:00
|
|
|
if ($bTestExtra & !$bS3)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-02-03 03:44:42 +02:00
|
|
|
# Create a postmaster.pid file so it appears that the server is running
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->put($oHostDbMaster->dbBasePath() . '/postmaster.pid', '99999');
|
2017-02-03 03:44:42 +02:00
|
|
|
|
|
|
|
# Incr backup - make sure a --no-online backup fails
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostBackup->backup(
|
2020-03-09 23:41:59 +02:00
|
|
|
CFGOPTVAL_BACKUP_TYPE_INCR, 'fail on --no-online',
|
|
|
|
{iExpectedExitStatus => ERROR_POSTMASTER_RUNNING, strOptionalParam => '--no-online'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-02-03 03:44:42 +02:00
|
|
|
# Incr backup - allow --no-online backup to succeed with --force
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostBackup->backup(
|
2020-03-09 23:41:59 +02:00
|
|
|
CFGOPTVAL_BACKUP_TYPE_INCR, 'succeed on --no-online with --force', {strOptionalParam => '--no-online --force'});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
2019-05-15 19:14:58 +02:00
|
|
|
|
|
|
|
# Stanza-delete --force without access to pgbackrest on database host
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($bTestExtra && !$bS3 && $bHostBackup)
|
|
|
|
{
|
2019-08-26 18:05:36 +02:00
|
|
|
# With stanza-delete --force, allow stanza to be deleted regardless of accessibility of database host
|
2019-05-15 19:14:58 +02:00
|
|
|
if ($bHostBackup)
|
|
|
|
{
|
|
|
|
$oHostDbMaster->stop();
|
|
|
|
$oHostBackup->stop({strStanza => $self->stanza});
|
2020-03-09 23:41:59 +02:00
|
|
|
$oHostBackup->stanzaDelete(
|
|
|
|
"delete stanza with --force when pgbackrest on pg host not accessible", {strOptionalParam => ' --force'});
|
2019-05-15 19:14:58 +02:00
|
|
|
$oHostDbMaster->start();
|
|
|
|
$oHostBackup->start();
|
|
|
|
}
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-12 16:52:32 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|