You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-03 00:26:59 +02:00
Unit tests for backup resume.
Improved warning message when a backup cannot be resumed.
This commit is contained in:
@ -1502,6 +1502,14 @@ sub backup
|
|||||||
{
|
{
|
||||||
my $bUsable = false;
|
my $bUsable = false;
|
||||||
|
|
||||||
|
my $strType = $oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE);
|
||||||
|
my $strPrior = $oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef, false, '<undef>');
|
||||||
|
my $strVersion = $oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_VERSION);
|
||||||
|
|
||||||
|
my $strAbortedType = '<undef>';
|
||||||
|
my $strAbortedPrior = '<undef>';
|
||||||
|
my $strAbortedVersion = '<undef>';
|
||||||
|
|
||||||
# Attempt to read the manifest file in the aborted backup to see if the backup type and prior backup are the same as the
|
# Attempt to read the manifest file in the aborted backup to see if the backup type and prior backup are the same as the
|
||||||
# new backup that is being started. If any error at all occurs then the backup will be considered unusable and a resume
|
# new backup that is being started. If any error at all occurs then the backup will be considered unusable and a resume
|
||||||
# will not be attempted.
|
# will not be attempted.
|
||||||
@ -1511,14 +1519,14 @@ sub backup
|
|||||||
my $oAbortedManifest = new BackRest::Manifest("${strBackupTmpPath}/backup.manifest");
|
my $oAbortedManifest = new BackRest::Manifest("${strBackupTmpPath}/backup.manifest");
|
||||||
|
|
||||||
# Default values if they are not set
|
# Default values if they are not set
|
||||||
my $strAbortedType = $oAbortedManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE);
|
$strAbortedType = $oAbortedManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE);
|
||||||
my $strAbortedPrior = $oAbortedManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR);
|
$strAbortedPrior = $oAbortedManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef, false, '<undef>');
|
||||||
my $strAbortedVersion = $oAbortedManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_VERSION);
|
$strAbortedVersion = $oAbortedManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_VERSION);
|
||||||
|
|
||||||
# The backup is usable if between the current backup and the aborted backup:
|
# The backup is usable if between the current backup and the aborted backup:
|
||||||
# 1) The version matches
|
# 1) The version matches
|
||||||
# 2) The type of both is full or the types match and prior matches
|
# 2) The type of both is full or the types match and prior matches
|
||||||
if ($strAbortedVersion eq $oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_VERSION))
|
if ($strAbortedVersion eq $strVersion)
|
||||||
{
|
{
|
||||||
if ($strAbortedType eq BACKUP_TYPE_FULL
|
if ($strAbortedType eq BACKUP_TYPE_FULL
|
||||||
&& $oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE) eq BACKUP_TYPE_FULL)
|
&& $oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE) eq BACKUP_TYPE_FULL)
|
||||||
@ -1537,6 +1545,7 @@ sub backup
|
|||||||
if ($bUsable)
|
if ($bUsable)
|
||||||
{
|
{
|
||||||
&log(WARN, 'aborted backup of same type exists, will be cleaned to remove invalid files and resumed');
|
&log(WARN, 'aborted backup of same type exists, will be cleaned to remove invalid files and resumed');
|
||||||
|
&log(TEST, TEST_BACKUP_RESUME);
|
||||||
|
|
||||||
# Clean the old backup tmp path
|
# Clean the old backup tmp path
|
||||||
backup_tmp_clean($oBackupManifest);
|
backup_tmp_clean($oBackupManifest);
|
||||||
@ -1544,7 +1553,22 @@ sub backup
|
|||||||
# Else remove it
|
# Else remove it
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
&log(WARN, 'aborted backup exists, but cannot be resumed - will be dropped and recreated');
|
my $strReason = "new version '${strVersion}' does not match aborted version '${strVersion}'";
|
||||||
|
|
||||||
|
if ($strVersion eq $strAbortedVersion)
|
||||||
|
{
|
||||||
|
if ($strType ne $strAbortedType)
|
||||||
|
{
|
||||||
|
$strReason = "new type '${strType}' does not match aborted type '${strAbortedType}'";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$strReason = "new prior '${strPrior}' does not match aborted prior '${strAbortedPrior}'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&log(WARN, "aborted backup exists, but cannot be resumed (${strReason}) - will be dropped and recreated");
|
||||||
|
&log(TEST, TEST_BACKUP_NORESUME);
|
||||||
|
|
||||||
remove_tree($oFile->path_get(PATH_BACKUP_TMP))
|
remove_tree($oFile->path_get(PATH_BACKUP_TMP))
|
||||||
or confess &log(ERROR, "unable to delete tmp path: ${strBackupTmpPath}");
|
or confess &log(ERROR, "unable to delete tmp path: ${strBackupTmpPath}");
|
||||||
|
@ -24,7 +24,7 @@ our @EXPORT = qw(version_get
|
|||||||
lock_file_create lock_file_remove
|
lock_file_create lock_file_remove
|
||||||
ini_save ini_load timestamp_string_get timestamp_file_string_get
|
ini_save ini_load timestamp_string_get timestamp_file_string_get
|
||||||
TRACE DEBUG ERROR ASSERT WARN INFO OFF true false
|
TRACE DEBUG ERROR ASSERT WARN INFO OFF true false
|
||||||
TEST TEST_ENCLOSE TEST_MANIFEST_BUILD);
|
TEST TEST_ENCLOSE TEST_MANIFEST_BUILD TEST_BACKUP_RESUME TEST_BACKUP_NORESUME);
|
||||||
|
|
||||||
# Global constants
|
# Global constants
|
||||||
use constant
|
use constant
|
||||||
@ -65,9 +65,12 @@ $oLogLevelRank{OFF}{rank} = 0;
|
|||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
use constant
|
use constant
|
||||||
{
|
{
|
||||||
TEST => 'TEST',
|
TEST => 'TEST',
|
||||||
TEST_ENCLOSE => 'PgBaCkReStTeSt',
|
TEST_ENCLOSE => 'PgBaCkReStTeSt',
|
||||||
TEST_MANIFEST_BUILD => 'MANIFEST_BUILD'
|
|
||||||
|
TEST_MANIFEST_BUILD => 'MANIFEST_BUILD',
|
||||||
|
TEST_BACKUP_RESUME => 'BACKUP_RESUME',
|
||||||
|
TEST_BACKUP_NORESUME => 'BACKUP_NORESUME',
|
||||||
};
|
};
|
||||||
|
|
||||||
# Test global variables
|
# Test global variables
|
||||||
@ -369,7 +372,7 @@ sub test_set
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Test delay should be between 1 and 600 seconds
|
# Test delay should be between 1 and 600 seconds
|
||||||
if (!($iTestDelay >= 1 && $iTestDelay <= 600))
|
if (!($iTestDelay >= 0 && $iTestDelay <= 600))
|
||||||
{
|
{
|
||||||
confess &log(ERROR, 'test-delay must be between 1 and 600 seconds');
|
confess &log(ERROR, 'test-delay must be between 1 and 600 seconds');
|
||||||
}
|
}
|
||||||
@ -485,7 +488,11 @@ sub log
|
|||||||
if ($bTest && $strLevel eq TEST)
|
if ($bTest && $strLevel eq TEST)
|
||||||
{
|
{
|
||||||
*STDOUT->flush();
|
*STDOUT->flush();
|
||||||
sleep($iTestDelay);
|
|
||||||
|
if ($iTestDelay > 0)
|
||||||
|
{
|
||||||
|
sleep($iTestDelay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1145,9 +1145,20 @@ sub BackRestTestBackup_Test
|
|||||||
|
|
||||||
my $strTmpPath = BackRestTestCommon_BackupPathGet() . "/temp/${strStanza}.tmp";
|
my $strTmpPath = BackRestTestCommon_BackupPathGet() . "/temp/${strStanza}.tmp";
|
||||||
|
|
||||||
BackRestTestCommon_PathCopy(BackRestTestCommon_BackupPathGet() . "/backup/${strStanza}/${strFullBackup}",
|
BackRestTestCommon_PathMove(BackRestTestCommon_BackupPathGet() . "/backup/${strStanza}/${strFullBackup}",
|
||||||
$strTmpPath, $bRemote);
|
$strTmpPath, $bRemote);
|
||||||
|
|
||||||
|
BackRestTestCommon_ExecuteBegin("${strCommand} --type=${strType} --test --test-delay=0", $bRemote);
|
||||||
|
|
||||||
|
if (BackRestTestCommon_ExecuteEnd(TEST_BACKUP_RESUME))
|
||||||
|
{
|
||||||
|
BackRestTestCommon_ExecuteEnd();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
confess &log(ERROR, 'test point ' . TEST_MANIFEST_BUILD . ' was not found');
|
||||||
|
}
|
||||||
|
|
||||||
BackRestTestCommon_Execute("${strCommand} --type=${strType}", $bRemote);
|
BackRestTestCommon_Execute("${strCommand} --type=${strType}", $bRemote);
|
||||||
|
|
||||||
$oManifest{backup}{type} = $strType;
|
$oManifest{backup}{type} = $strType;
|
||||||
@ -1193,7 +1204,64 @@ sub BackRestTestBackup_Test
|
|||||||
|
|
||||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
||||||
|
|
||||||
# Perform second incr backup
|
# Resume Incr Backup
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup);
|
||||||
|
|
||||||
|
$strType = 'incr';
|
||||||
|
&log(INFO, " ${strType} backup resume");
|
||||||
|
|
||||||
|
$strTmpPath = BackRestTestCommon_BackupPathGet() . "/temp/${strStanza}.tmp";
|
||||||
|
|
||||||
|
BackRestTestCommon_PathMove(BackRestTestCommon_BackupPathGet() . "/backup/${strStanza}/${strBackup}",
|
||||||
|
$strTmpPath, $bRemote);
|
||||||
|
|
||||||
|
BackRestTestCommon_ExecuteBegin("${strCommand} --type=${strType} --test --test-delay=0", $bRemote);
|
||||||
|
|
||||||
|
if (BackRestTestCommon_ExecuteEnd(TEST_BACKUP_RESUME))
|
||||||
|
{
|
||||||
|
BackRestTestCommon_ExecuteEnd();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
confess &log(ERROR, 'test point ' . TEST_BACKUP_RESUME . ' was not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$oManifest{backup}{type} = $strType;
|
||||||
|
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||||
|
|
||||||
|
BackRestTestBackup_CompareBackup($oFile, $bRemote, $strBackup, \%oManifest);
|
||||||
|
|
||||||
|
# Resume Diff Backup
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup);
|
||||||
|
|
||||||
|
$strType = 'diff';
|
||||||
|
&log(INFO, " ${strType} backup resume (fail)");
|
||||||
|
|
||||||
|
$strTmpPath = BackRestTestCommon_BackupPathGet() . "/temp/${strStanza}.tmp";
|
||||||
|
|
||||||
|
BackRestTestCommon_PathMove(BackRestTestCommon_BackupPathGet() . "/backup/${strStanza}/${strBackup}",
|
||||||
|
$strTmpPath, $bRemote);
|
||||||
|
|
||||||
|
BackRestTestCommon_ExecuteBegin("${strCommand} --type=${strType} --test --test-delay=0", $bRemote);
|
||||||
|
|
||||||
|
if (BackRestTestCommon_ExecuteEnd(TEST_BACKUP_NORESUME))
|
||||||
|
{
|
||||||
|
BackRestTestCommon_ExecuteEnd();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
confess &log(ERROR, 'test point ' . TEST_BACKUP_NORESUME . ' was not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$oManifest{backup}{type} = $strType;
|
||||||
|
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||||
|
|
||||||
|
BackRestTestBackup_CompareBackup($oFile, $bRemote, $strBackup, \%oManifest);
|
||||||
|
|
||||||
|
# Incr Backup
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
||||||
|
|
||||||
$strType = 'incr';
|
$strType = 'incr';
|
||||||
@ -1213,7 +1281,7 @@ sub BackRestTestBackup_Test
|
|||||||
$oManifest{backup}{type} = $strType;
|
$oManifest{backup}{type} = $strType;
|
||||||
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
$strBackup = BackRestTestBackup_LastBackup($oFile);
|
||||||
|
|
||||||
BackRestTestBackup_CompareBackup($oFile, $bRemote, BackRestTestBackup_LastBackup($oFile), \%oManifest);
|
BackRestTestBackup_CompareBackup($oFile, $bRemote, $strBackup, \%oManifest);
|
||||||
|
|
||||||
# Perform third incr backup
|
# Perform third incr backup
|
||||||
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
||||||
|
@ -28,7 +28,7 @@ use Exporter qw(import);
|
|||||||
our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin BackRestTestCommon_ExecuteEnd
|
our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin BackRestTestCommon_ExecuteEnd
|
||||||
BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest
|
BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest
|
||||||
BackRestTestCommon_PathCreate BackRestTestCommon_PathMode BackRestTestCommon_PathRemove
|
BackRestTestCommon_PathCreate BackRestTestCommon_PathMode BackRestTestCommon_PathRemove
|
||||||
BackRestTestCommon_FileCreate BackRestTestCommon_FileRemove BackRestTestCommon_PathCopy
|
BackRestTestCommon_FileCreate BackRestTestCommon_FileRemove BackRestTestCommon_PathCopy BackRestTestCommon_PathMove
|
||||||
BackRestTestCommon_ConfigCreate BackRestTestCommon_Run BackRestTestCommon_Cleanup
|
BackRestTestCommon_ConfigCreate BackRestTestCommon_Run BackRestTestCommon_Cleanup
|
||||||
BackRestTestCommon_PgSqlBinPathGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet
|
BackRestTestCommon_PgSqlBinPathGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet
|
||||||
BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet
|
BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet
|
||||||
@ -294,6 +294,22 @@ sub BackRestTestCommon_PathCopy
|
|||||||
BackRestTestCommon_Execute("cp -rp ${strSourcePath} ${strDestinationPath}", $bRemote, $bSuppressError);
|
BackRestTestCommon_Execute("cp -rp ${strSourcePath} ${strDestinationPath}", $bRemote, $bSuppressError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
####################################################################################################################################
|
||||||
|
# BackRestTestCommon_PathMove
|
||||||
|
#
|
||||||
|
# Copy a path.
|
||||||
|
####################################################################################################################################
|
||||||
|
sub BackRestTestCommon_PathMove
|
||||||
|
{
|
||||||
|
my $strSourcePath = shift;
|
||||||
|
my $strDestinationPath = shift;
|
||||||
|
my $bRemote = shift;
|
||||||
|
my $bSuppressError = shift;
|
||||||
|
|
||||||
|
BackRestTestCommon_PathCopy($strSourcePath, $strDestinationPath, $bRemote, $bSuppressError);
|
||||||
|
BackRestTestCommon_PathRemove($strSourcePath, $bRemote, $bSuppressError);
|
||||||
|
}
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
# BackRestTestCommon_FileCreate
|
# BackRestTestCommon_FileCreate
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user