1
0
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:
David Steele
2015-01-31 13:48:09 -05:00
parent cd9df8b4f8
commit e524c4dd1a
7 changed files with 305 additions and 110 deletions

View File

@ -459,7 +459,7 @@ if (operation_get() eq OP_RESTORE)
param_get(PARAM_TARGET_EXCLUSIVE), param_get(PARAM_TARGET_EXCLUSIVE),
param_get(PARAM_TARGET_RESUME), param_get(PARAM_TARGET_RESUME),
param_get(PARAM_TARGET_TIMELINE), param_get(PARAM_TARGET_TIMELINE),
config_section_load(CONFIG_SECTION_RECOVERY), config_section_load(CONFIG_SECTION_RECOVERY_OPTION),
param_get(PARAM_STANZA), param_get(PARAM_STANZA),
$0, $0,
param_get(PARAM_CONFIG) param_get(PARAM_CONFIG)

View File

@ -362,7 +362,7 @@ sub archive_xfer
foreach my $strFile (sort(keys $oManifestHash{name})) 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; push @stryFile, $strFile;

View File

@ -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 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_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_RESTORE CONFIG_SECTION_RECOVERY CONFIG_SECTION_RECOVERY_OPTION CONFIG_SECTION_TABLESPACE_MAP
CONFIG_SECTION_RETENTION CONFIG_SECTION_STANZA CONFIG_SECTION_ARCHIVE CONFIG_SECTION_RETENTION CONFIG_SECTION_STANZA
CONFIG_KEY_USER CONFIG_KEY_HOST CONFIG_KEY_PATH 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_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_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 # File/path constants
@ -135,6 +138,7 @@ use constant
CONFIG_SECTION_BACKUP => 'backup', CONFIG_SECTION_BACKUP => 'backup',
CONFIG_SECTION_RESTORE => 'restore', CONFIG_SECTION_RESTORE => 'restore',
CONFIG_SECTION_RECOVERY => 'recovery', CONFIG_SECTION_RECOVERY => 'recovery',
CONFIG_SECTION_RECOVERY_OPTION => 'recovery:option',
CONFIG_SECTION_TABLESPACE_MAP => 'tablespace:map', CONFIG_SECTION_TABLESPACE_MAP => 'tablespace:map',
CONFIG_SECTION_ARCHIVE => 'archive', CONFIG_SECTION_ARCHIVE => 'archive',
CONFIG_SECTION_RETENTION => 'retention', CONFIG_SECTION_RETENTION => 'retention',
@ -163,7 +167,14 @@ use constant
CONFIG_KEY_FULL_RETENTION => 'full-retention', CONFIG_KEY_FULL_RETENTION => 'full-retention',
CONFIG_KEY_DIFFERENTIAL_RETENTION => 'differential-retention', CONFIG_KEY_DIFFERENTIAL_RETENTION => 'differential-retention',
CONFIG_KEY_ARCHIVE_RETENTION_TYPE => 'archive-retention-type', 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 # Get and validate the operation
$strOperation = $ARGV[0]; $strOperation = $ARGV[0];
# Validate params
param_valid(); param_valid();
# # Validate thread parameter # # 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)), 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))); uc(config_key_load(CONFIG_SECTION_LOG, CONFIG_KEY_LEVEL_CONSOLE, true, ERROR)));
# Validate config
config_valid();
# Set test parameters # Set test parameters
test_set(param_get(PARAM_TEST), param_get(PARAM_TEST_DELAY)); test_set(param_get(PARAM_TEST), param_get(PARAM_TEST_DELAY));
} }
@ -330,6 +345,42 @@ sub config_key_load
return $strValue; 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 # PARAM_VALID
# #
@ -429,8 +480,8 @@ sub param_valid
confess &log(ERROR, PARAM_TARGET . ' is only required ' . $strTargetMessage, ERROR_PARAM); 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 # Check target-resume - can only be used when target is specified
if ((defined(param_get(PARAM_TARGET_RESUME)) || defined(param_get(PARAM_TARGET_TIMELINE))) && !defined($strTarget)) if (defined(param_get(PARAM_TARGET_RESUME)) && !defined($strTarget))
{ {
confess &log(ERROR, PARAM_TARGET_RESUME . ' and ' . PARAM_TARGET_TIMELINE . confess &log(ERROR, PARAM_TARGET_RESUME . ' and ' . PARAM_TARGET_TIMELINE .
' are only valid when target is specified', ERROR_PARAM); ' are only valid when target is specified', ERROR_PARAM);

View File

@ -12,7 +12,7 @@ use Carp;
# Exports # Exports
#################################################################################################################################### ####################################################################################################################################
use Exporter qw(import); 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 # Exception Codes
@ -20,9 +20,10 @@ our @EXPORT = qw(ERROR_CHECKSUM ERROR_PARAM ERROR_POSTMASTER_RUNNING ERROR_RESTO
use constant use constant
{ {
ERROR_CHECKSUM => 100, ERROR_CHECKSUM => 100,
ERROR_PARAM => 101, ERROR_CONFIG => 101,
ERROR_RESTORE_PATH_NOT_EMPTY => 102, ERROR_PARAM => 102,
ERROR_POSTMASTER_RUNNING => 103 ERROR_RESTORE_PATH_NOT_EMPTY => 103,
ERROR_POSTMASTER_RUNNING => 104
}; };
#################################################################################################################################### ####################################################################################################################################

View File

@ -38,7 +38,7 @@ sub new
my $strTarget = shift; # Recovery target my $strTarget = shift; # Recovery target
my $bTargetExclusive = shift; # Target exlusive option my $bTargetExclusive = shift; # Target exlusive option
my $bTargetResume = shift; # Target resume 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 $oRecoveryRef = shift; # Other recovery options
my $strStanza = shift; # Restore stanza my $strStanza = shift; # Restore stanza
my $strBackRestBin = shift; # Absolute backrest filename my $strBackRestBin = shift; # Absolute backrest filename
@ -59,7 +59,7 @@ sub new
$self->{strTarget} = $strTarget; $self->{strTarget} = $strTarget;
$self->{bTargetExclusive} = $bTargetExclusive; $self->{bTargetExclusive} = $bTargetExclusive;
$self->{bTargetResume} = $bTargetResume; $self->{bTargetResume} = $bTargetResume;
$self->{bTargetTimeline} = $bTargetTimeline; $self->{strTargetTimeline} = $strTargetTimeline;
$self->{oRecoveryRef} = $oRecoveryRef; $self->{oRecoveryRef} = $oRecoveryRef;
$self->{strStanza} = $strStanza; $self->{strStanza} = $strStanza;
$self->{strBackRestBin} = $strBackRestBin; $self->{strBackRestBin} = $strBackRestBin;
@ -478,19 +478,31 @@ sub recovery
# Write the recovery options from pg_backrest.conf # Write the recovery options from pg_backrest.conf
my $strRecovery = ''; 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 # Write the restore command
if (!$bRestoreCommandOverride)
{
$strRecovery .= "restore_command = '$self->{strBackRestBin} --stanza=$self->{strStanza}" . $strRecovery .= "restore_command = '$self->{strBackRestBin} --stanza=$self->{strStanza}" .
(defined($self->{strConfigFile}) ? " --config=$self->{strConfigFile}" : '') . (defined($self->{strConfigFile}) ? " --config=$self->{strConfigFile}" : '') .
" archive-get %f \"%p\"'\n"; " archive-get %f \"%p\"'\n";
}
# If RECOVERY_TYPE_DEFAULT do not write target options # If RECOVERY_TYPE_DEFAULT do not write target options
if ($self->{strType} ne RECOVERY_TYPE_DEFAULT) if ($self->{strType} ne RECOVERY_TYPE_DEFAULT)
@ -503,15 +515,10 @@ sub recovery
{ {
$strRecovery .= "recovery_target_inclusive = false\n"; $strRecovery .= "recovery_target_inclusive = false\n";
} }
# Write recovery_target_inclusive
if ($self->{bTargetExclusive})
{
$strRecovery .= "recovery_target_inclusive = false\n";
} }
# Write pause_at_recovery_target # Write pause_at_recovery_target
if ($self->{bTargetResult}) if ($self->{bTargetResume})
{ {
$strRecovery .= "pause_at_recovery_target = false\n"; $strRecovery .= "pause_at_recovery_target = false\n";
} }
@ -521,7 +528,6 @@ sub recovery
{ {
$strRecovery .= "recovery_target_timeline = $self->{strTargetTimeline}\n"; $strRecovery .= "recovery_target_timeline = $self->{strTargetTimeline}\n";
} }
}
# Write recovery.conf # Write recovery.conf
my $hFile; my $hFile;

View File

@ -151,6 +151,33 @@ sub BackRestTestBackup_PgSelectOne
return (BackRestTestBackup_PgSelect($strSql))[0]; 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 # BackRestTestBackup_ClusterStop
#################################################################################################################################### ####################################################################################################################################
@ -181,10 +208,12 @@ sub BackRestTestBackup_ClusterStart
{ {
my $strPath = shift; my $strPath = shift;
my $iPort = shift; my $iPort = shift;
my $bHotStandby = shift;
# Set default # Set default
$iPort = defined($iPort) ? $iPort : BackRestTestCommon_DbPortGet(); $iPort = defined($iPort) ? $iPort : BackRestTestCommon_DbPortGet();
$strPath = defined($strPath) ? $strPath : BackRestTestCommon_DbCommonPathGet(); $strPath = defined($strPath) ? $strPath : BackRestTestCommon_DbCommonPathGet();
$bHotStandby = defined($bHotStandby) ? $bHotStandby : false;
# Make sure postgres is not running # Make sure postgres is not running
if (-e $strPath . '/postmaster.pid') if (-e $strPath . '/postmaster.pid')
@ -197,8 +226,10 @@ sub BackRestTestBackup_ClusterStart
' --config=' . BackRestTestCommon_DbPathGet() . '/pg_backrest.conf archive-push %p'; ' --config=' . BackRestTestCommon_DbPathGet() . '/pg_backrest.conf archive-push %p';
# Start the cluster # Start the cluster
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/pg_ctl start -o \"-c port=${iPort} -c " . BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/pg_ctl start -o \"-c port=${iPort}" .
"checkpoint_segments=1 -c wal_level=archive -c archive_mode=on -c archive_command='${strArchive}' " . ' -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() . "'\" " . " -c unix_socket_directories='" . BackRestTestCommon_DbPathGet() . "'\" " .
"-D ${strPath} -l ${strPath}/postgresql.log -w -s"); "-D ${strPath} -l ${strPath}/postgresql.log -w -s");
@ -978,7 +1009,9 @@ sub BackRestTestBackup_Restore
($strBackup ne 'latest' ? ", backup '${strBackup}'" : '') . ($strBackup ne 'latest' ? ", backup '${strBackup}'" : '') .
($strType ? ", type '${strType}' " : '') . ($strType ? ", type '${strType}' " : '') .
($strTarget ? ", target '${strTarget}'" : '') . ($strTarget ? ", target '${strTarget}'" : '') .
($strTargetTimeline ? ", timeline '${strTargetTimeline}'" : '') .
(defined($bTargetExclusive) && $bTargetExclusive ? ', exclusive' : '') . (defined($bTargetExclusive) && $bTargetExclusive ? ', exclusive' : '') .
(defined($bTargetResume) && $bTargetResume ? ', resume' : '') .
(defined($oRemapHashRef) ? ', remap' : '') . (defined($oRemapHashRef) ? ', remap' : '') .
(defined($iExpectedExitStatus) ? ", expect exit ${iExpectedExitStatus}" : '') . (defined($iExpectedExitStatus) ? ", expect exit ${iExpectedExitStatus}" : '') .
(defined($strComment) ? " (${strComment})" : '')); (defined($strComment) ? " (${strComment})" : ''));
@ -988,6 +1021,11 @@ sub BackRestTestBackup_Restore
BackRestTestCommon_ConfigRemap($oRemapHashRef, $oExpectedManifestRef, $bRemote); BackRestTestCommon_ConfigRemap($oRemapHashRef, $oExpectedManifestRef, $bRemote);
} }
if (defined($oRecoveryHashRef))
{
BackRestTestCommon_ConfigRecovery($oRecoveryHashRef, $bRemote);
}
# Create the backup command # Create the backup command
BackRestTestCommon_Execute(BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() . BackRestTestCommon_Execute(BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() .
'/pg_backrest.conf' . (defined($bDelta) && $bDelta ? ' --delta' : '') . '/pg_backrest.conf' . (defined($bDelta) && $bDelta ? ' --delta' : '') .
@ -995,7 +1033,9 @@ sub BackRestTestBackup_Restore
($strBackup ne 'latest' ? " --set=${strBackup}" : '') . ($strBackup ne 'latest' ? " --set=${strBackup}" : '') .
(defined($strType) && $strType ne RECOVERY_TYPE_DEFAULT ? " --type=${strType}" : '') . (defined($strType) && $strType ne RECOVERY_TYPE_DEFAULT ? " --type=${strType}" : '') .
(defined($strTarget) ? " --target=\"${strTarget}\"" : '') . (defined($strTarget) ? " --target=\"${strTarget}\"" : '') .
(defined($strTargetTimeline) ? " --target-timeline=\"${strTargetTimeline}\"" : '') .
(defined($bTargetExclusive) && $bTargetExclusive ? " --target-exclusive" : '') . (defined($bTargetExclusive) && $bTargetExclusive ? " --target-exclusive" : '') .
(defined($bTargetResume) && $bTargetResume ? " --target-resume" : '') .
" --stanza=${strStanza} restore", " --stanza=${strStanza} restore",
undef, undef, undef, $iExpectedExitStatus); undef, undef, undef, $iExpectedExitStatus);
} }
@ -1662,13 +1702,22 @@ sub BackRestTestBackup_Test
undef); # compress-async undef); # compress-async
} }
# Backup parameters # Static backup parameters
my $strType;
my $bSynthetic = false; my $bSynthetic = false;
my $bTestPoint = false;
my $fTestDelay = .25; my $fTestDelay = .25;
# Variable backup parameters
my $bDelta = true; my $bDelta = true;
my $bForce = false; 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 # Restore test string
my $strDefaultMessage = 'default'; my $strDefaultMessage = 'default';
@ -1677,19 +1726,21 @@ sub BackRestTestBackup_Test
my $strTimeMessage = 'time'; my $strTimeMessage = 'time';
my $strXidMessage = 'xid'; my $strXidMessage = 'xid';
my $strNameMessage = 'name'; my $strNameMessage = 'name';
my $strTimelineMessage = 'timeline3';
# Full backup # Full backup
#----------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
$strType = BACKUP_TYPE_FULL; $strType = BACKUP_TYPE_FULL;
$bTestPoint = true; $strTestPoint = TEST_MANIFEST_BUILD;
$strComment = 'insert during backup';
BackRestTestBackup_PgExecute("create table test (message text not null)"); BackRestTestBackup_PgExecute("create table test (message text not null)");
BackRestTestBackup_PgSwitchXlog(); BackRestTestBackup_PgSwitchXlog();
BackRestTestBackup_PgExecute("insert into test values ('$strDefaultMessage')"); BackRestTestBackup_PgExecute("insert into test values ('$strDefaultMessage')");
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "insert during backup", $bSynthetic, $bTestPoint, BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, $bSynthetic,
$fTestDelay); defined($strTestPoint), $fTestDelay);
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD); BackRestTestCommon_ExecuteEnd($strTestPoint);
BackRestTestBackup_PgExecute("update test set message = '$strFullMessage'", false); BackRestTestBackup_PgExecute("update test set message = '$strFullMessage'", false);
@ -1705,16 +1756,17 @@ sub BackRestTestBackup_Test
# Incr backup # Incr backup
#----------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
$strType = BACKUP_TYPE_INCR; $strType = BACKUP_TYPE_INCR;
$bTestPoint = true; $strTestPoint = TEST_MANIFEST_BUILD;
$strComment = 'update during backup';
BackRestTestBackup_PgExecute("create table test_remove (id int)", false); BackRestTestBackup_PgExecute("create table test_remove (id int)", false);
BackRestTestBackup_PgSwitchXlog(); BackRestTestBackup_PgSwitchXlog();
BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false); BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false);
BackRestTestBackup_PgSwitchXlog(); BackRestTestBackup_PgSwitchXlog();
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "update during backup", $bSynthetic, $bTestPoint, BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, $bSynthetic,
$fTestDelay); defined($strTestPoint), $fTestDelay);
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD); BackRestTestCommon_ExecuteEnd($strTestPoint);
BackRestTestBackup_PgExecute("drop table test_remove", false); BackRestTestBackup_PgExecute("drop table test_remove", false);
BackRestTestBackup_PgSwitchXlog(); BackRestTestBackup_PgSwitchXlog();
@ -1742,134 +1794,175 @@ sub BackRestTestBackup_Test
# Restore (type = default) # Restore (type = default)
#----------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_DEFAULT;
$bDelta = false; $bDelta = false;
$bForce = 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}"); &log(INFO, " testing recovery type = ${strType}");
# Expect failure because postmaster.pid exists # Expect failure because postmaster.pid exists
$strComment = 'postmaster running';
$iExpectedExitStatus = ERROR_POSTMASTER_RUNNING;
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce, BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, undef, undef, undef, undef, undef, $strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
'postmaster running', ERROR_POSTMASTER_RUNNING); $oRecoveryHashRef, $strComment, $iExpectedExitStatus);
BackRestTestBackup_ClusterStop(); BackRestTestBackup_ClusterStop();
# Expect failure because db path is not empty # 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, BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, undef, undef, undef, undef, undef, $strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
'path not empty', ERROR_RESTORE_PATH_NOT_EMPTY); $oRecoveryHashRef, $strComment, $iExpectedExitStatus);
# Drop and recreate db path # Drop and recreate db path
BackRestTestCommon_PathRemove(BackRestTestCommon_DbCommonPathGet()); BackRestTestCommon_PathRemove(BackRestTestCommon_DbCommonPathGet());
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet()); BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet());
# Now the restore should work # Now the restore should work
$strComment = undef;
$iExpectedExitStatus = undef;
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce, 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(); BackRestTestBackup_ClusterStart();
BackRestTestBackup_PgSelectOneTest('select message from test', $strNameMessage);
my $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
my $strMessageExpected = $strNameMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# Restore (restore type = xid, inclusive) # Restore (restore type = xid, inclusive)
#----------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_XID;
$bDelta = false; $bDelta = false;
$bForce = true; $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}"); &log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop(); BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, $strIncrBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce, BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, $strXidTarget, undef, undef, undef, undef); $strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
BackRestTestBackup_ClusterStart(); BackRestTestBackup_ClusterStart();
BackRestTestBackup_PgSelectOneTest('select message from test', $strXidMessage);
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test"); BackRestTestBackup_PgExecute("update test set message = '$strTimelineMessage'", false);
$strMessageExpected = $strXidMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# Restore (restore type = time, inclusive) - there is no exclusive time test because I can't find a way to find the # 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. # exact commit time of a transaction.
#----------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_TIME;
$bDelta = true; $bDelta = true;
$bForce = false; $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}"); &log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop(); BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce, 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(); BackRestTestBackup_ClusterStart();
BackRestTestBackup_PgSelectOneTest('select message from test', $strTimeMessage);
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
$strMessageExpected = $strTimeMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# Restore (restore type = xid, exclusive) # Restore (restore type = xid, exclusive)
#----------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_XID;
$bDelta = true; $bDelta = true;
$bForce = false; $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}"); &log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop(); BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce, 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(); BackRestTestBackup_ClusterStart();
BackRestTestBackup_PgSelectOneTest('select message from test', $strIncrMessage);
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
$strMessageExpected = $strIncrMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# Restore (restore type = name) # Restore (restore type = name)
#----------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_NAME;
$bDelta = true; $bDelta = true;
$bForce = 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}"); &log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop(); BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce, BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, $strNameTarget, undef, undef, undef, undef); $strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
BackRestTestBackup_ClusterStart(); BackRestTestBackup_ClusterStart();
BackRestTestBackup_PgSelectOneTest('select message from test', $strNameMessage);
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test"); # Restore (restore type = default, timeline = 3)
$strMessageExpected = $strNameMessage; #-----------------------------------------------------------------------------------------------------------------------
$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) &log(INFO, " testing recovery type = ${strType}");
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'"; 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; $bCreate = true;
} }

