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

Archive checksums are not calculated in stream.

This commit is contained in:
David Steele 2015-03-01 16:42:27 -05:00
parent 393525d280
commit 76391dde90
4 changed files with 47 additions and 18 deletions

View File

@ -102,7 +102,8 @@ while ($strCommand ne OP_EXIT)
param_get(\%oParamHash, 'permission', false),
param_get(\%oParamHash, 'destination_path_create') ? 'Y' : 'N',
param_get(\%oParamHash, 'user', false),
param_get(\%oParamHash, 'group', false));
param_get(\%oParamHash, 'group', false),
param_get(\%oParamHash, 'append_checksum', false));
}
# Copy a file from STDIN
elsif ($strCommand eq OP_FILE_COPY_IN)
@ -115,7 +116,8 @@ while ($strCommand ne OP_EXIT)
param_get(\%oParamHash, 'permission', false),
param_get(\%oParamHash, 'destination_path_create'),
param_get(\%oParamHash, 'user', false),
param_get(\%oParamHash, 'group', false));
param_get(\%oParamHash, 'group', false),
param_get(\%oParamHash, 'append_checksum', false));
}
# Copy a file to STDOUT
elsif ($strCommand eq OP_FILE_COPY_OUT)

View File

@ -317,12 +317,6 @@ sub archive_push
# Determine if this is an archive file (don't want to do compression or checksum on .backup files)
my $bArchiveFile = basename($strSourceFile) =~ /^[0-F]{24}$/ ? true : false;
# Append the checksum (if requested)
if ($bArchiveFile)
{
$strDestinationFile .= '-' . $oFile->hash(PATH_DB_ABSOLUTE, $strSourceFile);
}
# Append compression extension
if ($bArchiveFile && $bCompress)
{
@ -335,7 +329,9 @@ sub archive_push
false, # Source is not compressed
$bArchiveFile && $bCompress, # Destination compress is configurable
undef, undef, undef, # Unused params
true); # Create path if it does not exist
true, # Create path if it does not exist
undef, undef, # User and group
$bArchiveFile); # Append checksum if archive file
}
####################################################################################################################################
@ -1501,8 +1497,7 @@ sub backup
my $strFileLog = "pg_xlog/${strArchive}";
# Compare the checksum against the one already in the archive log name
if ($stryArchiveFile[0] =~ "^${strArchive}-[0-f]+(\\.$oFile->{strCompressExtension}){0,1}\$" &&
$stryArchiveFile[0] !~ "^${strArchive}-${strCopyChecksum}(\\.$oFile->{strCompressExtension}){0,1}\$")
if ($stryArchiveFile[0] !~ "^${strArchive}-${strCopyChecksum}(\\.$oFile->{strCompressExtension}){0,1}\$")
{
confess &log(ERROR, "error copying log '$stryArchiveFile[0]' to backup - checksum recorded with file does " .
"not match actual checksum of '${strCopyChecksum}'", ERROR_CHECKSUM);

View File

@ -1291,12 +1291,14 @@ sub copy
my $bDestinationPathCreate = shift;
my $strUser = shift;
my $strGroup = shift;
my $bAppendChecksum = shift;
# Set defaults
$bSourceCompressed = defined($bSourceCompressed) ? $bSourceCompressed : false;
$bDestinationCompress = defined($bDestinationCompress) ? $bDestinationCompress : false;
$bIgnoreMissingSource = defined($bIgnoreMissingSource) ? $bIgnoreMissingSource : false;
$bDestinationPathCreate = defined($bDestinationPathCreate) ? $bDestinationPathCreate : false;
$bAppendChecksum = defined($bAppendChecksum) ? $bAppendChecksum : false;
# Set working variables
my $bSourceRemote = $self->is_remote($strSourcePathType) || $strSourcePathType eq PIPE_STDIN;
@ -1461,6 +1463,11 @@ sub copy
$oParamHash{group} = $strGroup;
}
if ($bAppendChecksum)
{
$oParamHash{append_checksum} = true;
}
$hOut = $self->{oRemote}->{hIn};
}
}
@ -1494,6 +1501,11 @@ sub copy
{
$oParamHash{ignore_missing_source} = $bIgnoreMissingSource;
}
if ($bAppendChecksum)
{
$oParamHash{append_checksum} = true;
}
}
# Build debug string
@ -1637,14 +1649,34 @@ sub copy
$self->owner(PATH_ABSOLUTE, $strDestinationTmpOp, $strUser, $strGroup);
}
# Move the file from tmp to final destination
$self->move(PATH_ABSOLUTE, $strDestinationTmpOp, PATH_ABSOLUTE, $strDestinationOp, true);
# Get the checksum and size if they are not already set
if (!defined($strChecksum) || !defined($iFileSize))
{
($strChecksum, $iFileSize) = $self->hash_size(PATH_ABSOLUTE, $strDestinationOp, $bDestinationCompress);
($strChecksum, $iFileSize) = $self->hash_size(PATH_ABSOLUTE, $strDestinationTmpOp, $bDestinationCompress);
}
# Replace checksum in destination filename (if exists)
if ($bAppendChecksum)
{
if (!defined($strChecksum))
{
confess &log(ERROR, "${strDebug}: unable to append unset checksum");
}
if ($bDestinationCompress)
{
$strDestinationOp =
substr($strDestinationOp, 0, length($strDestinationOp) - length($self->{strCompressExtension}) - 1) .
'-' . $strChecksum . '.' . $self->{strCompressExtension};
}
else
{
$strDestinationOp .= '-' . $strChecksum;
}
}
# Move the file from tmp to final destination
$self->move(PATH_ABSOLUTE, $strDestinationTmpOp, PATH_ABSOLUTE, $strDestinationOp, true);
}
return $bResult, $strChecksum, $iFileSize;

View File

@ -1772,13 +1772,13 @@ sub BackRestTestBackup_Test
for (my $bRemote = false; $bRemote <= true; $bRemote++)
{
for (my $bCompress = false; $bCompress <= true; $bCompress++)
{
for (my $bArchiveAsync = false; $bArchiveAsync <= true; $bArchiveAsync++)
{
for (my $bCompress = false; $bCompress <= true; $bCompress++)
{
# Increment the run, log, and decide whether this unit test should be run
if (!BackRestTestCommon_Run(++$iRun,
"rmt ${bRemote}, cmp ${bCompress}, arc_async ${bArchiveAsync}")) {next}
"rmt ${bRemote}, arc_async ${bArchiveAsync}, cmp ${bCompress}")) {next}
# Create the file object
my $oFile = new BackRest::File