You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-12-13 23:25:51 +02:00
More flexible configuration for databases
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.
This commit is contained in:
81
lib/pgBackRest/ArchiveCommon.pm
Normal file
81
lib/pgBackRest/ArchiveCommon.pm
Normal file
@@ -0,0 +1,81 @@
|
||||
####################################################################################################################################
|
||||
# ARCHIVE COMMON MODULE
|
||||
####################################################################################################################################
|
||||
package pgBackRest::ArchiveCommon;
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw();
|
||||
|
||||
use pgBackRest::DbVersion;
|
||||
use pgBackRest::Common::Log;
|
||||
|
||||
####################################################################################################################################
|
||||
# lsnFileRange
|
||||
#
|
||||
# Generates a range of WAL filenames given the start and stop LSN. For pre-9.3 databases, use bSkipFF to exclude the FF that
|
||||
# prior versions did not generate.
|
||||
####################################################################################################################################
|
||||
sub lsnFileRange
|
||||
{
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$strLsnStart,
|
||||
$strLsnStop,
|
||||
$strDbVersion,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . 'lsnFileRange', \@_,
|
||||
{name => 'strLsnStart'},
|
||||
{name => 'strLsnStop'},
|
||||
{name => '$strDbVersion'},
|
||||
);
|
||||
|
||||
# Working variables
|
||||
my @stryArchive;
|
||||
my $iArchiveIdx = 0;
|
||||
my $bSkipFF = $strDbVersion < PG_VERSION_93;
|
||||
|
||||
# Iterate through all archive logs between start and stop
|
||||
my @stryArchiveSplit = split('/', $strLsnStart);
|
||||
my $iStartMajor = hex($stryArchiveSplit[0]);
|
||||
my $iStartMinor = hex(substr(sprintf("%08s", $stryArchiveSplit[1]), 0, 2));
|
||||
|
||||
@stryArchiveSplit = split('/', $strLsnStop);
|
||||
my $iStopMajor = hex($stryArchiveSplit[0]);
|
||||
my $iStopMinor = hex(substr(sprintf("%08s", $stryArchiveSplit[1]), 0, 2));
|
||||
|
||||
$stryArchive[$iArchiveIdx] = uc(sprintf("%08x%08x", $iStartMajor, $iStartMinor));
|
||||
$iArchiveIdx += 1;
|
||||
|
||||
while (!($iStartMajor == $iStopMajor && $iStartMinor == $iStopMinor))
|
||||
{
|
||||
$iStartMinor += 1;
|
||||
|
||||
if ($bSkipFF && $iStartMinor == 255 || !$bSkipFF && $iStartMinor == 256)
|
||||
{
|
||||
$iStartMajor += 1;
|
||||
$iStartMinor = 0;
|
||||
}
|
||||
|
||||
$stryArchive[$iArchiveIdx] = uc(sprintf("%08x%08x", $iStartMajor, $iStartMinor));
|
||||
$iArchiveIdx += 1;
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'stryWalFileName', value => \@stryArchive}
|
||||
);
|
||||
}
|
||||
|
||||
push @EXPORT, qw(lsnFileRange);
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user