mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Added tests for all --delta --force combinations.
Added error check for postmaster running. Added error check for path not empty.
This commit is contained in:
parent
16dd271794
commit
499d6c8422
@ -223,20 +223,6 @@ sub config_load
|
||||
|
||||
param_valid();
|
||||
|
||||
# Set the backup type
|
||||
# if ($strOperation ne OP_BACKUP)
|
||||
# {
|
||||
# if (!defined(param_get(PARAM_TYPE)))
|
||||
# {
|
||||
# param_set(PARAM_TYPE, BACKUP_TYPE_INCR);
|
||||
# }
|
||||
# elsif (param_get(PARAM_TYPE) ne BACKUP_TYPE_FULL && param_get(PARAM_TYPE) ne BACKUP_TYPE_DIFF &&
|
||||
# param_get(PARAM_TYPE) ne BACKUP_TYPE_INCR)
|
||||
# {
|
||||
# confess &log(ERROR, 'backup type must be full, diff (differential), incr (incremental)');
|
||||
# }
|
||||
# }
|
||||
|
||||
# # Validate thread parameter
|
||||
# if (defined(param_get(PARAM_THREAD)) && !(param_get(PARAM_THREAD) >= 1))
|
||||
# {
|
||||
|
@ -12,7 +12,7 @@ use Carp;
|
||||
# Exports
|
||||
####################################################################################################################################
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw(ERROR_CHECKSUM ERROR_PARAM ERROR_RESTORE_PATH_NOT_EMPTY);
|
||||
our @EXPORT = qw(ERROR_CHECKSUM ERROR_PARAM ERROR_POSTMASTER_RUNNING ERROR_RESTORE_PATH_NOT_EMPTY);
|
||||
|
||||
####################################################################################################################################
|
||||
# Exception Codes
|
||||
@ -21,7 +21,8 @@ use constant
|
||||
{
|
||||
ERROR_CHECKSUM => 100,
|
||||
ERROR_PARAM => 101,
|
||||
ERROR_RESTORE_PATH_NOT_EMPTY => 102
|
||||
ERROR_RESTORE_PATH_NOT_EMPTY => 102,
|
||||
ERROR_POSTMASTER_RUNNING => 103
|
||||
};
|
||||
|
||||
####################################################################################################################################
|
||||
|
@ -548,7 +548,7 @@ sub restore
|
||||
# Make sure that Postgres is not running
|
||||
if ($self->{oFile}->exists(PATH_DB_ABSOLUTE, $self->{strDbClusterPath} . '/' . FILE_POSTMASTER_PID))
|
||||
{
|
||||
confess &log(ERROR, 'unable to restore while Postgres is running');
|
||||
confess &log(ERROR, 'unable to restore while Postgres is running', ERROR_POSTMASTER_RUNNING);
|
||||
}
|
||||
|
||||
# Log the backup set to restore
|
||||
|
@ -967,13 +967,16 @@ sub BackRestTestBackup_Restore
|
||||
$bDelta = defined($bDelta) ? $bDelta : false;
|
||||
$bForce = defined($bForce) ? $bForce : false;
|
||||
|
||||
&log(INFO, ' ' . ($bDelta ? 'delta ' : '') . ($bForce ? 'force ' : '') .
|
||||
($strBackup ne 'latest' ? "backup '${strBackup}' " : '') .
|
||||
($strType ? "type '${strType}' " : '') .
|
||||
($strTarget ? "target '${strTarget}' " : '') .
|
||||
(defined($bTargetExclusive) && $bTargetExclusive ? "exclusive " : '') .
|
||||
(defined($oRemapHashRef) ? 'remap ' : '') . 'restore' .
|
||||
(defined($strComment) ? " (${strComment})" : ''));
|
||||
&log(INFO, ' restore' .
|
||||
($bDelta ? ' delta' : '') .
|
||||
($bForce ? ', force' : '') .
|
||||
($strBackup ne 'latest' ? ", backup '${strBackup}'" : '') .
|
||||
($strType ? ", type '${strType}' " : '') .
|
||||
($strTarget ? ", target '${strTarget}'" : '') .
|
||||
(defined($bTargetExclusive) && $bTargetExclusive ? ', exclusive' : '') .
|
||||
(defined($oRemapHashRef) ? ', remap' : '') .
|
||||
(defined($iExpectedExitStatus) ? ", expect exit ${iExpectedExitStatus}" : '') .
|
||||
(defined($strComment) ? " (${strComment})" : ''));
|
||||
|
||||
if (defined($oRemapHashRef))
|
||||
{
|
||||
@ -1654,7 +1657,7 @@ sub BackRestTestBackup_Test
|
||||
my $strType;
|
||||
my $bSynthetic = false;
|
||||
my $bTestPoint = false;
|
||||
my $fTestDelay = .1;
|
||||
my $fTestDelay = .25;
|
||||
my $bDelta = true;
|
||||
my $bForce = false;
|
||||
|
||||
@ -1695,6 +1698,8 @@ sub BackRestTestBackup_Test
|
||||
$strType = BACKUP_TYPE_INCR;
|
||||
$bTestPoint = true;
|
||||
|
||||
BackRestTestBackup_PgExecute("create table test_remove (id int)", false);
|
||||
BackRestTestBackup_PgSwitchXlog();
|
||||
BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false);
|
||||
BackRestTestBackup_PgSwitchXlog();
|
||||
|
||||
@ -1702,6 +1707,8 @@ sub BackRestTestBackup_Test
|
||||
$fTestDelay);
|
||||
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD);
|
||||
|
||||
BackRestTestBackup_PgExecute("drop table test_remove", false);
|
||||
BackRestTestBackup_PgSwitchXlog();
|
||||
BackRestTestBackup_PgExecute("update test set message = '$strIncrMessage'", false);
|
||||
|
||||
my $strIncrBackup = BackRestTestBackup_BackupEnd($strType, $oFile, $bRemote, undef, undef, $bSynthetic);
|
||||
@ -1727,14 +1734,30 @@ sub BackRestTestBackup_Test
|
||||
# Restore (type = default)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_DEFAULT;
|
||||
$bDelta = false;
|
||||
$bForce = false;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
# Expect failure because postmaster.pid exists
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, undef, undef, undef, undef, undef,
|
||||
'restore to full');
|
||||
'postmaster running', ERROR_POSTMASTER_RUNNING);
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
# Expect failure because db path is not empty
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, undef, undef, undef, undef, undef,
|
||||
'path not empty', ERROR_RESTORE_PATH_NOT_EMPTY);
|
||||
|
||||
# Drop and recreate db path
|
||||
BackRestTestCommon_PathRemove(BackRestTestCommon_DbCommonPathGet());
|
||||
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet());
|
||||
|
||||
# Now the restore should work
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, undef, undef, undef, undef, undef);
|
||||
|
||||
BackRestTestBackup_ClusterStart();
|
||||
|
||||
@ -1749,6 +1772,8 @@ sub BackRestTestBackup_Test
|
||||
# Restore (restore type = xid, inclusive)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_XID;
|
||||
$bDelta = false;
|
||||
$bForce = true;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
@ -1771,6 +1796,8 @@ sub BackRestTestBackup_Test
|
||||
# exact commit time of a transaction.
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_TIME;
|
||||
$bDelta = true;
|
||||
$bForce = false;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
@ -1792,6 +1819,8 @@ sub BackRestTestBackup_Test
|
||||
# Restore (restore type = xid, exclusive)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_XID;
|
||||
$bDelta = true;
|
||||
$bForce = false;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
@ -1813,6 +1842,8 @@ sub BackRestTestBackup_Test
|
||||
# Restore (restore type = name)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_NAME;
|
||||
$bDelta = true;
|
||||
$bForce = true;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user