mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
d0b6f78b20
Master and standby can both be configured on the backup server and pgBackRest will automatically determine which is the master. This means no configuration changes for backup are required after failing over from a master to standby when a separate backup server is used.
136 lines
4.9 KiB
Perl
136 lines
4.9 KiB
Perl
####################################################################################################################################
|
|
# 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();
|
|
|
|
use pgBackRest::Common::Log;
|
|
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();
|
|
|
|
# Create the backup host
|
|
my $strBackupDestination;
|
|
my $bHostBackup = defined($$oConfigParam{bHostBackup}) ? $$oConfigParam{bHostBackup} : false;
|
|
my $oHostBackup = undef;
|
|
|
|
if ($bHostBackup)
|
|
{
|
|
$strBackupDestination = defined($$oConfigParam{strBackupDestination}) ? $$oConfigParam{strBackupDestination} : HOST_BACKUP;
|
|
|
|
$oHostBackup = new pgBackRestTest::Backup::Common::HostBackupTest(
|
|
{strBackupDestination => $strBackupDestination, bSynthetic => $bSynthetic, oLogTest => $oLogTest});
|
|
$oHostGroup->hostAdd($oHostBackup);
|
|
}
|
|
else
|
|
{
|
|
$strBackupDestination =
|
|
defined($$oConfigParam{strBackupDestination}) ? $$oConfigParam{strBackupDestination} : HOST_DB_MASTER;
|
|
}
|
|
|
|
# Create the db-master host
|
|
my $oHostDbMaster = undef;
|
|
|
|
if ($bSynthetic)
|
|
{
|
|
$oHostDbMaster = new pgBackRestTest::Backup::Common::HostDbSyntheticTest(
|
|
{strBackupDestination => $strBackupDestination, oLogTest => $oLogTest});
|
|
}
|
|
else
|
|
{
|
|
$oHostDbMaster = new pgBackRestTest::Backup::Common::HostDbTest(
|
|
{strBackupDestination => $strBackupDestination, oLogTest => $oLogTest});
|
|
}
|
|
|
|
$oHostGroup->hostAdd($oHostDbMaster);
|
|
|
|
# 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);
|
|
}
|
|
|
|
# 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
|
|
$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))
|
|
{
|
|
$oHostDbStandby->configCreate({
|
|
strBackupSource => $$oConfigParam{strBackupSource},
|
|
bCompress => $$oConfigParam{bCompress},
|
|
bHardlink => $bHostBackup ? undef : $$oConfigParam{bHardLink},
|
|
bArchiveAsync => $$oConfigParam{bArchiveAsync}});
|
|
}
|
|
|
|
return $oHostDbMaster, $oHostDbStandby, $oHostBackup, $oFile;
|
|
}
|
|
|
|
push @EXPORT, qw(backupTestSetup);
|
|
|
|
1;
|