2017-01-10 19:59:32 -05:00
|
|
|
####################################################################################################################################
|
|
|
|
# ARCHIVE GET MODULE
|
|
|
|
####################################################################################################################################
|
2017-06-21 08:02:21 -04:00
|
|
|
package pgBackRest::Archive::Get::Get;
|
|
|
|
use parent 'pgBackRest::Archive::Base';
|
2017-01-10 19:59:32 -05:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
use English '-no_match_vars';
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
use Fcntl qw(SEEK_CUR O_RDONLY O_WRONLY O_CREAT);
|
|
|
|
use File::Basename qw(dirname basename);
|
|
|
|
use Scalar::Util qw(blessed);
|
|
|
|
|
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Lock;
|
|
|
|
use pgBackRest::Common::Log;
|
2017-06-21 08:02:21 -04:00
|
|
|
use pgBackRest::Archive::Common;
|
2018-04-29 10:16:59 -04:00
|
|
|
use pgBackRest::Archive::Get::File;
|
2017-06-21 08:02:21 -04:00
|
|
|
use pgBackRest::Archive::Info;
|
2017-01-10 19:59:32 -05:00
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Common::Wait;
|
|
|
|
use pgBackRest::Config::Config;
|
|
|
|
use pgBackRest::Db;
|
|
|
|
use pgBackRest::DbVersion;
|
2017-05-15 11:12:14 -04:00
|
|
|
use pgBackRest::Protocol::Helper;
|
2017-06-09 17:51:41 -04:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
|
|
use pgBackRest::Storage::Base;
|
|
|
|
use pgBackRest::Storage::Filter::Gzip;
|
|
|
|
use pgBackRest::Storage::Helper;
|
2017-01-10 19:59:32 -05:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# process
|
|
|
|
####################################################################################################################################
|
|
|
|
sub process
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
2018-01-28 21:37:09 -05:00
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2018-04-30 17:27:39 -04:00
|
|
|
$rstryCommandArg,
|
2018-01-28 21:37:09 -05:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->process', \@_,
|
2018-04-30 17:27:39 -04:00
|
|
|
{name => 'rstryCommandArg'},
|
2018-01-28 21:37:09 -05:00
|
|
|
);
|
2017-01-10 19:59:32 -05:00
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
my $iResult = 0;
|
|
|
|
|
2017-06-27 17:54:30 -04:00
|
|
|
# Make sure the command happens on the db side
|
|
|
|
if (!isDbLocal())
|
|
|
|
{
|
2017-08-25 16:47:47 -04:00
|
|
|
confess &log(ERROR, cfgCommandName(CFGCMD_ARCHIVE_GET) . ' operation must run on db host', ERROR_HOST_INVALID);
|
2017-06-27 17:54:30 -04:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
# Start the async process and wait for WAL to complete
|
|
|
|
if (cfgOption(CFGOPT_ARCHIVE_ASYNC))
|
2017-01-10 19:59:32 -05:00
|
|
|
{
|
2018-04-30 17:27:39 -04:00
|
|
|
# Load module dynamically
|
|
|
|
require pgBackRest::Archive::Get::Async;
|
|
|
|
(new pgBackRest::Archive::Get::Async(
|
|
|
|
storageSpool()->pathGet(STORAGE_SPOOL_ARCHIVE_IN), $self->{strBackRestBin}, $rstryCommandArg))->process();
|
2017-01-10 19:59:32 -05:00
|
|
|
}
|
2018-04-30 17:27:39 -04:00
|
|
|
# Else push synchronously
|
|
|
|
else
|
2017-01-10 19:59:32 -05:00
|
|
|
{
|
2018-04-30 17:27:39 -04:00
|
|
|
# Make sure the archive file is defined
|
|
|
|
my $strSourceArchive = ${$rstryCommandArg}[0];
|
|
|
|
|
|
|
|
if (!defined($strSourceArchive))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'WAL segment not provided', ERROR_PARAM_REQUIRED);
|
|
|
|
}
|
2017-01-10 19:59:32 -05:00
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
# Make sure the destination file is defined
|
|
|
|
my $strDestinationFile = ${$rstryCommandArg}[1];
|
|
|
|
|
|
|
|
if (!defined($strDestinationFile))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'WAL segment destination not provided', ERROR_PARAM_REQUIRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
$iResult = archiveGetFile($strSourceArchive, $strDestinationFile, false);
|
|
|
|
|
|
|
|
# Info for the Postgres log
|
|
|
|
&log(INFO, 'got WAL segment ' . $strSourceArchive);
|
|
|
|
}
|
2017-01-10 19:59:32 -05:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2018-04-30 17:27:39 -04:00
|
|
|
{name => 'iResult', value => $iResult, trace => true},
|
2017-01-10 19:59:32 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|