mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Fixes to restore compare unit tests.
This commit is contained in:
parent
8abcf6caf1
commit
bde8943517
@ -1235,7 +1235,7 @@ sub backup
|
||||
my $oBackupManifest = new BackRest::Manifest($strBackupConfFile, false);
|
||||
|
||||
# Find the previous backup based on the type
|
||||
my $oLastManifest;
|
||||
my $oLastManifest = undef;
|
||||
|
||||
my $strBackupLastPath = backup_type_find($strType, $oFile->path_get(PATH_BACKUP_CLUSTER));
|
||||
|
||||
@ -1243,11 +1243,8 @@ sub backup
|
||||
{
|
||||
$oLastManifest = new BackRest::Manifest($oFile->path_get(PATH_BACKUP_CLUSTER) . "/${strBackupLastPath}/backup.manifest");
|
||||
|
||||
my $strLastBackupLabel = $oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL);
|
||||
|
||||
&log(INFO, "last backup label: ${strLastBackupLabel}, version " .
|
||||
$oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_VERSION));
|
||||
$oBackupManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef, $strLastBackupLabel);
|
||||
&log(INFO, 'last backup label: ' . $oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL) .
|
||||
', version ' . $oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_VERSION));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -517,11 +517,19 @@ sub build
|
||||
my $oTablespaceMapRef = shift;
|
||||
my $strLevel = shift;
|
||||
|
||||
&log(DEBUG, 'Manifest->build');
|
||||
|
||||
# If no level is defined then it must be base
|
||||
if (!defined($strLevel))
|
||||
{
|
||||
$strLevel = 'base';
|
||||
|
||||
if (defined($oLastManifest))
|
||||
{
|
||||
$self->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef,
|
||||
$oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL));
|
||||
}
|
||||
|
||||
# If bNoStartStop then build the tablespace map from pg_tblspc path
|
||||
if ($bNoStartStop)
|
||||
{
|
||||
@ -537,14 +545,14 @@ sub build
|
||||
next;
|
||||
}
|
||||
|
||||
if ($oTablespaceManifestHash{name}{"${strName}"}{type} ne 'l')
|
||||
if ($oTablespaceManifestHash{name}{$strName}{type} ne 'l')
|
||||
{
|
||||
confess &log(ERROR, "pg_tblspc/${strName} is not a link");
|
||||
}
|
||||
|
||||
&log(DEBUG, "Found tablespace ${strName}");
|
||||
|
||||
${$oTablespaceMapRef}{oid}{"${strName}"}{name} = $strName;
|
||||
${$oTablespaceMapRef}{oid}{$strName}{name} = $strName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -611,7 +619,7 @@ sub build
|
||||
if (index($strName, 'pg_tblspc/') == 0 && $strLevel eq 'base')
|
||||
{
|
||||
my $strTablespaceOid = basename($strName);
|
||||
my $strTablespaceName = ${$oTablespaceMapRef}{oid}{"${strTablespaceOid}"}{name};
|
||||
my $strTablespaceName = ${$oTablespaceMapRef}{oid}{$strTablespaceOid}{name};
|
||||
|
||||
$self->set(MANIFEST_SECTION_BACKUP_TABLESPACE, $strTablespaceName,
|
||||
MANIFEST_SUBKEY_LINK, $strTablespaceOid);
|
||||
|
@ -22,6 +22,7 @@ use lib dirname($0) . '/../lib';
|
||||
use BackRest::Exception;
|
||||
use BackRest::Utility;
|
||||
use BackRest::Config;
|
||||
use BackRest::Manifest;
|
||||
use BackRest::File;
|
||||
use BackRest::Remote;
|
||||
|
||||
@ -1003,6 +1004,8 @@ sub BackRestTestBackup_Restore
|
||||
$bDelta = defined($bDelta) ? $bDelta : false;
|
||||
$bForce = defined($bForce) ? $bForce : false;
|
||||
|
||||
my $bSynthetic = defined($oExpectedManifestRef) ? true : false;
|
||||
|
||||
&log(INFO, ' restore' .
|
||||
($bDelta ? ' delta' : '') .
|
||||
($bForce ? ', force' : '') .
|
||||
@ -1061,7 +1064,7 @@ sub BackRestTestBackup_Restore
|
||||
|
||||
if (!defined($iExpectedExitStatus))
|
||||
{
|
||||
BackRestTestBackup_RestoreCompare($oFile, $strStanza, $bRemote, $strBackup, $oExpectedManifestRef);
|
||||
BackRestTestBackup_RestoreCompare($oFile, $strStanza, $bRemote, $strBackup, $bSynthetic, $oExpectedManifestRef);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1074,6 +1077,7 @@ sub BackRestTestBackup_RestoreCompare
|
||||
my $strStanza = shift;
|
||||
my $bRemote = shift;
|
||||
my $strBackup = shift;
|
||||
my $bSynthetic = shift;
|
||||
my $oExpectedManifestRef = shift;
|
||||
|
||||
my $strTestPath = BackRestTestCommon_TestPathGet();
|
||||
@ -1083,18 +1087,35 @@ sub BackRestTestBackup_RestoreCompare
|
||||
|
||||
if (defined(${$oExpectedManifestRef}{'backup'}{'prior'}))
|
||||
{
|
||||
# Change permissions on the backup path so it can be read
|
||||
if ($bRemote)
|
||||
{
|
||||
BackRestTestCommon_Execute('chmod 750 ' . BackRestTestCommon_BackupPathGet(), true);
|
||||
}
|
||||
|
||||
my $oExpectedManifest = new BackRest::Manifest(BackRestTestCommon_BackupPathGet() .
|
||||
"/backup/${strStanza}/${strBackup}/backup.manifest", true);
|
||||
|
||||
$oLastManifest = new BackRest::Manifest(BackRestTestCommon_BackupPathGet() .
|
||||
"/backup/${strStanza}/${strBackup}/backup.manifest", true);
|
||||
"/backup/${strStanza}/" . ${$oExpectedManifestRef}{'backup'}{'prior'} .
|
||||
'/backup.manifest', true);
|
||||
|
||||
# Change permissions on the backup path back before unit tests continue
|
||||
if ($bRemote)
|
||||
{
|
||||
BackRestTestCommon_Execute('chmod 700 ' . BackRestTestCommon_BackupPathGet(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Generate the actual manifest
|
||||
my $oActualManifest = new BackRest::Manifest("${strTestPath}/actual.manifest", false);
|
||||
|
||||
my %oTablespaceMap;
|
||||
$oActualManifest->build($oFile, ${$oExpectedManifestRef}{'backup:path'}{'base'}, $oLastManifest, false, \%oTablespaceMap);
|
||||
delete(${$oActualManifest->{oManifest}}{'backup'}{'timestamp-copy-start'});
|
||||
my $oTablespaceMapRef = undef;
|
||||
$oActualManifest->build($oFile, ${$oExpectedManifestRef}{'backup:path'}{'base'}, $oLastManifest, $bSynthetic, undef);
|
||||
|
||||
# Build paths/links in each restore path
|
||||
# Generate checksums for all files if required
|
||||
# Also fudge size if this is a synthetic test - sizes may change during backup.
|
||||
foreach my $strSectionPathKey ($oActualManifest->keys('backup:path'))
|
||||
{
|
||||
my $strSectionPath = $oActualManifest->get('backup:path', $strSectionPathKey);
|
||||
@ -1104,7 +1125,10 @@ sub BackRestTestBackup_RestoreCompare
|
||||
|
||||
foreach my $strName ($oActualManifest->keys($strSection))
|
||||
{
|
||||
$oActualManifest->set($strSection, $strName, 'size', ${$oExpectedManifestRef}{$strSection}{$strName}{size});
|
||||
if (!$bSynthetic)
|
||||
{
|
||||
$oActualManifest->set($strSection, $strName, 'size', ${$oExpectedManifestRef}{$strSection}{$strName}{size});
|
||||
}
|
||||
|
||||
if ($oActualManifest->get($strSection, $strName, 'size') != 0 &&
|
||||
defined(${$oExpectedManifestRef}{'backup:option'}{checksum}) &&
|
||||
@ -1116,37 +1140,40 @@ sub BackRestTestBackup_RestoreCompare
|
||||
}
|
||||
}
|
||||
|
||||
# Now get rid of all pg_xlog files in the actual and expected manifests
|
||||
# my $strSection = "base:file";
|
||||
#
|
||||
# foreach my $strName ($oActualManifest->keys($strSection))
|
||||
# {
|
||||
# if ($strName =~ /^pg_xlog\/.*$/)
|
||||
# {
|
||||
# $oActualManifest->remove($strSection, $strName);
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# foreach my $strName (sort(keys(${$oExpectedManifestRef}{$strSection})))
|
||||
# {
|
||||
# if ($strName =~ /^pg_xlog\/.*$/)
|
||||
# {
|
||||
# delete(${$oExpectedManifestRef}{$strSection}{$strName});
|
||||
# }
|
||||
# }
|
||||
# Set actual to expected for settings that always change from backup to backup
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_CHECKSUM, undef,
|
||||
${$oExpectedManifestRef}{'backup:option'}{checksum});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_COMPRESS, undef,
|
||||
${$oExpectedManifestRef}{'backup:option'}{compress});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_HARDLINK, undef,
|
||||
${$oExpectedManifestRef}{'backup:option'}{hardlink});
|
||||
|
||||
delete(${$oExpectedManifestRef}{'backup:option'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'archive-start'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'archive-stop'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'label'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'type'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'version'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'timestamp-db-start'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'timestamp-db-stop'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'timestamp-start'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'timestamp-stop'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'timestamp-copy-start'});
|
||||
delete(${$oExpectedManifestRef}{'backup'}{'checksum'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_VERSION, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{version});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_COPY_START, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'timestamp-copy-start'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_START, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'timestamp-start'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_STOP, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'timestamp-stop'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'label'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'type'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_CHECKSUM, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'checksum'});
|
||||
|
||||
if (!$bSynthetic)
|
||||
{
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_ARCHIVE_START, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'archive-start'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_ARCHIVE_STOP, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'archive-stop'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_DB_START, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'timestamp-db-start'});
|
||||
$oActualManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_DB_STOP, undef,
|
||||
${$oExpectedManifestRef}{'backup'}{'timestamp-db-stop'});
|
||||
}
|
||||
|
||||
ini_save("${strTestPath}/actual.manifest", $oActualManifest->{oManifest});
|
||||
ini_save("${strTestPath}/expected.manifest", $oExpectedManifestRef);
|
||||
|
Loading…
Reference in New Issue
Block a user