2015-04-07 13:34:37 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# RESTORE FILE MODULE
|
|
|
|
####################################################################################################################################
|
2016-04-14 15:30:54 +02:00
|
|
|
package pgBackRest::RestoreFile;
|
2015-04-07 13:34:37 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
use Exporter qw(import);
|
2015-08-29 20:20:46 +02:00
|
|
|
our @EXPORT = qw();
|
2018-05-02 18:06:12 +02:00
|
|
|
use Fcntl qw(:mode);
|
2015-04-07 13:34:37 +02:00
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use File::stat qw(lstat);
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Exception;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Common::Io::Handle;
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Config::Config;
|
|
|
|
use pgBackRest::Manifest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
|
|
use pgBackRest::Storage::Helper;
|
2015-08-29 20:20:46 +02:00
|
|
|
|
2016-09-06 15:35:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# restoreLog
|
|
|
|
#
|
|
|
|
# Log a restored file.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub restoreLog
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2016-12-04 00:34:51 +02:00
|
|
|
$iLocalId,
|
2016-09-06 15:35:02 +02:00
|
|
|
$strDbFile,
|
|
|
|
$lSize,
|
|
|
|
$lModificationTime,
|
|
|
|
$strChecksum,
|
|
|
|
$bZero,
|
|
|
|
$bForce,
|
2016-12-04 00:34:51 +02:00
|
|
|
$bCopy,
|
2016-09-06 15:35:02 +02:00
|
|
|
$lSizeTotal,
|
|
|
|
$lSizeCurrent,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '::restoreLog', \@_,
|
2016-12-04 00:34:51 +02:00
|
|
|
{name => 'iLocalId', required => false},
|
|
|
|
{name => 'strDbFile'},
|
|
|
|
{name => 'lSize'},
|
|
|
|
{name => 'lModificationTime'},
|
|
|
|
{name => 'strChecksum', required => false},
|
|
|
|
{name => 'bZero', required => false, default => false},
|
|
|
|
{name => 'bForce'},
|
2016-09-06 15:35:02 +02:00
|
|
|
{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
|
2015-05-07 23:56:56 +02:00
|
|
|
{
|
2016-09-06 15:35:02 +02:00
|
|
|
$strLog = 'exists and ' . ($lSize == 0 ? 'is zero size' : 'matches backup');
|
2015-05-07 23:56:56 +02:00
|
|
|
}
|
2015-04-07 13:34:37 +02:00
|
|
|
}
|
2015-05-07 23:56:56 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# Log the restore
|
2016-09-06 15:35:02 +02:00
|
|
|
$lSizeCurrent += $lSize;
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
&log($bCopy ? INFO : DETAIL,
|
2016-05-11 15:21:39 +02:00
|
|
|
'restore' . ($bZero ? ' zeroed' : '') .
|
2016-09-06 15:35:02 +02:00
|
|
|
" file ${strDbFile}" . (defined($strLog) ? " - ${strLog}" : '') .
|
|
|
|
' (' . fileSizeFormat($lSize) .
|
2016-04-15 04:50:02 +02:00
|
|
|
($lSizeTotal > 0 ? ', ' . int($lSizeCurrent * 100 / $lSizeTotal) . '%' : '') . ')' .
|
2016-09-14 23:37:07 +02:00
|
|
|
($lSize != 0 && !$bZero ? " checksum ${strChecksum}" : ''), undef, undef, undef, $iLocalId);
|
2015-05-07 23:56:56 +02:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'lSizeCurrent', value => $lSizeCurrent, trace => true}
|
|
|
|
);
|
2015-04-07 13:34:37 +02:00
|
|
|
}
|
|
|
|
|
2016-09-06 15:35:02 +02:00
|
|
|
push @EXPORT, qw(restoreLog);
|
2015-04-07 13:34:37 +02:00
|
|
|
|
|
|
|
1;
|