2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2017-01-05 01:31:16 +02:00
|
|
|
# FullCommonTest.pm - Common code for backup tests
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2017-01-27 16:42:30 +02:00
|
|
|
package pgBackRestTest::Common::Env::EnvHostTest;
|
|
|
|
use parent 'pgBackRestTest::Config::ConfigEnvTest';
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
use pgBackRest::Common::Log;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRest::Config::Config;
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRest::File;
|
|
|
|
use pgBackRest::FileCommon;
|
|
|
|
|
|
|
|
use pgBackRestTest::Common::Host::HostBackupTest;
|
|
|
|
use pgBackRestTest::Common::Host::HostBaseTest;
|
|
|
|
use pgBackRestTest::Common::Host::HostDbCommonTest;
|
|
|
|
use pgBackRestTest::Common::Host::HostDbTest;
|
|
|
|
use pgBackRestTest::Common::Host::HostDbSyntheticTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::HostGroupTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2016-12-23 15:22:59 +02:00
|
|
|
# Constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant WAL_VERSION_94 => '94';
|
|
|
|
push @EXPORT, qw(WAL_VERSION_94);
|
2017-01-27 18:02:27 +02:00
|
|
|
use constant WAL_VERSION_94_SYS_ID => 6353949018581704918;
|
|
|
|
push @EXPORT, qw(WAL_VERSION_94_SYS_ID);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2017-01-27 16:42:30 +02:00
|
|
|
# initModule
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2017-01-27 16:42:30 +02:00
|
|
|
sub initModule
|
2016-06-24 14:12:58 +02:00
|
|
|
{
|
2016-12-23 15:22:59 +02:00
|
|
|
# Set file and path modes
|
|
|
|
pathModeDefaultSet('0700');
|
|
|
|
fileModeDefaultSet('0600');
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub setup
|
|
|
|
{
|
|
|
|
my $self = shift;
|
2016-06-24 14:12:58 +02:00
|
|
|
my $bSynthetic = shift;
|
|
|
|
my $oLogTest = shift;
|
|
|
|
my $oConfigParam = shift;
|
|
|
|
|
|
|
|
# Get host group
|
|
|
|
my $oHostGroup = hostGroupGet();
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
# Create the backup host
|
|
|
|
my $strBackupDestination;
|
|
|
|
my $bHostBackup = defined($$oConfigParam{bHostBackup}) ? $$oConfigParam{bHostBackup} : false;
|
2016-06-24 14:12:58 +02:00
|
|
|
my $oHostBackup = undef;
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
if ($bHostBackup)
|
2016-06-24 14:12:58 +02:00
|
|
|
{
|
2016-08-24 18:39:27 +02:00
|
|
|
$strBackupDestination = defined($$oConfigParam{strBackupDestination}) ? $$oConfigParam{strBackupDestination} : HOST_BACKUP;
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostBackup = new pgBackRestTest::Common::Host::HostBackupTest(
|
2016-08-24 18:39:27 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, bSynthetic => $bSynthetic, oLogTest => $oLogTest});
|
2016-06-24 14:12:58 +02:00
|
|
|
$oHostGroup->hostAdd($oHostBackup);
|
|
|
|
}
|
2016-08-24 18:39:27 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$strBackupDestination =
|
|
|
|
defined($$oConfigParam{strBackupDestination}) ? $$oConfigParam{strBackupDestination} : HOST_DB_MASTER;
|
|
|
|
}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
# Create the db-master host
|
2016-06-24 14:12:58 +02:00
|
|
|
my $oHostDbMaster = undef;
|
|
|
|
|
|
|
|
if ($bSynthetic)
|
|
|
|
{
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster = new pgBackRestTest::Common::Host::HostDbSyntheticTest(
|
2016-08-24 18:39:27 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, oLogTest => $oLogTest});
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster = new pgBackRestTest::Common::Host::HostDbTest(
|
2016-08-24 18:39:27 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, oLogTest => $oLogTest});
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oHostGroup->hostAdd($oHostDbMaster);
|
2016-08-24 18:39:27 +02:00
|
|
|
|
|
|
|
# Create the db-standby host
|
|
|
|
my $oHostDbStandby = undef;
|
|
|
|
|
|
|
|
if (defined($$oConfigParam{bStandby}) && $$oConfigParam{bStandby})
|
|
|
|
{
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbStandby = new pgBackRestTest::Common::Host::HostDbTest(
|
2016-08-24 18:39:27 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, bStandby => true, oLogTest => $oLogTest});
|
|
|
|
|
|
|
|
$oHostGroup->hostAdd($oHostDbStandby);
|
|
|
|
}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
# Create the local file object
|
|
|
|
my $oFile =
|
|
|
|
new pgBackRest::File
|
|
|
|
(
|
|
|
|
$oHostDbMaster->stanza(),
|
|
|
|
$oHostDbMaster->repoPath(),
|
|
|
|
new pgBackRest::Protocol::Common
|
|
|
|
(
|
|
|
|
OPTION_DEFAULT_BUFFER_SIZE, # Buffer size
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL, # Compress level
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK, # Compress network level
|
|
|
|
HOST_PROTOCOL_TIMEOUT # Protocol timeout
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
# Create db master config
|
2016-08-24 18:39:27 +02:00
|
|
|
$oHostDbMaster->configCreate({
|
|
|
|
strBackupSource => $$oConfigParam{strBackupSource},
|
|
|
|
bCompress => $$oConfigParam{bCompress},
|
|
|
|
bHardlink => $bHostBackup ? undef : $$oConfigParam{bHardLink},
|
|
|
|
bArchiveAsync => $$oConfigParam{bArchiveAsync}});
|
|
|
|
|
|
|
|
# Create backup config if backup host exists
|
|
|
|
if (defined($oHostBackup))
|
|
|
|
{
|
|
|
|
$oHostBackup->configCreate({
|
|
|
|
bCompress => $$oConfigParam{bCompress},
|
|
|
|
bHardlink => $$oConfigParam{bHardLink}});
|
|
|
|
}
|
|
|
|
# If backup host is not defined set it to db-master
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oHostBackup = $strBackupDestination eq HOST_DB_MASTER ? $oHostDbMaster : $oHostDbStandby;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create db-standby config
|
|
|
|
if (defined($oHostDbStandby))
|
2016-06-24 14:12:58 +02:00
|
|
|
{
|
2016-08-24 18:39:27 +02:00
|
|
|
$oHostDbStandby->configCreate({
|
|
|
|
strBackupSource => $$oConfigParam{strBackupSource},
|
|
|
|
bCompress => $$oConfigParam{bCompress},
|
|
|
|
bHardlink => $bHostBackup ? undef : $$oConfigParam{bHardLink},
|
|
|
|
bArchiveAsync => $$oConfigParam{bArchiveAsync}});
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
return $oHostDbMaster, $oHostDbStandby, $oHostBackup, $oFile;
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# archiveGenerate
|
|
|
|
#
|
|
|
|
# Generate an WAL segment for testing.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub archiveGenerate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $oFile = shift;
|
|
|
|
my $strXlogPath = shift;
|
|
|
|
my $iSourceNo = shift;
|
|
|
|
my $iArchiveNo = shift;
|
|
|
|
my $strWalVersion = shift;
|
|
|
|
my $bPartial = shift;
|
|
|
|
|
|
|
|
my $strArchiveFile = uc(sprintf('0000000100000001%08x', $iArchiveNo)) .
|
|
|
|
(defined($bPartial) && $bPartial ? '.partial' : '');
|
|
|
|
my $strArchiveTestFile = $self->dataPath() . "/backup.wal${iSourceNo}_${strWalVersion}.bin";
|
|
|
|
|
|
|
|
my $strSourceFile = "${strXlogPath}/${strArchiveFile}";
|
|
|
|
|
|
|
|
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile, # Source file
|
|
|
|
PATH_DB_ABSOLUTE, $strSourceFile, # Destination file
|
|
|
|
false, # Source is not compressed
|
|
|
|
false); # Destination is not compressed
|
|
|
|
|
|
|
|
return $strArchiveFile, $strSourceFile;
|
|
|
|
}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2017-01-27 18:02:27 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# walSegment
|
|
|
|
#
|
|
|
|
# Generate name of WAL segment from component parts.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walSegment
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $iTimeline = shift;
|
|
|
|
my $iMajor = shift;
|
|
|
|
my $iMinor = shift;
|
|
|
|
|
|
|
|
return uc(sprintf('%08x%08x%08x', $iTimeline, $iMajor, $iMinor));
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# walGenerate
|
|
|
|
#
|
|
|
|
# Generate a WAL segment and ready file for testing.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walGenerate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $oFile = shift;
|
|
|
|
my $strWalPath = shift;
|
|
|
|
my $strPgVersion = shift;
|
|
|
|
my $iSourceNo = shift;
|
|
|
|
my $strWalSegment = shift;
|
|
|
|
my $bPartial = shift;
|
|
|
|
|
|
|
|
my $strWalFile = "${strWalPath}/${strWalSegment}" . (defined($bPartial) && $bPartial ? '.partial' : '');
|
|
|
|
my $strArchiveTestFile = $self->dataPath() . "/backup.wal${iSourceNo}_${strPgVersion}.bin";
|
|
|
|
|
|
|
|
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile, # Source file
|
|
|
|
PATH_DB_ABSOLUTE, $strWalFile, # Destination file
|
|
|
|
false, # Source is not compressed
|
|
|
|
false); # Destination is not compressed
|
|
|
|
|
|
|
|
fileStringWrite("${strWalPath}/archive_status/${strWalSegment}.ready");
|
|
|
|
|
|
|
|
return $strWalFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# walRemove
|
|
|
|
#
|
|
|
|
# Remove WAL file and ready file.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walRemove
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strWalPath = shift;
|
|
|
|
my $strWalFile = shift;
|
|
|
|
|
|
|
|
fileRemove("$self->{strWalPath}/${strWalFile}");
|
|
|
|
fileRemove("$self->{strWalPath}/archive_status/${strWalFile}.ready");
|
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
1;
|