2015-09-02 01:05:10 +02:00
|
|
|
####################################################################################################################################
|
2015-10-28 11:10:36 +02:00
|
|
|
# ExpireCommonTest.pm - Common code for expire tests
|
2015-09-02 01:05:10 +02:00
|
|
|
####################################################################################################################################
|
2017-05-12 22:43:04 +02:00
|
|
|
package pgBackRestTest::Env::ExpireEnvTest;
|
2017-11-19 03:02:54 +02:00
|
|
|
use parent 'pgBackRestTest::Env::HostEnvTest';
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
2020-03-06 14:21:17 +02:00
|
|
|
use Fcntl qw(O_RDONLY);
|
2017-06-09 23:51:41 +02:00
|
|
|
use File::Basename qw(basename);
|
|
|
|
|
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
|
|
|
|
|
|
|
use pgBackRestTest::Common::DbVersion;
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::FileTest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRestTest::Common::RunTest;
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Common::StorageRepo;
|
|
|
|
use pgBackRestTest::Env::ArchiveInfo;
|
|
|
|
use pgBackRestTest::Env::BackupInfo;
|
|
|
|
use pgBackRestTest::Env::HostEnvTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostBaseTest;
|
|
|
|
use pgBackRestTest::Env::Manifest;
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# new
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
|
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(
|
|
|
|
my $strOperation,
|
2016-06-24 14:12:58 +02:00
|
|
|
$self->{oHostBackup},
|
2016-12-23 15:22:59 +02:00
|
|
|
$self->{strBackRestExe},
|
2017-06-09 23:51:41 +02:00
|
|
|
$self->{oStorageRepo},
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->{strPgPath},
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->{oRunTest},
|
2015-09-02 01:05:10 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->new', \@_,
|
2017-02-05 17:31:29 +02:00
|
|
|
{name => 'oHostBackup', required => false, trace => true},
|
2016-12-23 15:22:59 +02:00
|
|
|
{name => 'strBackRestExe', trace => true},
|
2017-06-09 23:51:41 +02:00
|
|
|
{name => 'oStorageRepo', trace => true},
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'strPgPath', trace => true},
|
2017-04-03 16:42:55 +02:00
|
|
|
{name => 'oRunTest', required => false, trace => true},
|
2015-09-02 01:05:10 +02:00
|
|
|
);
|
|
|
|
|
2018-09-25 11:24:42 +02:00
|
|
|
$self->{strVm} = $self->{oRunTest}->vm();
|
|
|
|
|
2015-09-02 01:05:10 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-06 14:21:17 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# get into from pg_control
|
|
|
|
####################################################################################################################################
|
|
|
|
my $oPgControlVersionHash =
|
|
|
|
{
|
|
|
|
# iControlVersion => {iCatalogVersion => strDbVersion}
|
|
|
|
937 => {201306121 => PG_VERSION_93},
|
|
|
|
942 =>
|
|
|
|
{
|
|
|
|
201409291 => PG_VERSION_94,
|
|
|
|
201510051 => PG_VERSION_95,
|
|
|
|
},
|
|
|
|
960 =>
|
|
|
|
{
|
|
|
|
201608131 => PG_VERSION_96,
|
|
|
|
},
|
|
|
|
1002 =>
|
|
|
|
{
|
|
|
|
201707211 => PG_VERSION_10,
|
|
|
|
},
|
|
|
|
1100 =>
|
|
|
|
{
|
|
|
|
201809051 => PG_VERSION_11,
|
|
|
|
},
|
|
|
|
1201 =>
|
|
|
|
{
|
|
|
|
201909212 => PG_VERSION_12,
|
|
|
|
},
|
2020-05-21 19:46:16 +02:00
|
|
|
1300 =>
|
|
|
|
{
|
2020-09-17 18:39:30 +02:00
|
|
|
202007201 => PG_VERSION_13,
|
2020-05-21 19:46:16 +02:00
|
|
|
},
|
2020-03-06 14:21:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
sub info
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strDbPath
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->info', \@_,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'strDbPath', default => $self->{strPgPath}}
|
2020-03-06 14:21:17 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Open the control file and read system id and versions
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strControlFile = "${strDbPath}/" . DB_FILE_PGCONTROL;
|
|
|
|
my $hFile;
|
|
|
|
my $tBlock;
|
|
|
|
|
|
|
|
sysopen($hFile, $strControlFile, O_RDONLY)
|
|
|
|
or confess &log(ERROR, "unable to open ${strControlFile}", ERROR_FILE_OPEN);
|
|
|
|
|
|
|
|
# Read system identifier
|
|
|
|
sysread($hFile, $tBlock, 8) == 8
|
|
|
|
or confess &log(ERROR, "unable to read database system identifier");
|
|
|
|
|
|
|
|
$self->{info}{$strDbPath}{ullDbSysId} = unpack('Q', $tBlock);
|
|
|
|
|
|
|
|
# Read control version
|
|
|
|
sysread($hFile, $tBlock, 4) == 4
|
|
|
|
or confess &log(ERROR, "unable to read control version");
|
|
|
|
|
|
|
|
$self->{info}{$strDbPath}{iDbControlVersion} = unpack('L', $tBlock);
|
|
|
|
|
|
|
|
# Read catalog version
|
|
|
|
sysread($hFile, $tBlock, 4) == 4
|
|
|
|
or confess &log(ERROR, "unable to read catalog version");
|
|
|
|
|
|
|
|
$self->{info}{$strDbPath}{iDbCatalogVersion} = unpack('L', $tBlock);
|
|
|
|
|
|
|
|
# Close the control file
|
|
|
|
close($hFile);
|
|
|
|
|
|
|
|
# Get PostgreSQL version
|
|
|
|
$self->{info}{$strDbPath}{strDbVersion} =
|
|
|
|
$oPgControlVersionHash->{$self->{info}{$strDbPath}{iDbControlVersion}}
|
|
|
|
{$self->{info}{$strDbPath}{iDbCatalogVersion}};
|
|
|
|
|
|
|
|
if (!defined($self->{info}{$strDbPath}{strDbVersion}))
|
|
|
|
{
|
|
|
|
confess &log(
|
|
|
|
ERROR,
|
|
|
|
'unexpected control version = ' . $self->{info}{$strDbPath}{iDbControlVersion} .
|
|
|
|
' and catalog version = ' . $self->{info}{$strDbPath}{iDbCatalogVersion} . "\n" .
|
2020-03-09 23:41:59 +02:00
|
|
|
'HINT: is this version of PostgreSQL supported?');
|
2020-03-06 14:21:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'strDbVersion', value => $self->{info}{$strDbPath}{strDbVersion}},
|
|
|
|
{name => 'iDbControlVersion', value => $self->{info}{$strDbPath}{iDbControlVersion}},
|
|
|
|
{name => 'iDbCatalogVersion', value => $self->{info}{$strDbPath}{iDbCatalogVersion}},
|
|
|
|
{name => 'ullDbSysId', value => $self->{info}{$strDbPath}{ullDbSysId}}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-02 01:05:10 +02:00
|
|
|
####################################################################################################################################
|
2017-04-03 16:42:55 +02:00
|
|
|
# stanzaSet - set the local stanza object
|
2015-09-02 01:05:10 +02:00
|
|
|
####################################################################################################################################
|
2017-04-03 16:42:55 +02:00
|
|
|
sub stanzaSet
|
2015-09-02 01:05:10 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
2017-04-03 16:42:55 +02:00
|
|
|
$strDbVersion,
|
|
|
|
$bStanzaUpgrade,
|
2015-09-02 01:05:10 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2017-04-03 16:42:55 +02:00
|
|
|
__PACKAGE__ . '->stanzaSet', \@_,
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strStanza'},
|
2017-04-03 16:42:55 +02:00
|
|
|
{name => 'strDbVersion'},
|
|
|
|
{name => 'bStanzaUpgrade'},
|
2015-09-02 01:05:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Assign variables
|
|
|
|
my $oStanza = {};
|
2019-08-21 22:26:28 +02:00
|
|
|
my $oArchiveInfo = {};
|
|
|
|
my $oBackupInfo = {};
|
|
|
|
my $iArchiveDbId = 1;
|
|
|
|
my $iBackupDbId = 1;
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
# If we're not upgrading, then create the info files
|
2017-04-03 16:42:55 +02:00
|
|
|
if (!$bStanzaUpgrade)
|
|
|
|
{
|
2019-08-21 22:26:28 +02:00
|
|
|
$oArchiveInfo =
|
2020-03-10 21:12:44 +02:00
|
|
|
new pgBackRestTest::Env::ArchiveInfo($self->{oHostBackup}->repoArchivePath(), false,
|
2020-03-09 23:41:59 +02:00
|
|
|
{bIgnoreMissing => true, strCipherPassSub => $self->{oHostBackup}->repoEncrypt() ? ENCRYPTION_KEY_ARCHIVE : undef});
|
2019-08-21 22:26:28 +02:00
|
|
|
$oBackupInfo =
|
2020-03-10 21:12:44 +02:00
|
|
|
new pgBackRestTest::Env::BackupInfo($self->{oHostBackup}->repoBackupPath(), false,
|
2020-03-09 23:41:59 +02:00
|
|
|
{bIgnoreMissing => true, strCipherPassSub => $self->{oHostBackup}->repoEncrypt() ? ENCRYPTION_KEY_MANIFEST : undef});
|
2019-08-21 22:26:28 +02:00
|
|
|
}
|
|
|
|
# Else get the info data from disk
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oArchiveInfo =
|
2020-03-10 21:12:44 +02:00
|
|
|
new pgBackRestTest::Env::ArchiveInfo($self->{oHostBackup}->repoArchivePath(),
|
2020-03-09 23:41:59 +02:00
|
|
|
{strCipherPassSub => $self->{oHostBackup}->repoEncrypt() ? ENCRYPTION_KEY_ARCHIVE : undef});
|
2019-08-21 22:26:28 +02:00
|
|
|
$oBackupInfo =
|
2020-03-10 21:12:44 +02:00
|
|
|
new pgBackRestTest::Env::BackupInfo($self->{oHostBackup}->repoBackupPath(),
|
2020-03-09 23:41:59 +02:00
|
|
|
{strCipherPassSub => $self->{oHostBackup}->repoEncrypt() ? ENCRYPTION_KEY_MANIFEST : undef});
|
2017-04-03 16:42:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get the database info for the stanza
|
2020-03-06 14:21:17 +02:00
|
|
|
(my $strVersion, $$oStanza{iControlVersion}, $$oStanza{iCatalogVersion}, $$oStanza{ullDbSysId}) = $self->info();
|
2015-09-02 01:05:10 +02:00
|
|
|
$$oStanza{strDbVersion} = $strDbVersion;
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
if ($bStanzaUpgrade)
|
|
|
|
{
|
2019-08-21 22:26:28 +02:00
|
|
|
$iArchiveDbId = $oArchiveInfo->dbHistoryIdGet() + 1;
|
|
|
|
$iBackupDbId = $oBackupInfo->dbHistoryIdGet() + 1;
|
2017-04-03 16:42:55 +02:00
|
|
|
}
|
|
|
|
|
2019-08-21 22:26:28 +02:00
|
|
|
$oArchiveInfo->dbSectionSet($$oStanza{strDbVersion}, $$oStanza{ullDbSysId}, $iArchiveDbId);
|
|
|
|
$oArchiveInfo->save();
|
|
|
|
|
|
|
|
$oBackupInfo->dbSectionSet($$oStanza{strDbVersion}, $$oStanza{iControlVersion}, $$oStanza{iCatalogVersion},
|
|
|
|
$$oStanza{ullDbSysId}, $iBackupDbId);
|
|
|
|
$oBackupInfo->save();
|
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Get the archive and directory paths for the stanza
|
2020-03-09 23:41:59 +02:00
|
|
|
$$oStanza{strArchiveClusterPath} = $self->{oHostBackup}->repoArchivePath($oArchiveInfo->archiveId());
|
|
|
|
$$oStanza{strBackupClusterPath} = $self->{oHostBackup}->repoBackupPath();
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
$self->{oStanzaHash}{$strStanza} = $oStanza;
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# stanzaCreate
|
|
|
|
####################################################################################################################################
|
|
|
|
sub stanzaCreate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
$strDbVersion,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->stanzaCreate', \@_,
|
|
|
|
{name => 'strStanza'},
|
|
|
|
{name => 'strDbVersion'},
|
|
|
|
);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
my $strDbVersionTemp = $strDbVersion;
|
|
|
|
$strDbVersionTemp =~ s/\.//;
|
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Create the test path for pg_control
|
2020-03-09 23:41:59 +02:00
|
|
|
storageTest()->pathCreate(($self->{strPgPath} . '/' . DB_PATH_GLOBAL), {bIgnoreExists => true});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Generate pg_control for stanza-create
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->controlGenerate($self->{strPgPath}, $strDbVersion);
|
|
|
|
executeTest('chmod 600 ' . $self->{strPgPath} . '/' . DB_FILE_PGCONTROL);
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Create the stanza and set the local stanza object
|
|
|
|
$self->stanzaSet($strStanza, $strDbVersion, false);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# stanzaUpgrade
|
|
|
|
####################################################################################################################################
|
|
|
|
sub stanzaUpgrade
|
|
|
|
{
|
|
|
|
my $self = shift;
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
$strDbVersion,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->stanzaUpgrade', \@_,
|
|
|
|
{name => 'strStanza'},
|
|
|
|
{name => 'strDbVersion'},
|
|
|
|
);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
my $strDbVersionTemp = $strDbVersion;
|
|
|
|
$strDbVersionTemp =~ s/\.//;
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Remove pg_control
|
2020-03-09 23:41:59 +02:00
|
|
|
storageTest()->remove($self->{strPgPath} . '/' . DB_FILE_PGCONTROL);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Copy pg_control for stanza-upgrade
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->controlGenerate($self->{strPgPath}, $strDbVersion);
|
|
|
|
executeTest('chmod 600 ' . $self->{strPgPath} . '/' . DB_FILE_PGCONTROL);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->stanzaSet($strStanza, $strDbVersion, true);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
2016-08-11 23:32:28 +02:00
|
|
|
return logDebugReturn($strOperation);
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
####################################################################################################################################
|
|
|
|
# backupCreate
|
|
|
|
####################################################################################################################################
|
|
|
|
sub backupCreate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
$strType,
|
|
|
|
$lTimestamp,
|
|
|
|
$iArchiveBackupTotal,
|
|
|
|
$iArchiveBetweenTotal
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->backupCreate', \@_,
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strStanza'},
|
|
|
|
{name => 'strType'},
|
|
|
|
{name => 'lTimestamp'},
|
|
|
|
{name => 'iArchiveBackupTotal', default => 3},
|
|
|
|
{name => 'iArchiveBetweenTotal', default => 3}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $oStanza = $self->{oStanzaHash}{$strStanza};
|
|
|
|
|
2017-02-05 17:31:29 +02:00
|
|
|
my ($strArchiveStart, $strArchiveStop);
|
|
|
|
|
|
|
|
if ($iArchiveBackupTotal != -1)
|
|
|
|
{
|
|
|
|
($strArchiveStart, $strArchiveStop) = $self->archiveCreate($strStanza, $iArchiveBackupTotal);
|
|
|
|
}
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
# Create the manifest
|
2017-08-25 22:47:47 +02:00
|
|
|
my $oLastManifest = $strType ne CFGOPTVAL_BACKUP_TYPE_FULL ? $$oStanza{oManifest} : undef;
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
my $strBackupLabel =
|
|
|
|
backupLabelFormat($strType,
|
|
|
|
defined($oLastManifest) ? $oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL) : undef,
|
|
|
|
$lTimestamp);
|
|
|
|
|
2017-04-10 23:23:39 +02:00
|
|
|
my $strBackupClusterSetPath = "$$oStanza{strBackupClusterPath}/${strBackupLabel}";
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
&log(INFO, "create backup ${strBackupLabel}");
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Get passphrase (returns undefined if repo not encrypted) to access the manifest
|
|
|
|
my $strCipherPassManifest =
|
2020-03-10 21:12:44 +02:00
|
|
|
(new pgBackRestTest::Env::BackupInfo($self->{oHostBackup}->repoBackupPath()))->cipherPassSub();
|
2017-11-06 19:51:12 +02:00
|
|
|
my $strCipherPassBackupSet;
|
|
|
|
|
|
|
|
# If repo is encrypted then get passphrase for accessing the backup files from the last manifest if it exists provide one
|
|
|
|
if (defined($strCipherPassManifest))
|
|
|
|
{
|
|
|
|
$strCipherPassBackupSet = (defined($oLastManifest)) ? $oLastManifest->cipherPassSub() :
|
|
|
|
ENCRYPTION_KEY_BACKUPSET;
|
|
|
|
}
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strManifestFile = "$$oStanza{strBackupClusterPath}/${strBackupLabel}/" . FILE_MANIFEST;
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2020-03-10 21:12:44 +02:00
|
|
|
my $oManifest = new pgBackRestTest::Env::Manifest($strManifestFile, {bLoad => false, strDbVersion => PG_VERSION_93,
|
2018-07-16 23:25:15 +02:00
|
|
|
iDbCatalogVersion => $self->dbCatalogVersion(PG_VERSION_93),
|
2017-11-06 19:51:12 +02:00
|
|
|
strCipherPass => $strCipherPassManifest, strCipherPassSub => $strCipherPassBackupSet});
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
# Store information about the backup into the backup section
|
|
|
|
$oManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL, undef, $strBackupLabel);
|
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_ARCHIVE_CHECK, undef, true);
|
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_ARCHIVE_COPY, undef, false);
|
2016-08-25 17:25:46 +02:00
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_BACKUP_STANDBY, undef, false);
|
2015-09-02 01:05:10 +02:00
|
|
|
$oManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_ARCHIVE_START, undef, $strArchiveStart);
|
|
|
|
$oManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_ARCHIVE_STOP, undef, $strArchiveStop);
|
2022-02-14 21:24:14 +02:00
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, 'backup-bundle', undef, true);
|
2016-12-13 01:54:07 +02:00
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_CHECKSUM_PAGE, undef, true);
|
2015-09-02 01:05:10 +02:00
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_COMPRESS, undef, true);
|
2018-11-25 02:05:03 +02:00
|
|
|
$oManifest->numericSet(INI_SECTION_BACKREST, INI_KEY_FORMAT, undef, REPOSITORY_FORMAT);
|
2015-09-02 01:05:10 +02:00
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_HARDLINK, undef, false);
|
2016-02-20 02:32:02 +02:00
|
|
|
$oManifest->boolSet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_ONLINE, undef, true);
|
2015-09-02 01:05:10 +02:00
|
|
|
$oManifest->numericSet(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_START, undef, $lTimestamp);
|
|
|
|
$oManifest->numericSet(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_STOP, undef, $lTimestamp);
|
|
|
|
$oManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE, undef, $strType);
|
2018-11-25 02:05:03 +02:00
|
|
|
$oManifest->set(INI_SECTION_BACKREST, INI_KEY_VERSION, undef, PROJECT_VERSION);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
if ($strType ne CFGOPTVAL_BACKUP_TYPE_FULL)
|
2015-09-02 01:05:10 +02:00
|
|
|
{
|
|
|
|
if (!defined($oLastManifest))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "oLastManifest must be defined when strType = ${strType}");
|
|
|
|
}
|
|
|
|
|
2020-03-25 21:47:03 +02:00
|
|
|
# Set backup-prior
|
|
|
|
if ($strType eq CFGOPTVAL_BACKUP_TYPE_INCR)
|
|
|
|
{
|
|
|
|
# If this is an incremental backup, then it is always based on the prior backup so use the label from the last backup
|
|
|
|
$oManifest->set(
|
|
|
|
MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# If it is a differential then backup-prior must be set to the newest full backup so get the full backup label from
|
|
|
|
# the prior label
|
|
|
|
$oManifest->set(
|
|
|
|
MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef,
|
|
|
|
substr($oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL), 0, 16));
|
|
|
|
}
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oManifest->save();
|
|
|
|
$$oStanza{oManifest} = $oManifest;
|
|
|
|
|
|
|
|
# Add the backup to info
|
2020-03-10 21:12:44 +02:00
|
|
|
my $oBackupInfo = new pgBackRestTest::Env::BackupInfo($$oStanza{strBackupClusterPath}, false);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
$oBackupInfo->check($$oStanza{strDbVersion}, $$oStanza{iControlVersion}, $$oStanza{iCatalogVersion}, $$oStanza{ullDbSysId});
|
2016-04-15 04:50:02 +02:00
|
|
|
$oBackupInfo->add($oManifest);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
# Create the backup description string
|
|
|
|
if (defined($$oStanza{strBackupDescription}))
|
|
|
|
{
|
|
|
|
$$oStanza{strBackupDescription} .= "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$$oStanza{strBackupDescription} .=
|
|
|
|
"* ${strType} backup: label = ${strBackupLabel}" .
|
|
|
|
(defined($oLastManifest) ? ', prior = ' . $oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL) : '') .
|
2017-02-05 17:31:29 +02:00
|
|
|
(defined($strArchiveStart) ? ", start = ${strArchiveStart}, stop = ${strArchiveStop}" : ', not online');
|
2015-09-02 01:05:10 +02:00
|
|
|
|
2017-02-05 17:31:29 +02:00
|
|
|
if ($iArchiveBetweenTotal != -1)
|
|
|
|
{
|
|
|
|
$self->archiveCreate($strStanza, $iArchiveBetweenTotal);
|
|
|
|
}
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
2016-08-11 23:32:28 +02:00
|
|
|
return logDebugReturn($strOperation);
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# archiveNext
|
|
|
|
####################################################################################################################################
|
|
|
|
sub archiveNext
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strArchive,
|
|
|
|
$bSkipFF
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->archiveNext', \@_,
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strArchive', trace => true},
|
|
|
|
{name => 'bSkipFF', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Break archive log into components
|
|
|
|
my $lTimeline = hex(substr($strArchive, 0, 8));
|
|
|
|
my $lMajor = hex(substr($strArchive, 8, 8));
|
|
|
|
my $lMinor = hex(substr($strArchive, 16, 8));
|
|
|
|
|
|
|
|
# Increment the minor component (and major when needed)
|
|
|
|
$lMinor += 1;
|
|
|
|
|
|
|
|
if ($bSkipFF && $lMinor == 255 || !$bSkipFF && $lMinor == 256)
|
|
|
|
{
|
|
|
|
$lMajor += 1;
|
|
|
|
$lMinor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'strArchiveNext', value => uc(sprintf("%08x%08x%08x", $lTimeline, $lMajor, $lMinor)), trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# archiveCreate
|
|
|
|
####################################################################################################################################
|
|
|
|
sub archiveCreate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
$iArchiveTotal
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->archiveCreate', \@_,
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strStanza'},
|
|
|
|
{name => 'iArchiveTotal'}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $oStanza = $self->{oStanzaHash}{$strStanza};
|
|
|
|
my $iArchiveIdx = 0;
|
|
|
|
|
2022-12-20 07:20:47 +02:00
|
|
|
my $strArchive = defined($$oStanza{strArchiveLast}) ? $self->archiveNext($$oStanza{strArchiveLast}, false) :
|
2015-09-02 01:05:10 +02:00
|
|
|
'000000010000000000000000';
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Get passphrase (returns undefined if repo not encrypted) to access the archive files
|
|
|
|
my $strCipherPass =
|
2020-03-10 21:12:44 +02:00
|
|
|
(new pgBackRestTest::Env::ArchiveInfo($self->{oHostBackup}->repoArchivePath()))->cipherPassSub();
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2015-09-02 01:05:10 +02:00
|
|
|
push(my @stryArchive, $strArchive);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
my $strPath = "$$oStanza{strArchiveClusterPath}/" . substr($strArchive, 0, 16);
|
|
|
|
my $strFile = "${strPath}/${strArchive}-0000000000000000000000000000000000000000" . ($iArchiveIdx % 2 == 0 ? '.gz' : '');
|
2017-11-06 19:51:12 +02:00
|
|
|
|
|
|
|
storageRepo()->put($strFile, 'ARCHIVE', {strCipherPass => $strCipherPass});
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
$iArchiveIdx++;
|
|
|
|
|
|
|
|
if ($iArchiveIdx < $iArchiveTotal)
|
|
|
|
{
|
2022-12-20 07:20:47 +02:00
|
|
|
$strArchive = $self->archiveNext($strArchive, false);
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while ($iArchiveIdx < $iArchiveTotal);
|
|
|
|
|
|
|
|
push(@stryArchive, $strArchive);
|
|
|
|
$$oStanza{strArchiveLast} = $strArchive;
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'stryArchive', value => \@stryArchive}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# process
|
|
|
|
####################################################################################################################################
|
|
|
|
sub process
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
$iExpireFull,
|
|
|
|
$iExpireDiff,
|
|
|
|
$strExpireArchiveType,
|
|
|
|
$iExpireArchive,
|
|
|
|
$strDescription
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->process', \@_,
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strStanza'},
|
2016-09-07 14:07:37 +02:00
|
|
|
{name => 'iExpireFull', required => false},
|
|
|
|
{name => 'iExpireDiff', required => false},
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strExpireArchiveType'},
|
2016-09-07 14:07:37 +02:00
|
|
|
{name => 'iExpireArchive', required => false},
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strDescription'}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $oStanza = $self->{oStanzaHash}{$strStanza};
|
|
|
|
|
|
|
|
undef($$oStanza{strBackupDescription});
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
my $strCommand =
|
|
|
|
$self->{strBackRestExe} . ' --config="' . $self->{oHostBackup}->backrestConfig() . '"' . ' --stanza=' . $strStanza .
|
|
|
|
' --log-level-console=' . lc(DETAIL);
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
if (defined($iExpireFull))
|
|
|
|
{
|
2018-02-19 22:07:24 +02:00
|
|
|
$strCommand .= ' --repo1-retention-full=' . $iExpireFull;
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($iExpireDiff))
|
|
|
|
{
|
2018-02-19 22:07:24 +02:00
|
|
|
$strCommand .= ' --repo1-retention-diff=' . $iExpireDiff;
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($strExpireArchiveType))
|
|
|
|
{
|
2016-09-07 14:07:37 +02:00
|
|
|
if (defined($iExpireArchive))
|
|
|
|
{
|
2018-02-19 22:07:24 +02:00
|
|
|
$strCommand .= ' --repo1-retention-archive-type=' . $strExpireArchiveType .
|
|
|
|
' --repo1-retention-archive=' . $iExpireArchive;
|
2016-09-07 14:07:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-19 22:07:24 +02:00
|
|
|
$strCommand .= ' --repo1-retention-archive-type=' . $strExpireArchiveType;
|
2016-09-07 14:07:37 +02:00
|
|
|
}
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$strCommand .= ' expire';
|
|
|
|
|
2022-05-10 19:18:26 +02:00
|
|
|
$self->{oHostBackup}->executeSimple($strCommand, {strComment => $strDescription});
|
2015-09-02 01:05:10 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
2016-01-19 14:39:29 +02:00
|
|
|
return logDebugReturn($strOperation);
|
2015-09-02 01:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|