mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-20 04:59:25 +02:00
1bc84c6474
This is just the part of restore run by the local helper processes, not the entire command. Even so, various optimizations in the code (like pipelining and optimizations for zero-length files) should make the restore command faster on object stores.
101 lines
3.0 KiB
Perl
101 lines
3.0 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::Base;
|
|
use pgBackRest::Storage::Filter::Gzip;
|
|
use pgBackRest::Storage::Filter::Sha;
|
|
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;
|