1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Merge from dev-0.30.

Squashed commit of the following:

commit f3a012eb86702297ac06c9ae7c3da6a2eae41136
Author: David Steele <david@pgmasters.net>
Date:   Wed Oct 1 19:05:57 2014 -0400

    Fixed an issue where archive-get was not returning 1 if the archive directory did not exist.  This happens when it is trying to retrieve archive log 00 and that has not been pushed from the master yet.
This commit is contained in:
David Steele 2014-10-02 10:55:38 -04:00
parent 168398e58a
commit 991afe3b16
6 changed files with 90 additions and 59 deletions

View File

@ -105,7 +105,8 @@ while ($strCommand ne OP_EXIT)
foreach my $strFile ($oFile->list(PATH_ABSOLUTE, param_get(\%oParamHash, 'path'),
param_get(\%oParamHash, 'expression', false),
param_get(\%oParamHash, 'sort_order')))
param_get(\%oParamHash, 'sort_order'),
param_get(\%oParamHash, 'ignore_missing')))
{
if (defined($strOutput))
{

View File

@ -249,7 +249,7 @@ sub archive_get
# Get the name of the requested archive file (may have hash info and compression extension)
my @stryArchiveFile = $oFile->list(PATH_BACKUP_ABSOLUTE, $strArchivePath,
"^${strSourceArchive}(-[0-f]+){0,1}(\\.$oFile->{strCompressExtension}){0,1}\$");
"^${strSourceArchive}(-[0-f]+){0,1}(\\.$oFile->{strCompressExtension}){0,1}\$", undef, true);
# If there is more than one matching archive file then there is a serious issue - likely a bug in the archiver
if (scalar @stryArchiveFile > 1)

View File

@ -848,9 +848,11 @@ sub list
my $strPath = shift;
my $strExpression = shift;
my $strSortOrder = shift;
my $bIgnoreMissing = shift;
# Set defaults
$strSortOrder = defined($strSortOrder) ? $strSortOrder : 'forward';
$bIgnoreMissing = defined($bIgnoreMissing) ? $bIgnoreMissing : false;
# Set operation variables
my $strPathOp = $self->path_get($strPathType, $strPath);
@ -871,6 +873,7 @@ sub list
$oParamHash{path} = $strPathOp;
$oParamHash{sort_order} = $strSortOrder;
$oParamHash{ignore_missing} = ${bIgnoreMissing};
if (defined($strExpression))
{
@ -902,6 +905,12 @@ sub list
if (!$self->exists($strPathType, $strPath))
{
# If ignore missing is set then return an empty array
if ($bIgnoreMissing)
{
return @stryFileList;
}
$strError = "${strPathOp} does not exist";
$iErrorCode = COMMAND_ERR_PATH_MISSING;
}

View File

@ -413,10 +413,12 @@ sub BackRestTestBackup_Test
for (my $bCompress = false; $bCompress <= true; $bCompress++)
{
for (my $bChecksum = false; $bChecksum <= true; $bChecksum++)
{
for (my $bExists = false; $bExists <= true; $bExists++)
{
# Increment the run, log, and decide whether this unit test should be run
if (!BackRestTestCommon_Run(++$iRun,
"rmt ${bRemote}, cmp ${bCompress}, chk ${bChecksum}")) {next}
"rmt ${bRemote}, cmp ${bCompress}, chk ${bChecksum}, exists ${bExists}")) {next}
# Create the test directory
if ($bCreate)
@ -451,63 +453,74 @@ sub BackRestTestBackup_Test
my $strCommand = BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() .
'/pg_backrest.conf --stanza=db archive-get';
# Loop through backups
my $strArchiveFile;
# Loop through archive files
for (my $iArchiveNo = 1; $iArchiveNo <= $iArchiveMax; $iArchiveNo++)
if ($bExists)
{
# Construct the archive filename
if ($iArchiveNo > 255)
# Loop through archive files
my $strArchiveFile;
for (my $iArchiveNo = 1; $iArchiveNo <= $iArchiveMax; $iArchiveNo++)
{
confess 'backup total * archive total cannot be greater than 255';
}
$strArchiveFile = uc(sprintf('0000000100000001%08x', $iArchiveNo));
&log(INFO, ' archive ' .sprintf('%02x', $iArchiveNo) .
" - ${strArchiveFile}");
my $strSourceFile = $strArchiveFile;
if ($bChecksum)
{
$strSourceFile .= "-${strArchiveChecksum}";
}
if ($bCompress)
{
$strSourceFile .= '.gz';
}
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile, # Source file
PATH_BACKUP_ARCHIVE, $strSourceFile, # Destination file
false, # Source is not compressed
$bCompress, # Destination compress based on test
undef, undef, undef, # Unused params
true); # Create path if it does not exist
my $strDestinationFile = "${strXlogPath}/${strArchiveFile}";
BackRestTestCommon_Execute($strCommand . " ${strArchiveFile} ${strDestinationFile}");
# Check that the destination file exists
if ($oFile->exists(PATH_DB_ABSOLUTE, $strDestinationFile))
{
if ($oFile->hash(PATH_DB_ABSOLUTE, $strDestinationFile) ne $strArchiveChecksum)
# Construct the archive filename
if ($iArchiveNo > 255)
{
confess "archive file hash does not match ${strArchiveChecksum}";
confess 'backup total * archive total cannot be greater than 255';
}
$strArchiveFile = uc(sprintf('0000000100000001%08x', $iArchiveNo));
&log(INFO, ' archive ' .sprintf('%02x', $iArchiveNo) .
" - ${strArchiveFile}");
my $strSourceFile = $strArchiveFile;
if ($bChecksum)
{
$strSourceFile .= "-${strArchiveChecksum}";
}
if ($bCompress)
{
$strSourceFile .= '.gz';
}
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile, # Source file
PATH_BACKUP_ARCHIVE, $strSourceFile, # Destination file
false, # Source is not compressed
$bCompress, # Destination compress based on test
undef, undef, undef, # Unused params
true); # Create path if it does not exist
my $strDestinationFile = "${strXlogPath}/${strArchiveFile}";
BackRestTestCommon_Execute($strCommand . " ${strArchiveFile} ${strDestinationFile}");
# Check that the destination file exists
if ($oFile->exists(PATH_DB_ABSOLUTE, $strDestinationFile))
{
if ($oFile->hash(PATH_DB_ABSOLUTE, $strDestinationFile) ne $strArchiveChecksum)
{
confess "archive file hash does not match ${strArchiveChecksum}";
}
}
else
{
confess 'archive file is not in destination';
}
}
else
}
else
{
if (BackRestTestCommon_Execute($strCommand . " 000000090000000900000009 ${strXlogPath}/RECOVERYXLOG",
false, true) != 1)
{
confess 'archive file is not in destination';
confess 'archive-get should return 1 when archive log is not present';
}
}
$bCreate = true;
}
}
}
}
if (BackRestTestCommon_Cleanup())

