2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BACKUP COMMON MODULE
|
|
|
|
####################################################################################################################################
|
2016-04-14 15:30:54 +02:00
|
|
|
package pgBackRest::BackupCommon;
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
2015-08-29 20:20:46 +02:00
|
|
|
our @EXPORT = qw();
|
2015-06-14 00:25:49 +02:00
|
|
|
use File::Basename;
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Config::Config;
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# backupRegExpGet - Generate a regexp depending on the backups that need to be found
|
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
sub backupRegExpGet
|
|
|
|
{
|
2015-08-29 20:20:46 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$bFull,
|
|
|
|
$bDifferential,
|
2016-04-15 04:50:02 +02:00
|
|
|
$bIncremental,
|
|
|
|
$bAnchor
|
2015-08-29 20:20:46 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '::backupRegExpGet', \@_,
|
2015-08-29 20:20:46 +02:00
|
|
|
{name => 'bFull', default => false},
|
|
|
|
{name => 'bDifferential', default => false},
|
2016-04-15 04:50:02 +02:00
|
|
|
{name => 'bIncremental', default => false},
|
|
|
|
{name => 'bAnchor', default => true}
|
2015-08-29 20:20:46 +02:00
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
if (!$bFull && !$bDifferential && !$bIncremental)
|
|
|
|
{
|
2015-08-29 20:20:46 +02:00
|
|
|
confess &log(ASSERT, 'one parameter must be true');
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $strDateTimeRegExp = "[0-9]{8}\\-[0-9]{6}";
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strRegExp = $bAnchor ? '^' : '';
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
if ($bFull || $bDifferential || $bIncremental)
|
|
|
|
{
|
|
|
|
$strRegExp .= $strDateTimeRegExp . 'F';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bDifferential || $bIncremental)
|
|
|
|
{
|
|
|
|
if ($bFull)
|
|
|
|
{
|
|
|
|
$strRegExp .= "(\\_";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strRegExp .= "\\_";
|
|
|
|
}
|
|
|
|
|
|
|
|
$strRegExp .= $strDateTimeRegExp;
|
|
|
|
|
|
|
|
if ($bDifferential && $bIncremental)
|
|
|
|
{
|
|
|
|
$strRegExp .= '(D|I)';
|
|
|
|
}
|
|
|
|
elsif ($bDifferential)
|
|
|
|
{
|
|
|
|
$strRegExp .= 'D';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strRegExp .= 'I';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bFull)
|
|
|
|
{
|
|
|
|
$strRegExp .= '){0,1}';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
$strRegExp .= $bAnchor ? "\$" : '';
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'strRegExp', value => $strRegExp}
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(backupRegExpGet);
|
|
|
|
|
2015-09-02 01:05:10 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# backupLabelFormat
|
|
|
|
####################################################################################################################################
|
|
|
|
sub backupLabelFormat
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strType,
|
|
|
|
$strBackupLabelLast,
|
|
|
|
$lTimestampStop
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '::backupLabelFormat', \@_,
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strType', trace => true},
|
|
|
|
{name => 'strBackupLabelLast', required => false, trace => true},
|
|
|
|
{name => 'lTimestampStop', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $strBackupLabel;
|
|
|
|
|
|
|
|
if ($strType eq BACKUP_TYPE_FULL)
|
|
|
|
{
|
|
|
|
if (defined($strBackupLabelLast))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "strBackupPathLast cannot be defined when type = ${strType}");
|
|
|
|
}
|
|
|
|
|
|
|
|
$strBackupLabel = timestampFileFormat(undef, $lTimestampStop) . 'F';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!defined($strBackupLabelLast))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "strBackupLabelLast must be defined when type = ${strType}");
|
|
|
|
}
|
|
|
|
|
|
|
|
$strBackupLabel = substr($strBackupLabelLast, 0, 16);
|
|
|
|
|
|
|
|
$strBackupLabel .= '_' . timestampFileFormat(undef, $lTimestampStop);
|
|
|
|
|
|
|
|
if ($strType eq BACKUP_TYPE_DIFF)
|
|
|
|
{
|
|
|
|
$strBackupLabel .= 'D';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strBackupLabel .= 'I';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'strBackupLabel', value => $strBackupLabel, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(backupLabelFormat);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
1;
|