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