2017-06-09 17:51:41 -04:00
|
|
|
####################################################################################################################################
|
|
|
|
# Db & Repository Storage Helper
|
|
|
|
####################################################################################################################################
|
|
|
|
package pgBackRest::Protocol::Storage::Helper;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
use File::Basename qw(basename);
|
|
|
|
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Config::Config;
|
2019-06-26 08:24:58 -04:00
|
|
|
use pgBackRest::LibC qw(:storage);
|
2017-06-09 17:51:41 -04:00
|
|
|
use pgBackRest::Protocol::Helper;
|
|
|
|
use pgBackRest::Protocol::Storage::Remote;
|
|
|
|
use pgBackRest::Storage::Helper;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Storage constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant STORAGE_DB => '<DB>';
|
|
|
|
push @EXPORT, qw(STORAGE_DB);
|
|
|
|
|
|
|
|
use constant STORAGE_REPO => '<REPO>';
|
|
|
|
push @EXPORT, qw(STORAGE_REPO);
|
|
|
|
use constant STORAGE_REPO_ARCHIVE => '<REPO:ARCHIVE>';
|
|
|
|
push @EXPORT, qw(STORAGE_REPO_ARCHIVE);
|
|
|
|
use constant STORAGE_REPO_BACKUP => '<REPO:BACKUP>';
|
|
|
|
push @EXPORT, qw(STORAGE_REPO_BACKUP);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Cache storage so it can be retrieved quickly
|
|
|
|
####################################################################################################################################
|
|
|
|
my $hStorage;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# storageDb - get db storage
|
|
|
|
####################################################################################################################################
|
|
|
|
sub storageDb
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$iRemoteIdx,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '::storageDb', \@_,
|
2017-08-25 16:47:47 -04:00
|
|
|
{name => 'iRemoteIdx', optional => true, default => cfgOptionValid(CFGOPT_HOST_ID) ? cfgOption(CFGOPT_HOST_ID) : 1,
|
2017-06-09 17:51:41 -04:00
|
|
|
trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
# Create storage if not defined
|
|
|
|
if (!defined($hStorage->{&STORAGE_DB}{$iRemoteIdx}))
|
|
|
|
{
|
|
|
|
if (isDbLocal({iRemoteIdx => $iRemoteIdx}))
|
|
|
|
{
|
2019-06-26 08:24:58 -04:00
|
|
|
$hStorage->{&STORAGE_DB}{$iRemoteIdx} = new pgBackRest::Storage::Storage(
|
|
|
|
STORAGE_DB, {lBufferMax => cfgOption(CFGOPT_BUFFER_SIZE)});
|
2017-06-09 17:51:41 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-25 16:47:47 -04:00
|
|
|
$hStorage->{&STORAGE_DB}{$iRemoteIdx} = new pgBackRest::Protocol::Storage::Remote(
|
|
|
|
protocolGet(CFGOPTVAL_REMOTE_TYPE_DB, $iRemoteIdx));
|
2017-06-09 17:51:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'oStorageDb', value => $hStorage->{&STORAGE_DB}{$iRemoteIdx}, trace => true},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(storageDb);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# storageRepo - get repository storage
|
|
|
|
####################################################################################################################################
|
|
|
|
sub storageRepo
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '::storageRepo', \@_,
|
|
|
|
{name => 'strStanza', optional => true, trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
# Create storage if not defined
|
2019-06-26 08:24:58 -04:00
|
|
|
if (!defined($hStorage->{&STORAGE_REPO}))
|
2017-06-09 17:51:41 -04:00
|
|
|
{
|
|
|
|
if (isRepoLocal())
|
|
|
|
{
|
2019-06-26 08:24:58 -04:00
|
|
|
$hStorage->{&STORAGE_REPO} = new pgBackRest::Storage::Storage(
|
|
|
|
STORAGE_REPO, {lBufferMax => cfgOption(CFGOPT_BUFFER_SIZE)});
|
2017-06-09 17:51:41 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Create remote storage
|
2019-06-26 08:24:58 -04:00
|
|
|
$hStorage->{&STORAGE_REPO} = new pgBackRest::Protocol::Storage::Remote(
|
2017-08-25 16:47:47 -04:00
|
|
|
protocolGet(CFGOPTVAL_REMOTE_TYPE_BACKUP));
|
2017-06-09 17:51:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2019-06-26 08:24:58 -04:00
|
|
|
{name => 'oStorageRepo', value => $hStorage->{&STORAGE_REPO}, trace => true},
|
2017-06-09 17:51:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(storageRepo);
|
|
|
|
|
2017-11-06 12:51:12 -05:00
|
|
|
####################################################################################################################################
|
2019-06-04 10:34:19 -04:00
|
|
|
# Clear the repo storage cache - FOR TESTING ONLY!
|
2017-11-06 12:51:12 -05:00
|
|
|
####################################################################################################################################
|
|
|
|
sub storageRepoCacheClear
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
2019-06-04 10:34:19 -04:00
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '::storageRepoCacheClear');
|
2017-11-06 12:51:12 -05:00
|
|
|
|
2019-06-04 10:34:19 -04:00
|
|
|
delete($hStorage->{&STORAGE_REPO});
|
2017-11-06 12:51:12 -05:00
|
|
|
|
2019-06-26 08:24:58 -04:00
|
|
|
storageRepoFree();
|
|
|
|
|
2019-06-04 10:34:19 -04:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
2017-11-06 12:51:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(storageRepoCacheClear);
|
|
|
|
|
2017-06-09 17:51:41 -04:00
|
|
|
1;
|