2015-04-01 21:58:33 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# ARCHIVE MODULE
|
|
|
|
####################################################################################################################################
|
2017-06-21 14:02:21 +02:00
|
|
|
package pgBackRest::Archive::Base;
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
2015-08-29 20:20:46 +02:00
|
|
|
our @EXPORT = qw();
|
2017-01-11 02:59:32 +02:00
|
|
|
use File::Basename qw(dirname);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2017-06-21 14:02:21 +02:00
|
|
|
use pgBackRest::Archive::Info;
|
|
|
|
use pgBackRest::Archive::Common;
|
2017-01-11 02:59:32 +02:00
|
|
|
use pgBackRest::Db;
|
|
|
|
use pgBackRest::DbVersion;
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::Wait;
|
|
|
|
use pgBackRest::Config::Config;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Helper;
|
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
|
|
use pgBackRest::Storage::Helper;
|
2017-01-27 18:02:27 +02:00
|
|
|
use pgBackRest::Version;
|
2016-05-14 16:33:12 +02:00
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# constructor
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
|
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
2017-01-27 18:02:27 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(
|
|
|
|
my $strOperation,
|
|
|
|
$self->{strBackRestBin},
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->new', \@_,
|
|
|
|
{name => 'strBackRestBin', default => BACKREST_BIN, trace => true},
|
|
|
|
);
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self}
|
|
|
|
);
|
2015-04-01 21:58:33 +02:00
|
|
|
}
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# getCheck
|
|
|
|
####################################################################################################################################
|
|
|
|
sub getCheck
|
2016-07-29 20:02:11 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strDbVersion,
|
2017-01-27 18:02:27 +02:00
|
|
|
$ullDbSysId,
|
|
|
|
$strWalFile,
|
2016-07-29 20:02:11 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->getCheck', \@_,
|
2016-07-29 20:02:11 +02:00
|
|
|
{name => 'strDbVersion', required => false},
|
2017-01-27 18:02:27 +02:00
|
|
|
{name => 'ullDbSysId', required => false},
|
|
|
|
{name => 'strWalFile', required => false},
|
2016-07-29 20:02:11 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
my $strArchiveId;
|
2017-01-27 18:02:27 +02:00
|
|
|
my $strArchiveFile;
|
2016-07-29 20:02:11 +02:00
|
|
|
|
|
|
|
# If the dbVersion/dbSysId are not passed, then we need to retrieve the database information
|
|
|
|
if (!defined($strDbVersion) || !defined($ullDbSysId) )
|
|
|
|
{
|
|
|
|
# get DB info for comparison
|
2016-11-30 21:15:11 +02:00
|
|
|
($strDbVersion, my $iControlVersion, my $iCatalogVersion, $ullDbSysId) = dbMasterGet()->info();
|
2016-07-29 20:02:11 +02:00
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Get db info from the repo
|
|
|
|
if (!isRepoLocal())
|
2016-07-29 20:02:11 +02:00
|
|
|
{
|
2017-08-25 22:47:47 +02:00
|
|
|
($strArchiveId, $strArchiveFile) = protocolGet(CFGOPTVAL_REMOTE_TYPE_BACKUP)->cmdExecute(
|
2017-01-27 18:02:27 +02:00
|
|
|
OP_ARCHIVE_GET_CHECK, [$strDbVersion, $ullDbSysId, $strWalFile], true);
|
2016-07-29 20:02:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-20 23:52:20 +02:00
|
|
|
# check that the archive info is compatible with the database
|
2016-07-29 20:02:11 +02:00
|
|
|
$strArchiveId =
|
2017-06-21 14:02:21 +02:00
|
|
|
(new pgBackRest::Archive::Info(
|
2017-06-09 23:51:41 +02:00
|
|
|
storageRepo()->pathGet(STORAGE_REPO_ARCHIVE), true))->check($strDbVersion, $ullDbSysId);
|
2017-01-27 18:02:27 +02:00
|
|
|
|
|
|
|
if (defined($strWalFile))
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
$strArchiveFile = walSegmentFind(storageRepo(), ${strArchiveId}, $strWalFile);
|
2017-01-27 18:02:27 +02:00
|
|
|
}
|
2016-07-29 20:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2017-01-27 18:02:27 +02:00
|
|
|
{name => 'strArchiveId', value => $strArchiveId},
|
|
|
|
{name => 'strArchiveFile', value => $strArchiveFile}
|
2016-07-29 20:02:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
1;
|