View File

@ -117,6 +117,8 @@ sub BackRestTestCommon_ExecuteBegin
$strOutLog = '';
$hOut = undef;
&log(DEBUG, "executing command: ${strCommand}");
# Execute the command
$pId = open3(undef, $hOut, $hError, $strCommand);
}
@ -175,11 +177,15 @@ sub BackRestTestCommon_ExecuteEnd
($strOutLog ne '' ? "STDOUT:\n${strOutLog}" : '') .
($strErrorLog ne '' ? "STDERR:\n${strErrorLog}" : ''));
}
else
{
&log(DEBUG, "suppressed error was ${iExitStatus}");
}
$hError = undef;
$hOut = undef;
return false;
return $iExitStatus;
}
####################################################################################################################################
@ -192,7 +198,7 @@ sub BackRestTestCommon_Execute
my $bSuppressError = shift;
BackRestTestCommon_ExecuteBegin($strCommand, $bRemote);
BackRestTestCommon_ExecuteEnd(undef, $bSuppressError);
return BackRestTestCommon_ExecuteEnd(undef, $bSuppressError);
}
####################################################################################################################################

View File

@ -558,7 +558,7 @@ sub BackRestTestFile_Test
&log(INFO, '--------------------------------------------------------------------------------');
&log(INFO, "Test File->list()\n");
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
for (my $bRemote = false; $bRemote <= true; $bRemote++)
{
# Create the file object
my $oFile = BackRest::File->new
@ -569,8 +569,7 @@ sub BackRestTestFile_Test
oRemote => $bRemote ? $oRemote : undef
);
# Loop through exists
for (my $bSort = 0; $bSort <= 1; $bSort++)
for (my $bSort = false; $bSort <= true; $bSort++)
{
my $strSort = $bSort ? undef : 'reverse';
@ -591,14 +590,16 @@ sub BackRestTestFile_Test
}
# Loop through exists
for (my $bExists = 0; $bExists <= 1; $bExists++)
for (my $bExists = false; $bExists <= true; $bExists++)
{
# Loop through ignore missing
for (my $bIgnoreMissing = false; $bIgnoreMissing <= $bExists; $bIgnoreMissing++)
{
# Loop through error
for (my $bError = 0; $bError <= 1; $bError++)
for (my $bError = false; $bError <= true; $bError++)
{
if (!BackRestTestCommon_Run(++$iRun,
"rmt ${bRemote}, err ${bError}, exists ${bExists}, " .
"rmt ${bRemote}, err ${bError}, exists ${bExists}, ignmis ${bIgnoreMissing}, " .
'expression ' . (defined($strExpression) ? $strExpression : '[undef]') . ', ' .
'sort ' . (defined($strSort) ? $strSort : '[undef]'))) {next}
@ -625,11 +626,11 @@ sub BackRestTestFile_Test
# Execute in eval in case of error
my @stryFileList;
my $bErrorExpected = !$bExists || $bError;
my $bErrorExpected = (!$bExists && !$bIgnoreMissing) || $bError;
eval
{
@stryFileList = $oFile->list(PATH_BACKUP_ABSOLUTE, $strPath, $strExpression, $strSort);
@stryFileList = $oFile->list(PATH_BACKUP_ABSOLUTE, $strPath, $strExpression, $strSort, $bIgnoreMissing);
};
if ($@)
@ -668,6 +669,7 @@ sub BackRestTestFile_Test
}
}
}
}
}
}
}