2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackupCommonTest.pm - Common code for backup unit tests
|
|
|
|
####################################################################################################################################
|
|
|
|
package pgBackRestTest::Backup::BackupCommonTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# 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;
|
|
|
|
|
|
|
|
use pgBackRestTest::Backup::Common::HostBackupTest;
|
|
|
|
use pgBackRestTest::Backup::Common::HostBaseTest;
|
|
|
|
use pgBackRestTest::Backup::Common::HostDbCommonTest;
|
|
|
|
use pgBackRestTest::Backup::Common::HostDbTest;
|
|
|
|
use pgBackRestTest::Backup::Common::HostDbSyntheticTest;
|
|
|
|
use pgBackRestTest::Common::HostGroupTest;
|
|
|
|
use pgBackRestTest::CommonTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# backupTestSetup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub backupTestSetup
|
|
|
|
{
|
|
|
|
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-06-24 14:12:58 +02:00
|
|
|
$oHostBackup = new pgBackRestTest::Backup::Common::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)
|
|
|
|
{
|
|
|
|
$oHostDbMaster = new pgBackRestTest::Backup::Common::HostDbSyntheticTest(
|
2016-08-24 18:39:27 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, oLogTest => $oLogTest});
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-24 18:39:27 +02:00
|
|
|
$oHostDbMaster = new pgBackRestTest::Backup::Common::HostDbTest(
|
|
|
|
{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})
|
|
|
|
{
|
|
|
|
$oHostDbStandby = new pgBackRestTest::Backup::Common::HostDbTest(
|
|
|
|
{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
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(backupTestSetup);
|
|
|
|
|
|
|
|
1;
|