mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
4815752ccc
Maintaining the storage layer/drivers in two languages is burdensome. Since the integration tests require the Perl storage layer/drivers we'll need them even after the core code is migrated to C. Create an interface layer so the Perl code can be removed and new storage drivers/features introduced without adding Perl equivalents. The goal is to move the integration tests to C so this interface will eventually be removed. That being the case, the interface was designed for maximum compatibility to ease the transition. The result looks a bit hacky but we'll improve it as needed until it can be retired.
98 lines
2.9 KiB
Perl
98 lines
2.9 KiB
Perl
####################################################################################################################################
|
|
# RESTORE FILE MODULE
|
|
####################################################################################################################################
|
|
package pgBackRest::RestoreFile;
|
|
|
|
use strict;
|
|
use warnings FATAL => qw(all);
|
|
use Carp qw(confess);
|
|
|
|
use Exporter qw(import);
|
|
our @EXPORT = qw();
|
|
use Fcntl qw(:mode);
|
|
use File::Basename qw(dirname);
|
|
use File::stat qw(lstat);
|
|
|
|
use pgBackRest::Common::Exception;
|
|
use pgBackRest::Common::Io::Handle;
|
|
use pgBackRest::Common::Log;
|
|
use pgBackRest::Common::String;
|
|
use pgBackRest::Config::Config;
|
|
use pgBackRest::Manifest;
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
use pgBackRest::Storage::Helper;
|
|
|
|
####################################################################################################################################
|
|
# restoreLog
|
|
#
|
|
# Log a restored file.
|
|
####################################################################################################################################
|
|
sub restoreLog
|
|
{
|
|
# Assign function parameters, defaults, and log debug info
|
|
my
|
|
(
|
|
$strOperation,
|
|
$iLocalId,
|
|
$strDbFile,
|
|
$lSize,
|
|
$lModificationTime,
|
|
$strChecksum,
|
|
$bZero,
|
|
$bForce,
|
|
$bCopy,
|
|
$lSizeTotal,
|
|
$lSizeCurrent,
|
|
) =
|
|
logDebugParam
|
|
(
|
|
__PACKAGE__ . '::restoreLog', \@_,
|
|
{name => 'iLocalId', required => false},
|
|
{name => 'strDbFile'},
|
|
{name => 'lSize'},
|
|
{name => 'lModificationTime'},
|
|
{name => 'strChecksum', required => false},
|
|
{name => 'bZero', required => false, default => false},
|
|
{name => 'bForce'},
|
|
{name => 'bCopy'},
|
|
{name => 'lSizeTotal'},
|
|
{name => 'lSizeCurrent'},
|
|
);
|
|
|
|
# If the file was not copied then create a log entry to explain why
|
|
my $strLog;
|
|
|
|
if (!$bCopy && !$bZero)
|
|
{
|
|
if ($bForce)
|
|
{
|
|
$strLog = 'exists and matches size ' . $lSize . ' and modification time ' . $lModificationTime;
|
|
}
|
|
else
|
|
{
|
|
$strLog = 'exists and ' . ($lSize == 0 ? 'is zero size' : 'matches backup');
|
|
}
|
|
}
|
|
|
|
# Log the restore
|
|
$lSizeCurrent += $lSize;
|
|
|
|
&log($bCopy ? INFO : DETAIL,
|
|
'restore' . ($bZero ? ' zeroed' : '') .
|
|
" file ${strDbFile}" . (defined($strLog) ? " - ${strLog}" : '') .
|
|
' (' . fileSizeFormat($lSize) .
|
|
($lSizeTotal > 0 ? ', ' . int($lSizeCurrent * 100 / $lSizeTotal) . '%' : '') . ')' .
|
|
($lSize != 0 && !$bZero ? " checksum ${strChecksum}" : ''), undef, undef, undef, $iLocalId);
|
|
|
|
# Return from function and log return values if any
|
|
return logDebugReturn
|
|
(
|
|
$strOperation,
|
|
{name => 'lSizeCurrent', value => $lSizeCurrent, trace => true}
|
|
);
|
|
}
|
|
|
|
push @EXPORT, qw(restoreLog);
|
|
|
|
1;
|