mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-03-05 15:05:48 +02:00
More backup unit tests.
This commit is contained in:
parent
9765b4e20b
commit
602db70d6a
@ -354,6 +354,34 @@ sub BackRestTestBackup_ManifestFileCreate
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestBackup_ManifestFileRemove
|
||||
#
|
||||
# Remove a file from disk and the manifest.
|
||||
####################################################################################################################################
|
||||
sub BackRestTestBackup_ManifestFileRemove
|
||||
{
|
||||
my $oManifestRef = shift;
|
||||
my $strPath = shift;
|
||||
my $strFile = shift;
|
||||
my $bManifestRemove = shift;
|
||||
|
||||
# Create actual file location
|
||||
my $strPathFile = ${$oManifestRef}{'backup:path'}{$strPath} . "/${strFile}";
|
||||
|
||||
# Remove the file
|
||||
if (-e $strPathFile)
|
||||
{
|
||||
BackRestTestCommon_FileRemove($strPathFile);
|
||||
}
|
||||
|
||||
# Remove from manifest
|
||||
if (defined($bManifestRemove) && $bManifestRemove)
|
||||
{
|
||||
delete(${$oManifestRef}{"${strPath}:file"}{$strFile});
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestBackup_ManifestReference
|
||||
#
|
||||
@ -363,9 +391,19 @@ sub BackRestTestBackup_ManifestReference
|
||||
{
|
||||
my $oManifestRef = shift;
|
||||
my $strReference = shift;
|
||||
my $bClear = shift;
|
||||
|
||||
# Set prior backup
|
||||
${$oManifestRef}{backup}{prior} = $strReference;
|
||||
if (defined($strReference))
|
||||
{
|
||||
${$oManifestRef}{backup}{prior} = $strReference;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete(${$oManifestRef}{backup}{prior});
|
||||
}
|
||||
|
||||
# Clear the reference list
|
||||
delete(${$oManifestRef}{backup}{reference});
|
||||
|
||||
# Find all file sections
|
||||
@ -379,7 +417,19 @@ sub BackRestTestBackup_ManifestReference
|
||||
|
||||
foreach my $strFile (sort(keys ${$oManifestRef}{$strSectionFile}))
|
||||
{
|
||||
if (!defined(${$oManifestRef}{$strSectionFile}{$strFile}{reference}))
|
||||
if (!defined($strReference))
|
||||
{
|
||||
delete(${$oManifestRef}{$strSectionFile}{$strFile}{reference});
|
||||
}
|
||||
elsif (defined($bClear) && $bClear)
|
||||
{
|
||||
if (defined(${$oManifestRef}{$strSectionFile}{$strFile}{reference}) &&
|
||||
${$oManifestRef}{$strSectionFile}{$strFile}{reference} ne $strReference)
|
||||
{
|
||||
delete(${$oManifestRef}{$strSectionFile}{$strFile}{reference});
|
||||
}
|
||||
}
|
||||
elsif (!defined(${$oManifestRef}{$strSectionFile}{$strFile}{reference}))
|
||||
{
|
||||
${$oManifestRef}{$strSectionFile}{$strFile}{reference} = $strReference;
|
||||
}
|
||||
@ -890,21 +940,21 @@ sub BackRestTestBackup_Test
|
||||
BackRestTestCommon_Execute("${strCommand} --type=${strType}", $bRemote);
|
||||
|
||||
$oManifest{backup}{type} = $strType;
|
||||
my $strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
my $strFullBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, $strBackup, \%oManifest);
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, $strFullBackup, \%oManifest);
|
||||
|
||||
# Perform first incr backup
|
||||
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
||||
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup);
|
||||
$oManifest{'backup:option'}{hardlink} = $bHardlink ? 'y' : 'n';
|
||||
|
||||
$strType = 'incr';
|
||||
&log(INFO, " ${strType} backup (no file changes, only references)");
|
||||
&log(INFO, " ${strType} backup (no updates)");
|
||||
|
||||
BackRestTestCommon_Execute("${strCommand} --type=${strType}", $bRemote);
|
||||
|
||||
$oManifest{backup}{type} = $strType;
|
||||
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
my $strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
||||
|
||||
@ -951,6 +1001,131 @@ sub BackRestTestBackup_Test
|
||||
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
||||
|
||||
# Perform first diff backup
|
||||
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup, true);
|
||||
|
||||
$strType = 'diff';
|
||||
&log(INFO, " ${strType} backup (no updates)");
|
||||
|
||||
BackRestTestCommon_Execute("${strCommand} --type=${strType}", $bRemote);
|
||||
|
||||
$oManifest{backup}{type} = $strType;
|
||||
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
||||
|
||||
# Perform fourth incr backup
|
||||
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
||||
|
||||
$strType = 'incr';
|
||||
&log(INFO, " ${strType} backup (remove files - but won't affect manifest)");
|
||||
|
||||
BackRestTestCommon_ExecuteBegin("${strCommand} --type=${strType} --test --test-delay=1", $bRemote);
|
||||
|
||||
if (BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD))
|
||||
{
|
||||
BackRestTestBackup_ManifestFileRemove(\%oManifest, 'base', 'base/base1.txt');
|
||||
|
||||
for (my $iTablespaceIdx = 1; $iTablespaceIdx <= $iTablespaceTotal; $iTablespaceIdx++)
|
||||
{
|
||||
BackRestTestBackup_ManifestFileRemove(\%oManifest, "tablespace:${iTablespaceIdx}", 'tablespace1.txt');
|
||||
}
|
||||
|
||||
BackRestTestCommon_ExecuteEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
confess &log(ERROR, 'test point ' . TEST_MANIFEST_BUILD . ' was not found');
|
||||
}
|
||||
|
||||
$oManifest{backup}{type} = $strType;
|
||||
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
||||
|
||||
# Perform second diff backup
|
||||
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup, true);
|
||||
|
||||
$strType = 'diff';
|
||||
&log(INFO, " ${strType} backup (remove files)");
|
||||
|
||||
BackRestTestBackup_ManifestFileRemove(\%oManifest, 'base', 'base/base1.txt', true);
|
||||
|
||||
for (my $iTablespaceIdx = 1; $iTablespaceIdx <= $iTablespaceTotal; $iTablespaceIdx++)
|
||||
{
|
||||
BackRestTestBackup_ManifestFileRemove(\%oManifest, "tablespace:${iTablespaceIdx}", 'tablespace1.txt', true);
|
||||
}
|
||||
|
||||
BackRestTestCommon_ExecuteBegin("${strCommand} --type=${strType} --test --test-delay=1", $bRemote);
|
||||
|
||||
if (BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD))
|
||||
{
|
||||
BackRestTestBackup_ManifestFileRemove(\%oManifest, 'base', 'base/base2.txt', true);
|
||||
|
||||
for (my $iTablespaceIdx = 1; $iTablespaceIdx <= $iTablespaceTotal; $iTablespaceIdx++)
|
||||
{
|
||||
BackRestTestBackup_ManifestFileRemove(\%oManifest, "tablespace:${iTablespaceIdx}", 'tablespace2.txt', true);
|
||||
delete($oManifest{"tablespace:${iTablespaceIdx}:file"});
|
||||
}
|
||||
|
||||
BackRestTestCommon_ExecuteEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
confess &log(ERROR, 'test point ' . TEST_MANIFEST_BUILD . ' was not found');
|
||||
}
|
||||
|
||||
$oManifest{backup}{type} = $strType;
|
||||
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
||||
|
||||
# Perform second full backup
|
||||
BackRestTestBackup_ManifestReference(\%oManifest);
|
||||
delete($oManifest{'backup:option'}{hardlink});
|
||||
|
||||
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base1.txt', 'BASEUPDT2',
|
||||
$bChecksum ? '7579ada0808d7f98087a0a586d0df9de009cdc33' : undef, $lTime);
|
||||
|
||||
for (my $iTablespaceIdx = 1; $iTablespaceIdx <= $iTablespaceTotal; $iTablespaceIdx++)
|
||||
{
|
||||
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace:${iTablespaceIdx}", 'tablespace1.txt', 'TBLSPCUPDT2',
|
||||
$bChecksum ? '42f9bdebc34de4476f21688d00b37ea77d1a2ffc' : undef, $lTime);
|
||||
}
|
||||
|
||||
$strType = 'full';
|
||||
&log(INFO, " ${strType} backup");
|
||||
|
||||
BackRestTestCommon_Execute("${strCommand} --type=${strType}", $bRemote);
|
||||
|
||||
$oManifest{backup}{type} = $strType;
|
||||
$strFullBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, $strFullBackup, \%oManifest);
|
||||
|
||||
# Perform third diff backup
|
||||
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup);
|
||||
$oManifest{'backup:option'}{hardlink} = $bHardlink ? 'y' : 'n';
|
||||
|
||||
$strType = 'diff';
|
||||
&log(INFO, " ${strType} backup (add files)");
|
||||
|
||||
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base2.txt', 'BASE2UPDT',
|
||||
$bChecksum ? 'cafac3c59553f2cfde41ce2e62e7662295f108c0' : undef, $lTime);
|
||||
|
||||
for (my $iTablespaceIdx = 1; $iTablespaceIdx <= $iTablespaceTotal; $iTablespaceIdx++)
|
||||
{
|
||||
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace:${iTablespaceIdx}", 'tablespace2.txt', 'TBLSPC2UPDT',
|
||||
$bChecksum ? 'bee4bf711a7533db234eda606782af7e80a76cf2' : undef, $lTime);
|
||||
}
|
||||
|
||||
BackRestTestCommon_Execute("${strCommand} --type=${strType}", $bRemote);
|
||||
|
||||
$oManifest{backup}{type} = $strType;
|
||||
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||
|
||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ use BackRest::File;
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin BackRestTestCommon_ExecuteEnd
|
||||
BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest
|
||||
BackRestTestCommon_PathCreate BackRestTestCommon_PathRemove BackRestTestCommon_FileCreate
|
||||
BackRestTestCommon_PathCreate BackRestTestCommon_PathRemove
|
||||
BackRestTestCommon_FileCreate BackRestTestCommon_FileRemove
|
||||
BackRestTestCommon_ConfigCreate BackRestTestCommon_Run BackRestTestCommon_Cleanup
|
||||
BackRestTestCommon_PgSqlBinPathGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet
|
||||
BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet
|
||||
@ -272,7 +273,7 @@ sub BackRestTestCommon_FileCreate
|
||||
or confess "unable to open ${strFile} for writing";
|
||||
|
||||
syswrite($hFile, $strContent)
|
||||
or confess "unable to write lf: $!";
|
||||
or confess "unable to write to ${strFile}: $!";
|
||||
|
||||
close($hFile);
|
||||
|
||||
@ -288,6 +289,19 @@ sub BackRestTestCommon_FileCreate
|
||||
or confess 'unable to set mode ${strMode} for ${strFile}';
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestCommon_FileRemove
|
||||
#
|
||||
# Remove a file.
|
||||
####################################################################################################################################
|
||||
sub BackRestTestCommon_FileRemove
|
||||
{
|
||||
my $strFile = shift;
|
||||
|
||||
unlink($strFile)
|
||||
or confess "unable to remove ${strFile}: $!";
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestCommon_Setup
|
||||
####################################################################################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user