You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-05-22 10:15:16 +02:00
Added check command.
The check command validates that pgBackRest is configured correctly for archiving and backups. Contributed by Cynthia Shang.
This commit is contained in:
committed by
David Steele
parent
7c9eaf7210
commit
7e45ed8366
@@ -292,6 +292,7 @@ sub BackRestTestBackup_ClusterStart
|
||||
my $bHotStandby = shift;
|
||||
my $bArchive = shift;
|
||||
my $bArchiveAlways = shift;
|
||||
my $bArchiveInvalid = shift;
|
||||
|
||||
# Set default
|
||||
$iPort = defined($iPort) ? $iPort : BackRestTestCommon_DbPortGet();
|
||||
@@ -307,7 +308,8 @@ sub BackRestTestBackup_ClusterStart
|
||||
}
|
||||
|
||||
# Create the archive command
|
||||
my $strArchive = BackRestTestCommon_CommandMainAbsGet() . ' --stanza=' . BackRestTestCommon_StanzaGet() .
|
||||
my $strArchive = BackRestTestCommon_CommandMainAbsGet() . ' --stanza=' .
|
||||
(defined($bArchiveInvalid) ? 'bogus' : BackRestTestCommon_StanzaGet()) .
|
||||
' --config=' . BackRestTestCommon_DbPathGet() . '/pgbackrest.conf archive-push %p';
|
||||
|
||||
# Start the cluster
|
||||
@@ -389,6 +391,7 @@ sub BackRestTestBackup_ClusterCreate
|
||||
my $iPort = shift;
|
||||
my $bArchive = shift;
|
||||
my $strXlogPath = shift;
|
||||
my $bArchiveInvalid = shift;
|
||||
|
||||
# Defaults
|
||||
$strPath = defined($strPath) ? $strPath : BackRestTestCommon_DbCommonPathGet();
|
||||
@@ -399,7 +402,7 @@ sub BackRestTestBackup_ClusterCreate
|
||||
'/initdb' . (BackRestTestCommon_DbVersion() >= PG_VERSION_92 ? ' --xlogdir=${strXlogPath}' : '') .
|
||||
" --pgdata=${strPath} --auth=trust");
|
||||
|
||||
BackRestTestBackup_ClusterStart($strPath, $iPort, undef, $bArchive);
|
||||
BackRestTestBackup_ClusterStart($strPath, $iPort, undef, $bArchive, undef, $bArchiveInvalid);
|
||||
|
||||
# Connect user session
|
||||
BackRestTestBackup_PgConnect();
|
||||
@@ -1306,6 +1309,31 @@ sub BackRestTestBackup_Backup
|
||||
return BackRestTestBackup_BackupEnd();
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestBackup_Check
|
||||
####################################################################################################################################
|
||||
push @EXPORT, qw(BackRestTestBackup_Check);
|
||||
|
||||
sub BackRestTestBackup_Check
|
||||
{
|
||||
my $strStanza = shift;
|
||||
my $bRemote = shift;
|
||||
my $iArchiveTimeout = shift;
|
||||
my $strComment = shift;
|
||||
my $iExpectedExitStatus = shift;
|
||||
|
||||
$strComment = "check" . (defined($strStanza) ? " ${strStanza}" : '') . " (" . $strComment . ")";
|
||||
&log(INFO, " $strComment");
|
||||
|
||||
my $strCommand = ($bRemote ? BackRestTestCommon_CommandMainAbsGet() : BackRestTestCommon_CommandMainGet()) .
|
||||
' --config=' . ($bRemote ? BackRestTestCommon_RepoPathGet() : BackRestTestCommon_DbPathGet()) .
|
||||
"/pgbackrest.conf --archive-timeout=${iArchiveTimeout} --stanza=${strStanza} check --log-level-console=detail";
|
||||
|
||||
executeTest($strCommand,
|
||||
{bRemote => $bRemote, strComment => $strComment, iExpectedExitStatus => $iExpectedExitStatus,
|
||||
oLogTest => $oBackupLogTest});
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestTestBackup_Info
|
||||
####################################################################################################################################
|
||||
|
||||
@@ -1717,7 +1717,8 @@ sub BackRestTestBackup_Test
|
||||
# Create the cluster
|
||||
if ($bCreate)
|
||||
{
|
||||
BackRestTestBackup_ClusterCreate();
|
||||
# For the 'fail on missing archive.info file' test, the archive.info file must not be found so set archive invalid
|
||||
BackRestTestBackup_ClusterCreate(undef, undef, undef, undef, true);
|
||||
$bCreate = false;
|
||||
}
|
||||
|
||||
@@ -1754,16 +1755,68 @@ sub BackRestTestBackup_Test
|
||||
# Test invalid archive command
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
$strType = BACKUP_TYPE_FULL;
|
||||
$strComment = 'fail on invalid archive_command';
|
||||
|
||||
# NOTE: This must run before the success test since that will create the archive.info file
|
||||
$strComment = 'fail on missing archive.info file';
|
||||
|
||||
BackRestTestBackup_Check($strStanza, $bRemote, 0.1, $strComment, ERROR_FILE_MISSING);
|
||||
|
||||
# Clean up the archive_timeout error from the postgresql log by stopping the cluster and removing the log file before
|
||||
# running the next test
|
||||
BackRestTestBackup_ClusterStop(undef, undef, true);
|
||||
BackRestTestCommon_FileRemove(BackRestTestCommon_DbCommonPathGet() . '/postgresql.log');
|
||||
|
||||
# Check archive_command_not_set error
|
||||
BackRestTestBackup_ClusterStop();
|
||||
$strComment = 'fail on invalid archive_command';
|
||||
BackRestTestBackup_ClusterStart(undef, undef, undef, false);
|
||||
|
||||
BackRestTestBackup_Backup($strType, $strStanza, $strComment, {iExpectedExitStatus => ERROR_ARCHIVE_COMMAND_INVALID});
|
||||
BackRestTestBackup_Backup(
|
||||
$strType, $strStanza, $strComment,
|
||||
{iExpectedExitStatus => ERROR_ARCHIVE_COMMAND_INVALID});
|
||||
|
||||
BackRestTestBackup_Check($strStanza, $bRemote, 0.1, $strComment, ERROR_ARCHIVE_COMMAND_INVALID);
|
||||
|
||||
# If running the remote tests then also need to run check locally
|
||||
if ($bRemote)
|
||||
{
|
||||
BackRestTestBackup_Check($strStanza, false, 0.1, "${strComment} - remote", ERROR_ARCHIVE_COMMAND_INVALID);
|
||||
}
|
||||
|
||||
# Clean up the archive_command error from the postgresql log by stopping the cluster and removing the log file before
|
||||
# running the next test
|
||||
BackRestTestBackup_ClusterStop(undef, undef, true);
|
||||
BackRestTestCommon_FileRemove(BackRestTestCommon_DbCommonPathGet() . '/postgresql.log');
|
||||
|
||||
# Providing a sufficient archive-timeout, verify that the check command runs successfully.
|
||||
$strComment = 'verify success';
|
||||
|
||||
BackRestTestBackup_ClusterStart();
|
||||
BackRestTestBackup_Check($strStanza, $bRemote, 5, $strComment, 0);
|
||||
|
||||
# If running the remote tests then also need to run check locally
|
||||
if ($bRemote)
|
||||
{
|
||||
BackRestTestBackup_Check($strStanza, false, 5, "${strComment} - remote", 0);
|
||||
}
|
||||
|
||||
# Check archive_timeout error
|
||||
$strComment = 'fail on archive timeout';
|
||||
BackRestTestBackup_ClusterStop();
|
||||
BackRestTestBackup_ClusterStart(undef, undef, undef, undef, undef, true);
|
||||
BackRestTestBackup_Check($strStanza, $bRemote, 0.1, $strComment, ERROR_ARCHIVE_TIMEOUT);
|
||||
|
||||
# If running the remote tests then also need to run check locally
|
||||
if ($bRemote)
|
||||
{
|
||||
BackRestTestBackup_Check($strStanza, false, 0.1, "${strComment} - remote", ERROR_ARCHIVE_TIMEOUT);
|
||||
}
|
||||
|
||||
# Clean up the archive_timeout error from the postgresql log by stopping the cluster and removing the log file
|
||||
# before running the next test
|
||||
BackRestTestBackup_ClusterStop(undef, undef, true);
|
||||
BackRestTestCommon_FileRemove(BackRestTestCommon_DbCommonPathGet() . '/postgresql.log');
|
||||
|
||||
# Reset the cluster to a normal state so the next test will work
|
||||
BackRestTestBackup_ClusterStop();
|
||||
BackRestTestBackup_ClusterStart();
|
||||
|
||||
# Full backup
|
||||
|
||||
Reference in New Issue
Block a user