1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Fixed info command to eliminate "db (prior)" output if no backups or archives exist for a prior version of the cluster.

Fixed by Cynthia Shang.
Reported by Stephen Frost.
This commit is contained in:
Cynthia Shang 2017-12-19 15:39:39 -05:00 committed by David Steele
parent 717a147542
commit c34a76690f
3 changed files with 71 additions and 7 deletions

View File

@ -28,6 +28,15 @@
<p>Fixed an issue where WAL was not expired on <postgres/> 10. This was caused by a faulty regex that expected all <postgres/> major versions to be X.X.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="frost.stephen"/>
<release-item-contributor id="shang.cynthia"/>
</release-item-contributor-list>
<p>Fixed <cmd>info</cmd> command to eliminate <code>"db (prior)"</code> output if no backups or archives exist for a prior version of the cluster.</p>
</release-item>
</release-bug-list>
<release-feature-list>

View File

@ -201,38 +201,62 @@ sub formatText
# Loop through the DB history array for the stanza from newest to oldest
foreach my $hDbInfo (reverse @{$oStanzaInfo->{&INFO_BACKUP_SECTION_DB}})
{
$strOutput .= $bDbCurrent ? "\n db (current)" : "\n db (prior)";
$bDbCurrent = false;
if ($bDbCurrent)
{
$strOutput .= "\n db (current)";
}
# Get the archive information for the DB
my $strOutputArchive;
foreach my $hDbArchive (@{$oStanzaInfo->{&INFO_SECTION_ARCHIVE}})
{
if ($hDbArchive->{&INFO_SECTION_DB}{&INFO_HISTORY_ID} == $hDbInfo->{&INFO_HISTORY_ID})
{
# Output archive start / stop values
$strOutput .= "\n wal archive min/max (" . $hDbArchive->{&INFO_KEY_ID} . "): ";
$strOutputArchive .= "\n wal archive min/max (" . $hDbArchive->{&INFO_KEY_ID} . "): ";
if (defined($hDbArchive->{&INFO_KEY_MIN}))
{
$strOutput .= $hDbArchive->{&INFO_KEY_MIN} . ' / ' . $hDbArchive->{&INFO_KEY_MAX};
$strOutputArchive .= $hDbArchive->{&INFO_KEY_MIN} . ' / ' . $hDbArchive->{&INFO_KEY_MAX};
}
else
{
$strOutput .= 'none present';
$strOutputArchive .= 'none present';
}
$strOutput .= "\n";
$strOutputArchive .= "\n";
}
}
# Get information for each stanza backup for the DB, from oldest to newest
my $strOutputBackup;
foreach my $oBackupInfo (@{$$oStanzaInfo{&INFO_BACKUP_SECTION_BACKUP}})
{
if ($oBackupInfo->{&INFO_SECTION_DB}{&INFO_KEY_ID} == $hDbInfo->{&INFO_HISTORY_ID})
{
$strOutput .= "\n" . $self->formatTextBackup($oBackupInfo) . "\n";
$strOutputBackup .= "\n" . $self->formatTextBackup($oBackupInfo) . "\n";
}
}
if (defined($strOutputArchive) || defined($strOutputBackup))
{
if (!$bDbCurrent)
{
$strOutput .= "\n db (prior)";
}
if (defined($strOutputArchive))
{
$strOutput .= $strOutputArchive;
}
if (defined($strOutputBackup))
{
$strOutput .= $strOutputBackup;
}
}
$bDbCurrent = false;
}
}

View File

@ -15,6 +15,7 @@ use English '-no_match_vars';
use File::Basename qw(dirname);
use Storable qw(dclone);
use pgBackRest::Backup::Common;
use pgBackRest::Backup::Info;
use pgBackRest::Common::Exception;
use pgBackRest::Common::Lock;
@ -365,6 +366,36 @@ sub run
" repository size: 0B, repository backup size: 0B\n",
"formatText() multiple DB versions");
# Remove backup from db (prior)
#---------------------------------------------------------------------------------------------------------------------------
# Load the backup.info file
my $oBackupInfo = new pgBackRest::Backup::Info($self->{strBackupPath});
my @stryPath = $oBackupInfo->list(backupRegExpGet(true));
# Remove the db prior full backup from the info file and save it
$oBackupInfo->delete($stryPath[0]);
$oBackupInfo->save();
# Remove the backup directory
storageTest()->remove($self->{strBackupPath} . "/" . $stryPath[0], {bRecurse => true});
$hyStanza = $oInfo->stanzaList($self->stanza());
$self->testResult(sub {$oInfo->formatText($hyStanza)},
"stanza: db\n status: ok\n" .
"\n db (current)\n" .
" wal archive min/max (9.5-2): 000000010000000000000000 / 000000010000000000000003\n\n" .
" full backup: 20161207-155728F\n" .
" timestamp start/stop: 2016-12-07 15:57:28 / 2016-12-07 15:57:28\n" .
" wal start/stop: 000000010000000000000000 / 000000010000000000000000\n" .
" database size: 0B, backup size: 0B\n" .
" repository size: 0B, repository backup size: 0B\n\n" .
" diff backup: 20161207-155728F_20161208-155728D\n" .
" timestamp start/stop: 2016-12-08 15:57:28 / 2016-12-08 15:57:28\n" .
" wal start/stop: 000000010000000000000002 / 000000010000000000000002\n" .
" database size: 0B, backup size: 0B\n" .
" repository size: 0B, repository backup size: 0B\n",
"db (prior) removed");
# dbArchiveSection() -- with archive
#---------------------------------------------------------------------------------------------------------------------------
$hDbInfo->{&INFO_HISTORY_ID} = 2;