View File

@ -30,13 +30,13 @@ our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin BackRe
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_PathMove BackRestTestCommon_FileCreate BackRestTestCommon_FileRemove BackRestTestCommon_PathCopy BackRestTestCommon_PathMove
BackRestTestCommon_ConfigCreate BackRestTestCommon_ConfigRemap BackRestTestCommon_Run BackRestTestCommon_Cleanup BackRestTestCommon_ConfigCreate BackRestTestCommon_ConfigRemap BackRestTestCommon_ConfigRecovery
BackRestTestCommon_PgSqlBinPathGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet BackRestTestCommon_Run BackRestTestCommon_Cleanup BackRestTestCommon_PgSqlBinPathGet
BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet BackRestTestCommon_CommandRemoteGet
BackRestTestCommon_GroupGet BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet BackRestTestCommon_GroupGet
BackRestTestCommon_DataPathGet BackRestTestCommon_BackupPathGet BackRestTestCommon_ArchivePathGet BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet BackRestTestCommon_DataPathGet
BackRestTestCommon_DbPathGet BackRestTestCommon_DbCommonPathGet BackRestTestCommon_DbTablespacePathGet BackRestTestCommon_BackupPathGet BackRestTestCommon_ArchivePathGet BackRestTestCommon_DbPathGet
BackRestTestCommon_DbPortGet); BackRestTestCommon_DbCommonPathGet BackRestTestCommon_DbTablespacePathGet BackRestTestCommon_DbPortGet);
my $strPgSqlBin; my $strPgSqlBin;
my $strCommonStanza; my $strCommonStanza;
@ -483,6 +483,50 @@ sub BackRestTestCommon_ConfigRemap
BackRestTestCommon_Execute("mv ${strRemoteConfigFile} " . BackRestTestCommon_BackupPathGet() . '/pg_backrest.conf', true); 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 # BackRestTestCommon_ConfigCreate