2017-06-09 17:51:41 -04:00
|
|
|
####################################################################################################################################
|
2020-03-09 17:41:59 -04:00
|
|
|
# Repository Storage Helper
|
2017-06-09 17:51:41 -04:00
|
|
|
####################################################################################################################################
|
|
|
|
package pgBackRest::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;
|
2019-06-26 08:24:58 -04:00
|
|
|
use pgBackRest::Storage::Storage;
|
2017-06-09 17:51:41 -04:00
|
|
|
use pgBackRest::Version;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Temp file extension
|
|
|
|
####################################################################################################################################
|
2018-11-24 19:05:03 -05:00
|
|
|
use constant STORAGE_TEMP_EXT => PROJECT_EXE . '.tmp';
|
2017-06-09 17:51:41 -04:00
|
|
|
push @EXPORT, qw(STORAGE_TEMP_EXT);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 17:41:59 -04:00
|
|
|
# Cache storage so it can be retrieved quickly
|
|
|
|
####################################################################################################################################
|
|
|
|
my $oRepoStorage;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# storageRepoCommandSet
|
|
|
|
####################################################################################################################################
|
|
|
|
my $strStorageRepoCommand;
|
|
|
|
my $strStorageRepoType;
|
|
|
|
|
|
|
|
sub storageRepoCommandSet
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strCommand,
|
|
|
|
$strStorageType,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '::storageRepoCommandSet', \@_,
|
|
|
|
{name => 'strCommand'},
|
|
|
|
{name => 'strStorageType'},
|
|
|
|
);
|
|
|
|
|
|
|
|
$strStorageRepoCommand = $strCommand;
|
|
|
|
$strStorageRepoType = $strStorageType;
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(storageRepoCommandSet);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# storageRepo - get repository storage
|
2017-06-09 17:51:41 -04:00
|
|
|
####################################################################################################################################
|
2020-03-09 17:41:59 -04:00
|
|
|
sub storageRepo
|
2017-06-09 17:51:41 -04:00
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
2020-03-09 17:41:59 -04:00
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '::storageRepo', \@_,
|
|
|
|
{name => 'strStanza', optional => true, trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
# Create storage if not defined
|
|
|
|
if (!defined($oRepoStorage))
|
|
|
|
{
|
|
|
|
$oRepoStorage = new pgBackRest::Storage::Storage($strStorageRepoCommand, $strStorageRepoType, 64 * 1024, 60);
|
|
|
|
}
|
2017-06-09 17:51:41 -04:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 17:41:59 -04:00
|
|
|
{name => 'oStorageRepo', value => $oRepoStorage, trace => true},
|
2017-06-09 17:51:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-09 17:41:59 -04:00
|
|
|
push @EXPORT, qw(storageRepo);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Clear the repo storage cache - FOR TESTING ONLY!
|
|
|
|
####################################################################################################################################
|
|
|
|
sub storageRepoCacheClear
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '::storageRepoCacheClear');
|
|
|
|
|
|
|
|
undef($oRepoStorage);
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(storageRepoCacheClear);
|
2017-06-09 17:51:41 -04:00
|
|
|
|
|
|
|
1;
|