From bacc08792dae400de652ce2f769aeeda73f0ef8e Mon Sep 17 00:00:00 2001 From: Cynthia Shang Date: Tue, 30 Jan 2018 16:49:47 -0500 Subject: [PATCH] Ensure latest db-id is selected on when matching archive.info to backup.info. This provides correct matching in the event there are system-id and db-version duplicates (e.g. after reverting a pg_upgrade). Fixed by Cynthia Shang. Reported by Adam K. Sumner. --- doc/xml/release.xml | 14 ++++++++++++++ lib/pgBackRest/Backup/Info.pm | 3 ++- .../Module/Backup/BackupInfoUnitTest.pm | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 67327dccd..f98b7a9b6 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -20,6 +20,15 @@

Fixed inability to restore a single database contained in a tablespace using --db-include.

+ + + + + + + +

Ensure latest db-id is selected on when matching archive.info to backup.info. This provides correct matching in the event there are system-id and db-version duplicates (e.g. after reverting a pg_upgrade).

+
@@ -4037,6 +4046,11 @@ Underhunden + + Adam K. Sumner + Flamacue + + Uspen uspen diff --git a/lib/pgBackRest/Backup/Info.pm b/lib/pgBackRest/Backup/Info.pm index 8abdb8c08..2098a505d 100644 --- a/lib/pgBackRest/Backup/Info.pm +++ b/lib/pgBackRest/Backup/Info.pm @@ -667,7 +667,8 @@ sub backupArchiveDbHistoryId my $ullDbSysIdArchive = $$hDbListArchive{$iDbIdArchive}{&INFO_SYSTEM_ID}; # Get the db-id from backup info history that corresponds to the archive db-version and db-system-id - foreach my $iDbIdBackup (keys %{$hDbListBackup}) + # Sort from newest (highest db-id) to oldest + foreach my $iDbIdBackup (sort {$b <=> $a} keys %{$hDbListBackup}) { if ($$hDbListBackup{$iDbIdBackup}{&INFO_SYSTEM_ID} == $ullDbSysIdArchive && $$hDbListBackup{$iDbIdBackup}{&INFO_DB_VERSION} eq $strDbVersionArchive) diff --git a/test/lib/pgBackRestTest/Module/Backup/BackupInfoUnitTest.pm b/test/lib/pgBackRestTest/Module/Backup/BackupInfoUnitTest.pm index 820df652d..4dfb8d743 100644 --- a/test/lib/pgBackRestTest/Module/Backup/BackupInfoUnitTest.pm +++ b/test/lib/pgBackRestTest/Module/Backup/BackupInfoUnitTest.pm @@ -186,6 +186,18 @@ sub run $strArchiveId = &PG_VERSION_93 . "-" . $iHistoryId; $self->testResult(sub {$oBackupInfo->backupArchiveDbHistoryId($strArchiveId, storageRepo()->pathGet(STORAGE_REPO_ARCHIVE))}, "[undef]", 'same db system-id but different version'); + + # First and last version and ullsystemid same in backup.info but only 1st in archive info - return last + #--------------------------------------------------------------------------------------------------------------------------- + $iHistoryId = $oBackupInfo->dbHistoryIdGet(true)+1; + $oBackupInfo->dbSectionSet( + PG_VERSION_93, $i93ControlVersion, $i93CatalogVersion, $self->dbSysId(PG_VERSION_93), $iHistoryId); + + $oBackupInfo->save(); + + $strArchiveId = &PG_VERSION_93 . "-1"; + $self->testResult(sub {$oBackupInfo->backupArchiveDbHistoryId($strArchiveId, + storageRepo()->pathGet(STORAGE_REPO_ARCHIVE))}, $iHistoryId, 'duplicate 1st and last version/sysid - last chosen'); } ################################################################################################################################