You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-17 01:12:23 +02:00
Timeline unit tests are working.
Options from config file are being written to recovery.conf. Fixed issue with .history files not being picked up by archive-xfer.
This commit is contained in:
@ -459,7 +459,7 @@ if (operation_get() eq OP_RESTORE)
|
||||
param_get(PARAM_TARGET_EXCLUSIVE),
|
||||
param_get(PARAM_TARGET_RESUME),
|
||||
param_get(PARAM_TARGET_TIMELINE),
|
||||
config_section_load(CONFIG_SECTION_RECOVERY),
|
||||
config_section_load(CONFIG_SECTION_RECOVERY_OPTION),
|
||||
param_get(PARAM_STANZA),
|
||||
$0,
|
||||
param_get(PARAM_CONFIG)
|
||||
|
@ -362,7 +362,7 @@ sub archive_xfer
|
||||
|
||||
foreach my $strFile (sort(keys $oManifestHash{name}))
|
||||
{
|
||||
if ($strFile =~ /^[0-F]{16}\/[0-F]{24}.*/)
|
||||
if ($strFile =~ /^[0-F]{16}\/[0-F]{24}.*/ || $strFile =~ /^[0-F]{8}\.history$/)
|
||||
{
|
||||
push @stryFile, $strFile;
|
||||
|
||||
|
@ -36,8 +36,8 @@ our @EXPORT = qw(config_load config_key_load config_section_load operation_get o
|
||||
PARAM_VERSION PARAM_HELP PARAM_TEST PARAM_TEST_DELAY PARAM_TEST_NO_FORK
|
||||
|
||||
CONFIG_SECTION_COMMAND CONFIG_SECTION_COMMAND_OPTION CONFIG_SECTION_LOG CONFIG_SECTION_BACKUP
|
||||
CONFIG_SECTION_RESTORE CONFIG_SECTION_RECOVERY CONFIG_SECTION_TABLESPACE_MAP CONFIG_SECTION_ARCHIVE
|
||||
CONFIG_SECTION_RETENTION CONFIG_SECTION_STANZA
|
||||
CONFIG_SECTION_RESTORE CONFIG_SECTION_RECOVERY CONFIG_SECTION_RECOVERY_OPTION CONFIG_SECTION_TABLESPACE_MAP
|
||||
CONFIG_SECTION_ARCHIVE CONFIG_SECTION_RETENTION CONFIG_SECTION_STANZA
|
||||
|
||||
CONFIG_KEY_USER CONFIG_KEY_HOST CONFIG_KEY_PATH
|
||||
|
||||
@ -49,7 +49,10 @@ our @EXPORT = qw(config_load config_key_load config_section_load operation_get o
|
||||
CONFIG_KEY_COMPRESS CONFIG_KEY_CHECKSUM CONFIG_KEY_PSQL CONFIG_KEY_REMOTE
|
||||
|
||||
CONFIG_KEY_FULL_RETENTION CONFIG_KEY_DIFFERENTIAL_RETENTION CONFIG_KEY_ARCHIVE_RETENTION_TYPE
|
||||
CONFIG_KEY_ARCHIVE_RETENTION);
|
||||
CONFIG_KEY_ARCHIVE_RETENTION
|
||||
|
||||
CONFIG_KEY_STANDBY_MODE CONFIG_KEY_PRIMARY_CONNINFO CONFIG_KEY_TRIGGER_FILE CONFIG_KEY_RESTORE_COMMAND
|
||||
CONFIG_KEY_ARCHIVE_CLEANUP_COMMAND CONFIG_KEY_RECOVERY_END_COMMAND);
|
||||
|
||||
####################################################################################################################################
|
||||
# File/path constants
|
||||
@ -135,6 +138,7 @@ use constant
|
||||
CONFIG_SECTION_BACKUP => 'backup',
|
||||
CONFIG_SECTION_RESTORE => 'restore',
|
||||
CONFIG_SECTION_RECOVERY => 'recovery',
|
||||
CONFIG_SECTION_RECOVERY_OPTION => 'recovery:option',
|
||||
CONFIG_SECTION_TABLESPACE_MAP => 'tablespace:map',
|
||||
CONFIG_SECTION_ARCHIVE => 'archive',
|
||||
CONFIG_SECTION_RETENTION => 'retention',
|
||||
@ -163,7 +167,14 @@ use constant
|
||||
CONFIG_KEY_FULL_RETENTION => 'full-retention',
|
||||
CONFIG_KEY_DIFFERENTIAL_RETENTION => 'differential-retention',
|
||||
CONFIG_KEY_ARCHIVE_RETENTION_TYPE => 'archive-retention-type',
|
||||
CONFIG_KEY_ARCHIVE_RETENTION => 'archive-retention'
|
||||
CONFIG_KEY_ARCHIVE_RETENTION => 'archive-retention',
|
||||
|
||||
CONFIG_KEY_STANDBY_MODE => 'standby-mode',
|
||||
CONFIG_KEY_PRIMARY_CONNINFO => 'primary-conninfo',
|
||||
CONFIG_KEY_TRIGGER_FILE => 'trigger-file',
|
||||
CONFIG_KEY_RESTORE_COMMAND => 'restore-command',
|
||||
CONFIG_KEY_ARCHIVE_CLEANUP_COMMAND => 'archive-cleanup-command',
|
||||
CONFIG_KEY_RECOVERY_END_COMMAND => 'recovery-end-command'
|
||||
};
|
||||
|
||||
####################################################################################################################################
|
||||
@ -221,6 +232,7 @@ sub config_load
|
||||
# Get and validate the operation
|
||||
$strOperation = $ARGV[0];
|
||||
|
||||
# Validate params
|
||||
param_valid();
|
||||
|
||||
# # Validate thread parameter
|
||||
@ -255,6 +267,9 @@ sub config_load
|
||||
log_level_set(uc(config_key_load(CONFIG_SECTION_LOG, CONFIG_KEY_LEVEL_FILE, true, INFO)),
|
||||
uc(config_key_load(CONFIG_SECTION_LOG, CONFIG_KEY_LEVEL_CONSOLE, true, ERROR)));
|
||||
|
||||
# Validate config
|
||||
config_valid();
|
||||
|
||||
# Set test parameters
|
||||
test_set(param_get(PARAM_TEST), param_get(PARAM_TEST_DELAY));
|
||||
}
|
||||
@ -330,6 +345,42 @@ sub config_key_load
|
||||
return $strValue;
|
||||
}
|
||||
|
||||
|
||||
####################################################################################################################################
|
||||
# CONFIG_VALID
|
||||
#
|
||||
# Make sure the configuration is valid.
|
||||
####################################################################################################################################
|
||||
sub config_valid
|
||||
{
|
||||
# Local variables
|
||||
my $strSection;
|
||||
my $oSectionHashRef;
|
||||
|
||||
# Check recovery:option section
|
||||
$strSection = param_get(PARAM_STANZA) . ':' . CONFIG_SECTION_RECOVERY_OPTION;
|
||||
$oSectionHashRef = $oConfig{$strSection};
|
||||
|
||||
if (defined($oSectionHashRef) && keys($oSectionHashRef) != 0)
|
||||
{
|
||||
foreach my $strKey (sort(keys($oSectionHashRef)))
|
||||
{
|
||||
if ($strKey ne CONFIG_KEY_STANDBY_MODE &&
|
||||
$strKey ne CONFIG_KEY_PRIMARY_CONNINFO &&
|
||||
$strKey ne CONFIG_KEY_TRIGGER_FILE &&
|
||||
$strKey ne CONFIG_KEY_RESTORE_COMMAND &&
|
||||
$strKey ne CONFIG_KEY_ARCHIVE_CLEANUP_COMMAND &&
|
||||
$strKey ne CONFIG_KEY_RECOVERY_END_COMMAND)
|
||||
{
|
||||
confess &log(ERROR, "invalid key '${strKey}' for section '${strSection}', must be: '" .
|
||||
CONFIG_KEY_STANDBY_MODE . "', '" . CONFIG_KEY_PRIMARY_CONNINFO . "', '" .
|
||||
CONFIG_KEY_TRIGGER_FILE . "', '" . CONFIG_KEY_RESTORE_COMMAND . "', '" .
|
||||
CONFIG_KEY_ARCHIVE_CLEANUP_COMMAND . "', '" . CONFIG_KEY_RECOVERY_END_COMMAND . "'", ERROR_CONFIG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# PARAM_VALID
|
||||
#
|
||||
@ -429,8 +480,8 @@ sub param_valid
|
||||
confess &log(ERROR, PARAM_TARGET . ' is only required ' . $strTargetMessage, ERROR_PARAM);
|
||||
}
|
||||
|
||||
# Check target-resume, target-timeline parameters - can only be used when target is specified
|
||||
if ((defined(param_get(PARAM_TARGET_RESUME)) || defined(param_get(PARAM_TARGET_TIMELINE))) && !defined($strTarget))
|
||||
# Check target-resume - can only be used when target is specified
|
||||
if (defined(param_get(PARAM_TARGET_RESUME)) && !defined($strTarget))
|
||||
{
|
||||
confess &log(ERROR, PARAM_TARGET_RESUME . ' and ' . PARAM_TARGET_TIMELINE .
|
||||
' are only valid when target is specified', ERROR_PARAM);
|
||||
|
@ -12,7 +12,7 @@ use Carp;
|
||||
# Exports
|
||||
####################################################################################################################################
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw(ERROR_CHECKSUM ERROR_PARAM ERROR_POSTMASTER_RUNNING ERROR_RESTORE_PATH_NOT_EMPTY);
|
||||
our @EXPORT = qw(ERROR_CHECKSUM ERROR_CONFIG ERROR_PARAM ERROR_POSTMASTER_RUNNING ERROR_RESTORE_PATH_NOT_EMPTY);
|
||||
|
||||
####################################################################################################################################
|
||||
# Exception Codes
|
||||
@ -20,9 +20,10 @@ our @EXPORT = qw(ERROR_CHECKSUM ERROR_PARAM ERROR_POSTMASTER_RUNNING ERROR_RESTO
|
||||
use constant
|
||||
{
|
||||
ERROR_CHECKSUM => 100,
|
||||
ERROR_PARAM => 101,
|
||||
ERROR_RESTORE_PATH_NOT_EMPTY => 102,
|
||||
ERROR_POSTMASTER_RUNNING => 103
|
||||
ERROR_CONFIG => 101,
|
||||
ERROR_PARAM => 102,
|
||||
ERROR_RESTORE_PATH_NOT_EMPTY => 103,
|
||||
ERROR_POSTMASTER_RUNNING => 104
|
||||
};
|
||||
|
||||
####################################################################################################################################
|
||||
|
@ -38,7 +38,7 @@ sub new
|
||||
my $strTarget = shift; # Recovery target
|
||||
my $bTargetExclusive = shift; # Target exlusive option
|
||||
my $bTargetResume = shift; # Target resume option
|
||||
my $bTargetTimeline = shift; # Target timeline option
|
||||
my $strTargetTimeline = shift; # Target timeline option
|
||||
my $oRecoveryRef = shift; # Other recovery options
|
||||
my $strStanza = shift; # Restore stanza
|
||||
my $strBackRestBin = shift; # Absolute backrest filename
|
||||
@ -59,7 +59,7 @@ sub new
|
||||
$self->{strTarget} = $strTarget;
|
||||
$self->{bTargetExclusive} = $bTargetExclusive;
|
||||
$self->{bTargetResume} = $bTargetResume;
|
||||
$self->{bTargetTimeline} = $bTargetTimeline;
|
||||
$self->{strTargetTimeline} = $strTargetTimeline;
|
||||
$self->{oRecoveryRef} = $oRecoveryRef;
|
||||
$self->{strStanza} = $strStanza;
|
||||
$self->{strBackRestBin} = $strBackRestBin;
|
||||
@ -478,19 +478,31 @@ sub recovery
|
||||
|
||||
# Write the recovery options from pg_backrest.conf
|
||||
my $strRecovery = '';
|
||||
my $bRestoreCommandOverride = false;
|
||||
|
||||
if (defined($self->{strRecoveryRef}))
|
||||
if (defined($self->{oRecoveryRef}))
|
||||
{
|
||||
foreach my $strKey (sort(keys $self->{strRecoveryRef}))
|
||||
foreach my $strKey (sort(keys $self->{oRecoveryRef}))
|
||||
{
|
||||
$strRecovery .= ${$self->{strRecoveryRef}}{$strKey} . "\n";
|
||||
my $strPgKey = $strKey;
|
||||
$strPgKey =~ s/\-/\_/g;
|
||||
|
||||
if ($strKey eq CONFIG_KEY_RESTORE_COMMAND)
|
||||
{
|
||||
$bRestoreCommandOverride = true;
|
||||
}
|
||||
|
||||
$strRecovery .= "$strPgKey = '${$self->{oRecoveryRef}}{$strKey}'\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Write the restore command
|
||||
$strRecovery .= "restore_command = '$self->{strBackRestBin} --stanza=$self->{strStanza}" .
|
||||
(defined($self->{strConfigFile}) ? " --config=$self->{strConfigFile}" : '') .
|
||||
" archive-get %f \"%p\"'\n";
|
||||
if (!$bRestoreCommandOverride)
|
||||
{
|
||||
$strRecovery .= "restore_command = '$self->{strBackRestBin} --stanza=$self->{strStanza}" .
|
||||
(defined($self->{strConfigFile}) ? " --config=$self->{strConfigFile}" : '') .
|
||||
" archive-get %f \"%p\"'\n";
|
||||
}
|
||||
|
||||
# If RECOVERY_TYPE_DEFAULT do not write target options
|
||||
if ($self->{strType} ne RECOVERY_TYPE_DEFAULT)
|
||||
@ -503,24 +515,18 @@ sub recovery
|
||||
{
|
||||
$strRecovery .= "recovery_target_inclusive = false\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Write recovery_target_inclusive
|
||||
if ($self->{bTargetExclusive})
|
||||
{
|
||||
$strRecovery .= "recovery_target_inclusive = false\n";
|
||||
}
|
||||
# Write pause_at_recovery_target
|
||||
if ($self->{bTargetResume})
|
||||
{
|
||||
$strRecovery .= "pause_at_recovery_target = false\n";
|
||||
}
|
||||
|
||||
# Write pause_at_recovery_target
|
||||
if ($self->{bTargetResult})
|
||||
{
|
||||
$strRecovery .= "pause_at_recovery_target = false\n";
|
||||
}
|
||||
|
||||
# Write recovery_target_timeline
|
||||
if (defined($self->{strTargetTimeline}))
|
||||
{
|
||||
$strRecovery .= "recovery_target_timeline = $self->{strTargetTimeline}\n";
|
||||
}
|
||||
# Write recovery_target_timeline
|
||||
if (defined($self->{strTargetTimeline}))
|
||||
{
|
||||
$strRecovery .= "recovery_target_timeline = $self->{strTargetTimeline}\n";
|
||||
}
|
||||
|
||||
# Write recovery.conf
|
||||
|
@ -151,6 +151,33 @@ sub BackRestTestBackup_PgSelectOne
|
||||
return (BackRestTestBackup_PgSelect($strSql))[0];
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestBackup_PgSelectOneTest
|
||||
####################################################################################################################################
|
||||
sub BackRestTestBackup_PgSelectOneTest
|
||||
{
|
||||
my $strSql = shift;
|
||||
my $strExpectedValue = shift;
|
||||
my $iTimeout = shift;
|
||||
|
||||
my $lStartTime = time();
|
||||
my $strActualValue;
|
||||
|
||||
do
|
||||
{
|
||||
$strActualValue = BackRestTestBackup_PgSelectOne($strSql);
|
||||
|
||||
if (defined($strActualValue) && $strActualValue eq $strExpectedValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (defined($iTimeout) && (time() - $lStartTime) <= $iTimeout);
|
||||
|
||||
confess "expected value '${strExpectedValue}' from '${strSql}' but actual was '" .
|
||||
(defined($strActualValue) ? $strActualValue : '[undef]') . "'";
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestBackup_ClusterStop
|
||||
####################################################################################################################################
|
||||
@ -181,10 +208,12 @@ sub BackRestTestBackup_ClusterStart
|
||||
{
|
||||
my $strPath = shift;
|
||||
my $iPort = shift;
|
||||
my $bHotStandby = shift;
|
||||
|
||||
# Set default
|
||||
$iPort = defined($iPort) ? $iPort : BackRestTestCommon_DbPortGet();
|
||||
$strPath = defined($strPath) ? $strPath : BackRestTestCommon_DbCommonPathGet();
|
||||
$bHotStandby = defined($bHotStandby) ? $bHotStandby : false;
|
||||
|
||||
# Make sure postgres is not running
|
||||
if (-e $strPath . '/postmaster.pid')
|
||||
@ -197,9 +226,11 @@ sub BackRestTestBackup_ClusterStart
|
||||
' --config=' . BackRestTestCommon_DbPathGet() . '/pg_backrest.conf archive-push %p';
|
||||
|
||||
# Start the cluster
|
||||
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/pg_ctl start -o \"-c port=${iPort} -c " .
|
||||
"checkpoint_segments=1 -c wal_level=archive -c archive_mode=on -c archive_command='${strArchive}' " .
|
||||
"-c unix_socket_directories='" . BackRestTestCommon_DbPathGet() . "'\" " .
|
||||
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/pg_ctl start -o \"-c port=${iPort}" .
|
||||
' -c checkpoint_segments=1' .
|
||||
" -c wal_level=hot_standby -c archive_mode=on -c archive_command='${strArchive}'" .
|
||||
($bHotStandby ? ' -c hot_standby=on' : '') .
|
||||
" -c unix_socket_directories='" . BackRestTestCommon_DbPathGet() . "'\" " .
|
||||
"-D ${strPath} -l ${strPath}/postgresql.log -w -s");
|
||||
|
||||
# Connect user session
|
||||
@ -978,7 +1009,9 @@ sub BackRestTestBackup_Restore
|
||||
($strBackup ne 'latest' ? ", backup '${strBackup}'" : '') .
|
||||
($strType ? ", type '${strType}' " : '') .
|
||||
($strTarget ? ", target '${strTarget}'" : '') .
|
||||
($strTargetTimeline ? ", timeline '${strTargetTimeline}'" : '') .
|
||||
(defined($bTargetExclusive) && $bTargetExclusive ? ', exclusive' : '') .
|
||||
(defined($bTargetResume) && $bTargetResume ? ', resume' : '') .
|
||||
(defined($oRemapHashRef) ? ', remap' : '') .
|
||||
(defined($iExpectedExitStatus) ? ", expect exit ${iExpectedExitStatus}" : '') .
|
||||
(defined($strComment) ? " (${strComment})" : ''));
|
||||
@ -988,6 +1021,11 @@ sub BackRestTestBackup_Restore
|
||||
BackRestTestCommon_ConfigRemap($oRemapHashRef, $oExpectedManifestRef, $bRemote);
|
||||
}
|
||||
|
||||
if (defined($oRecoveryHashRef))
|
||||
{
|
||||
BackRestTestCommon_ConfigRecovery($oRecoveryHashRef, $bRemote);
|
||||
}
|
||||
|
||||
# Create the backup command
|
||||
BackRestTestCommon_Execute(BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() .
|
||||
'/pg_backrest.conf' . (defined($bDelta) && $bDelta ? ' --delta' : '') .
|
||||
@ -995,7 +1033,9 @@ sub BackRestTestBackup_Restore
|
||||
($strBackup ne 'latest' ? " --set=${strBackup}" : '') .
|
||||
(defined($strType) && $strType ne RECOVERY_TYPE_DEFAULT ? " --type=${strType}" : '') .
|
||||
(defined($strTarget) ? " --target=\"${strTarget}\"" : '') .
|
||||
(defined($strTargetTimeline) ? " --target-timeline=\"${strTargetTimeline}\"" : '') .
|
||||
(defined($bTargetExclusive) && $bTargetExclusive ? " --target-exclusive" : '') .
|
||||
(defined($bTargetResume) && $bTargetResume ? " --target-resume" : '') .
|
||||
" --stanza=${strStanza} restore",
|
||||
undef, undef, undef, $iExpectedExitStatus);
|
||||
}
|
||||
@ -1662,13 +1702,22 @@ sub BackRestTestBackup_Test
|
||||
undef); # compress-async
|
||||
}
|
||||
|
||||
# Backup parameters
|
||||
my $strType;
|
||||
# Static backup parameters
|
||||
my $bSynthetic = false;
|
||||
my $bTestPoint = false;
|
||||
my $fTestDelay = .25;
|
||||
|
||||
# Variable backup parameters
|
||||
my $bDelta = true;
|
||||
my $bForce = false;
|
||||
my $strType = undef;
|
||||
my $strTarget = undef;
|
||||
my $bTargetExclusive = false;
|
||||
my $bTargetResume = false;
|
||||
my $strTargetTimeline = undef;
|
||||
my $oRecoveryHashRef = undef;
|
||||
my $strTestPoint = undef;
|
||||
my $strComment = undef;
|
||||
my $iExpectedExitStatus = undef;
|
||||
|
||||
# Restore test string
|
||||
my $strDefaultMessage = 'default';
|
||||
@ -1677,19 +1726,21 @@ sub BackRestTestBackup_Test
|
||||
my $strTimeMessage = 'time';
|
||||
my $strXidMessage = 'xid';
|
||||
my $strNameMessage = 'name';
|
||||
my $strTimelineMessage = 'timeline3';
|
||||
|
||||
# Full backup
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = BACKUP_TYPE_FULL;
|
||||
$bTestPoint = true;
|
||||
$strTestPoint = TEST_MANIFEST_BUILD;
|
||||
$strComment = 'insert during backup';
|
||||
|
||||
BackRestTestBackup_PgExecute("create table test (message text not null)");
|
||||
BackRestTestBackup_PgSwitchXlog();
|
||||
BackRestTestBackup_PgExecute("insert into test values ('$strDefaultMessage')");
|
||||
|
||||
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "insert during backup", $bSynthetic, $bTestPoint,
|
||||
$fTestDelay);
|
||||
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD);
|
||||
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, $bSynthetic,
|
||||
defined($strTestPoint), $fTestDelay);
|
||||
BackRestTestCommon_ExecuteEnd($strTestPoint);
|
||||
|
||||
BackRestTestBackup_PgExecute("update test set message = '$strFullMessage'", false);
|
||||
|
||||
@ -1705,16 +1756,17 @@ sub BackRestTestBackup_Test
|
||||
# Incr backup
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = BACKUP_TYPE_INCR;
|
||||
$bTestPoint = true;
|
||||
$strTestPoint = TEST_MANIFEST_BUILD;
|
||||
$strComment = 'update during backup';
|
||||
|
||||
BackRestTestBackup_PgExecute("create table test_remove (id int)", false);
|
||||
BackRestTestBackup_PgSwitchXlog();
|
||||
BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false);
|
||||
BackRestTestBackup_PgSwitchXlog();
|
||||
|
||||
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "update during backup", $bSynthetic, $bTestPoint,
|
||||
$fTestDelay);
|
||||
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD);
|
||||
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, $bSynthetic,
|
||||
defined($strTestPoint), $fTestDelay);
|
||||
BackRestTestCommon_ExecuteEnd($strTestPoint);
|
||||
|
||||
BackRestTestBackup_PgExecute("drop table test_remove", false);
|
||||
BackRestTestBackup_PgSwitchXlog();
|
||||
@ -1742,134 +1794,175 @@ sub BackRestTestBackup_Test
|
||||
|
||||
# Restore (type = default)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_DEFAULT;
|
||||
$bDelta = false;
|
||||
$bForce = false;
|
||||
$strType = RECOVERY_TYPE_DEFAULT;
|
||||
$strTarget = undef;
|
||||
$bTargetExclusive = undef;
|
||||
$bTargetResume = undef;
|
||||
$strTargetTimeline = undef;
|
||||
$oRecoveryHashRef = undef;
|
||||
$strComment = undef;
|
||||
$iExpectedExitStatus = undef;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
# Expect failure because postmaster.pid exists
|
||||
$strComment = 'postmaster running';
|
||||
$iExpectedExitStatus = ERROR_POSTMASTER_RUNNING;
|
||||
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, undef, undef, undef, undef, undef,
|
||||
'postmaster running', ERROR_POSTMASTER_RUNNING);
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
# Expect failure because db path is not empty
|
||||
$strComment = 'path not empty';
|
||||
$iExpectedExitStatus = ERROR_RESTORE_PATH_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);
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
# Drop and recreate db path
|
||||
BackRestTestCommon_PathRemove(BackRestTestCommon_DbCommonPathGet());
|
||||
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet());
|
||||
|
||||
# Now the restore should work
|
||||
$strComment = undef;
|
||||
$iExpectedExitStatus = undef;
|
||||
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, undef, undef, undef, undef, undef);
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
BackRestTestBackup_ClusterStart();
|
||||
|
||||
my $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
|
||||
my $strMessageExpected = $strNameMessage;
|
||||
|
||||
if ($strMessageActual ne $strMessageExpected)
|
||||
{
|
||||
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
|
||||
}
|
||||
BackRestTestBackup_PgSelectOneTest('select message from test', $strNameMessage);
|
||||
|
||||
# Restore (restore type = xid, inclusive)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_XID;
|
||||
$bDelta = false;
|
||||
$bForce = true;
|
||||
$strType = RECOVERY_TYPE_XID;
|
||||
$strTarget = $strXidTarget;
|
||||
$bTargetExclusive = undef;
|
||||
$bTargetResume = true;
|
||||
$strTargetTimeline = undef;
|
||||
$oRecoveryHashRef = undef;
|
||||
$strComment = undef;
|
||||
$iExpectedExitStatus = undef;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
BackRestTestBackup_Restore($oFile, $strIncrBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, $strXidTarget, undef, undef, undef, undef);
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
BackRestTestBackup_ClusterStart();
|
||||
BackRestTestBackup_PgSelectOneTest('select message from test', $strXidMessage);
|
||||
|
||||
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
|
||||
$strMessageExpected = $strXidMessage;
|
||||
|
||||
if ($strMessageActual ne $strMessageExpected)
|
||||
{
|
||||
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
|
||||
}
|
||||
BackRestTestBackup_PgExecute("update test set message = '$strTimelineMessage'", false);
|
||||
|
||||
# Restore (restore type = time, inclusive) - there is no exclusive time test because I can't find a way to find the
|
||||
# exact commit time of a transaction.
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_TIME;
|
||||
$bDelta = true;
|
||||
$bForce = false;
|
||||
$strType = RECOVERY_TYPE_TIME;
|
||||
$strTarget = $strTimeTarget;
|
||||
$bTargetExclusive = undef;
|
||||
$bTargetResume = undef;
|
||||
$strTargetTimeline = undef;
|
||||
$oRecoveryHashRef = undef;
|
||||
$strComment = undef;
|
||||
$iExpectedExitStatus = undef;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, $strTimeTarget, undef, undef, undef, undef);
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
BackRestTestBackup_ClusterStart();
|
||||
|
||||
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
|
||||
$strMessageExpected = $strTimeMessage;
|
||||
|
||||
if ($strMessageActual ne $strMessageExpected)
|
||||
{
|
||||
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
|
||||
}
|
||||
BackRestTestBackup_PgSelectOneTest('select message from test', $strTimeMessage);
|
||||
|
||||
# Restore (restore type = xid, exclusive)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_XID;
|
||||
$bDelta = true;
|
||||
$bForce = false;
|
||||
$strType = RECOVERY_TYPE_XID;
|
||||
$strTarget = $strXidTarget;
|
||||
$bTargetExclusive = true;
|
||||
$bTargetResume = undef;
|
||||
$strTargetTimeline = undef;
|
||||
$oRecoveryHashRef = undef;
|
||||
$strComment = undef;
|
||||
$iExpectedExitStatus = undef;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, $strXidTarget, true, undef, undef, undef);
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
BackRestTestBackup_ClusterStart();
|
||||
|
||||
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
|
||||
$strMessageExpected = $strIncrMessage;
|
||||
|
||||
if ($strMessageActual ne $strMessageExpected)
|
||||
{
|
||||
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
|
||||
}
|
||||
BackRestTestBackup_PgSelectOneTest('select message from test', $strIncrMessage);
|
||||
|
||||
# Restore (restore type = name)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = RECOVERY_TYPE_NAME;
|
||||
$bDelta = true;
|
||||
$bForce = true;
|
||||
$strType = RECOVERY_TYPE_NAME;
|
||||
$strTarget = $strNameTarget;
|
||||
$bTargetExclusive = undef;
|
||||
$bTargetResume = undef;
|
||||
$strTargetTimeline = undef;
|
||||
$oRecoveryHashRef = undef;
|
||||
$strComment = undef;
|
||||
$iExpectedExitStatus = undef;
|
||||
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, $strNameTarget, undef, undef, undef, undef);
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
BackRestTestBackup_ClusterStart();
|
||||
BackRestTestBackup_PgSelectOneTest('select message from test', $strNameMessage);
|
||||
|
||||
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
|
||||
$strMessageExpected = $strNameMessage;
|
||||
# Restore (restore type = default, timeline = 3)
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$bDelta = true;
|
||||
$bForce = false;
|
||||
$strType = RECOVERY_TYPE_DEFAULT;
|
||||
$strTarget = undef;
|
||||
$bTargetExclusive = undef;
|
||||
$bTargetResume = undef;
|
||||
$strTargetTimeline = 3;
|
||||
$oRecoveryHashRef = {&CONFIG_KEY_STANDBY_MODE => 'on'};
|
||||
$oRecoveryHashRef = undef;
|
||||
$strComment = undef;
|
||||
$iExpectedExitStatus = undef;
|
||||
|
||||
if ($strMessageActual ne $strMessageExpected)
|
||||
{
|
||||
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
|
||||
}
|
||||
&log(INFO, " testing recovery type = ${strType}");
|
||||
|
||||
BackRestTestBackup_ClusterStop();
|
||||
|
||||
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
||||
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
||||
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
||||
|
||||
BackRestTestBackup_ClusterStart(undef, undef, true);
|
||||
BackRestTestBackup_PgSelectOneTest('select message from test', $strTimelineMessage, 30);
|
||||
|
||||
$bCreate = true;
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin BackRe
|
||||
BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest
|
||||
BackRestTestCommon_PathCreate BackRestTestCommon_PathMode BackRestTestCommon_PathRemove
|
||||
BackRestTestCommon_FileCreate BackRestTestCommon_FileRemove BackRestTestCommon_PathCopy BackRestTestCommon_PathMove
|
||||
BackRestTestCommon_ConfigCreate BackRestTestCommon_ConfigRemap BackRestTestCommon_Run BackRestTestCommon_Cleanup
|
||||
BackRestTestCommon_PgSqlBinPathGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet
|
||||
BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet
|
||||
BackRestTestCommon_GroupGet BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet
|
||||
BackRestTestCommon_DataPathGet BackRestTestCommon_BackupPathGet BackRestTestCommon_ArchivePathGet
|
||||
BackRestTestCommon_DbPathGet BackRestTestCommon_DbCommonPathGet BackRestTestCommon_DbTablespacePathGet
|
||||
BackRestTestCommon_DbPortGet);
|
||||
BackRestTestCommon_ConfigCreate BackRestTestCommon_ConfigRemap BackRestTestCommon_ConfigRecovery
|
||||
BackRestTestCommon_Run BackRestTestCommon_Cleanup BackRestTestCommon_PgSqlBinPathGet
|
||||
BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet BackRestTestCommon_CommandRemoteGet
|
||||
BackRestTestCommon_HostGet BackRestTestCommon_UserGet BackRestTestCommon_GroupGet
|
||||
BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet BackRestTestCommon_DataPathGet
|
||||
BackRestTestCommon_BackupPathGet BackRestTestCommon_ArchivePathGet BackRestTestCommon_DbPathGet
|
||||
BackRestTestCommon_DbCommonPathGet BackRestTestCommon_DbTablespacePathGet BackRestTestCommon_DbPortGet);
|
||||
|
||||
my $strPgSqlBin;
|
||||
my $strCommonStanza;
|
||||
@ -483,6 +483,50 @@ sub BackRestTestCommon_ConfigRemap
|
||||
BackRestTestCommon_Execute("mv ${strRemoteConfigFile} " . BackRestTestCommon_BackupPathGet() . '/pg_backrest.conf', true);
|
||||
}
|
||||
}
|
||||
####################################################################################################################################
|
||||
# BackRestTestCommon_ConfigRecovery
|
||||
####################################################################################################################################
|
||||
sub BackRestTestCommon_ConfigRecovery
|
||||
{
|
||||
my $oRecoveryHashRef = shift;
|
||||
my $bRemote = shift;
|
||||
|
||||
# Create config filename
|
||||
my $strConfigFile = BackRestTestCommon_DbPathGet() . '/pg_backrest.conf';
|
||||
my $strStanza = BackRestTestCommon_StanzaGet();
|
||||
|
||||
# Load Config file
|
||||
my %oConfig;
|
||||
ini_load($strConfigFile, \%oConfig);
|
||||
|
||||
# Load remote config file
|
||||
my %oRemoteConfig;
|
||||
my $strRemoteConfigFile = BackRestTestCommon_TestPathGet() . '/pg_backrest.conf.remote';
|
||||
|
||||
if ($bRemote)
|
||||
{
|
||||
BackRestTestCommon_Execute("mv " . BackRestTestCommon_BackupPathGet() . "/pg_backrest.conf ${strRemoteConfigFile}", true);
|
||||
ini_load($strRemoteConfigFile, \%oRemoteConfig);
|
||||
}
|
||||
|
||||
# Rewrite remap section
|
||||
delete($oConfig{"${strStanza}:recovery:option"});
|
||||
|
||||
foreach my $strOption (sort(keys $oRecoveryHashRef))
|
||||
{
|
||||
$oConfig{"${strStanza}:recovery:option"}{$strOption} = ${$oRecoveryHashRef}{$strOption};
|
||||
}
|
||||
|
||||
# Resave the config file
|
||||
ini_save($strConfigFile, \%oConfig);
|
||||
|
||||
# Load remote config file
|
||||
if ($bRemote)
|
||||
{
|
||||
ini_save($strRemoteConfigFile, \%oRemoteConfig);
|
||||
BackRestTestCommon_Execute("mv ${strRemoteConfigFile} " . BackRestTestCommon_BackupPathGet() . '/pg_backrest.conf', true);
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestCommon_ConfigCreate
|
||||
|
Reference in New Issue
Block a user