2014-06-22 17:30:17 +03:00
|
|
|
#!/usr/bin/perl
|
|
|
|
####################################################################################################################################
|
|
|
|
# CommonTest.pm - Common globals used for testing
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRestTest::CommonTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
2015-03-03 07:57:20 +02:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2015-07-11 23:16:35 +02:00
|
|
|
use Cwd qw(abs_path cwd);
|
2015-06-14 00:25:49 +02:00
|
|
|
use Exporter qw(import);
|
2014-06-22 17:30:17 +03:00
|
|
|
use File::Basename;
|
2015-06-14 00:25:49 +02:00
|
|
|
use File::Copy qw(move);
|
2014-10-16 20:22:34 +03:00
|
|
|
use File::Path qw(remove_tree);
|
2015-06-14 00:25:49 +02:00
|
|
|
use IO::Select;
|
2014-07-03 02:15:21 +03:00
|
|
|
use IPC::Open3;
|
2014-09-18 18:28:23 +03:00
|
|
|
use POSIX ':sys_wait_h';
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2014-09-18 18:28:23 +03:00
|
|
|
use lib dirname($0) . '/../lib';
|
2015-08-29 20:20:46 +02:00
|
|
|
use BackRest::Common::Ini;
|
|
|
|
use BackRest::Common::Log;
|
|
|
|
use BackRest::Common::String;
|
|
|
|
use BackRest::Common::Wait;
|
2015-09-08 13:31:24 +02:00
|
|
|
use BackRest::Config::Config;
|
2015-06-14 00:25:49 +02:00
|
|
|
use BackRest::Db;
|
2014-06-22 21:51:28 +03:00
|
|
|
use BackRest::File;
|
2015-01-23 03:11:33 +02:00
|
|
|
use BackRest::Manifest;
|
2014-06-22 18:56:01 +03:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
our @EXPORT = qw(BackRestTestCommon_Create BackRestTestCommon_Drop BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin
|
|
|
|
BackRestTestCommon_ExecuteEnd BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest
|
2014-12-21 17:11:17 +02:00
|
|
|
BackRestTestCommon_PathCreate BackRestTestCommon_PathMode BackRestTestCommon_PathRemove
|
2015-01-22 17:54:02 +02:00
|
|
|
BackRestTestCommon_FileCreate BackRestTestCommon_FileRemove BackRestTestCommon_PathCopy BackRestTestCommon_PathMove
|
2015-01-31 20:48:09 +02:00
|
|
|
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
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_RepoPathGet BackRestTestCommon_LocalPathGet BackRestTestCommon_DbPathGet
|
|
|
|
BackRestTestCommon_DbCommonPathGet BackRestTestCommon_ClusterStop BackRestTestCommon_DbTablespacePathGet
|
2015-04-08 00:36:59 +02:00
|
|
|
BackRestTestCommon_DbPortGet BackRestTestCommon_iniLoad BackRestTestCommon_iniSave BackRestTestCommon_DbVersion
|
2015-05-07 02:24:34 +02:00
|
|
|
BackRestTestCommon_CommandPsqlGet BackRestTestCommon_DropRepo BackRestTestCommon_CreateRepo
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestCommon_manifestLoad BackRestTestCommon_manifestSave BackRestTestCommon_CommandMainAbsGet
|
2015-06-18 21:39:30 +02:00
|
|
|
BackRestTestCommon_TestLogAppendFile BackRestTestCommon_CommandRemoteFullGet);
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2014-08-11 04:22:17 +03:00
|
|
|
my $strPgSqlBin;
|
2014-06-22 17:30:17 +03:00
|
|
|
my $strCommonStanza;
|
2014-06-22 21:51:28 +03:00
|
|
|
my $strCommonCommandMain;
|
2015-07-11 23:16:35 +02:00
|
|
|
my $bCommandMainSet = false;
|
2014-06-22 17:30:17 +03:00
|
|
|
my $strCommonCommandRemote;
|
2015-06-18 21:39:30 +02:00
|
|
|
my $strCommonCommandRemoteFull;
|
2014-06-22 21:51:28 +03:00
|
|
|
my $strCommonCommandPsql;
|
2014-06-22 17:30:17 +03:00
|
|
|
my $strCommonHost;
|
|
|
|
my $strCommonUser;
|
|
|
|
my $strCommonGroup;
|
|
|
|
my $strCommonUserBackRest;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strCommonBasePath;
|
2014-06-22 17:30:17 +03:00
|
|
|
my $strCommonTestPath;
|
2014-07-13 16:13:19 +03:00
|
|
|
my $strCommonDataPath;
|
2015-03-12 18:15:19 +02:00
|
|
|
my $strCommonRepoPath;
|
|
|
|
my $strCommonLocalPath;
|
2014-06-22 21:51:28 +03:00
|
|
|
my $strCommonDbPath;
|
|
|
|
my $strCommonDbCommonPath;
|
2014-09-20 00:51:51 +03:00
|
|
|
my $strCommonDbTablespacePath;
|
2014-06-22 18:56:01 +03:00
|
|
|
my $iCommonDbPort;
|
2015-04-01 21:58:33 +02:00
|
|
|
my $strCommonDbVersion;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $iModuleTestRunOnly;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bDryRun;
|
|
|
|
my $bNoCleanup;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $bLogForce;
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2014-08-10 22:02:14 +03:00
|
|
|
# Execution globals
|
2015-06-14 00:25:49 +02:00
|
|
|
my $bExecuteRemote;
|
2014-08-10 22:02:14 +03:00
|
|
|
my $strErrorLog;
|
|
|
|
my $hError;
|
|
|
|
my $strOutLog;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strFullLog;
|
|
|
|
my $bFullLog = false;
|
2014-08-10 22:02:14 +03:00
|
|
|
my $hOut;
|
|
|
|
my $pId;
|
|
|
|
my $strCommand;
|
2015-05-29 20:39:43 +02:00
|
|
|
my $oReplaceHash = {};
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
# Test globals
|
|
|
|
my $strTestLog;
|
|
|
|
my $strModule;
|
|
|
|
my $strModuleTest;
|
|
|
|
my $iModuleTestRun;
|
2015-06-14 00:25:49 +02:00
|
|
|
my $bValidWalChecksum;
|
2015-05-05 19:08:48 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_ClusterStop
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_ClusterStop
|
|
|
|
{
|
|
|
|
my $strPath = shift;
|
|
|
|
my $bImmediate = shift;
|
|
|
|
|
|
|
|
# Set default
|
|
|
|
$strPath = defined($strPath) ? $strPath : BackRestTestCommon_DbCommonPathGet();
|
|
|
|
$bImmediate = defined($bImmediate) ? $bImmediate : false;
|
|
|
|
|
|
|
|
# If postmaster process is running then stop the cluster
|
|
|
|
if (-e $strPath . '/postmaster.pid')
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/pg_ctl stop -D ${strPath} -w -s -m " .
|
|
|
|
($bImmediate ? 'immediate' : 'fast'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-04-08 00:36:59 +02:00
|
|
|
# BackRestTestCommon_DropRepo
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
2015-04-08 00:36:59 +02:00
|
|
|
sub BackRestTestCommon_DropRepo
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
# Remove the backrest private directory
|
|
|
|
while (-e BackRestTestCommon_RepoPathGet())
|
|
|
|
{
|
|
|
|
BackRestTestCommon_PathRemove(BackRestTestCommon_RepoPathGet(), true, true);
|
|
|
|
BackRestTestCommon_PathRemove(BackRestTestCommon_RepoPathGet(), false, true);
|
2015-08-29 20:20:46 +02:00
|
|
|
waitHiRes(.1);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-04-08 00:36:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_CreateRepo
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_CreateRepo
|
|
|
|
{
|
|
|
|
my $bRemote = shift;
|
|
|
|
|
|
|
|
BackRestTestCommon_DropRepo();
|
|
|
|
|
|
|
|
# Create the backup directory
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute('mkdir -m 700 ' . BackRestTestCommon_RepoPathGet(), true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BackRestTestCommon_PathCreate(BackRestTestCommon_RepoPathGet());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_Drop
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_Drop
|
|
|
|
{
|
|
|
|
# Drop the cluster if it exists
|
|
|
|
BackRestTestCommon_ClusterStop(BackRestTestCommon_DbCommonPathGet(), true);
|
|
|
|
|
|
|
|
# Remove the backrest private directory
|
|
|
|
BackRestTestCommon_DropRepo();
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
# Remove the test directory
|
|
|
|
BackRestTestCommon_PathRemove(BackRestTestCommon_TestPathGet());
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_Create
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_Create
|
|
|
|
{
|
|
|
|
# Create the test directory
|
|
|
|
BackRestTestCommon_PathCreate(BackRestTestCommon_TestPathGet(), '0770');
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
####################################################################################################################################
|
2014-10-16 02:11:09 +03:00
|
|
|
# BackRestTestCommon_Run
|
2014-07-16 05:32:41 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_Run
|
|
|
|
{
|
|
|
|
my $iRun = shift;
|
|
|
|
my $strLog = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strModuleParam = shift;
|
|
|
|
my $strModuleTestParam = shift;
|
2015-06-14 00:25:49 +02:00
|
|
|
my $bValidWalChecksumParam = shift;
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
# &log(INFO, "module " . (defined($strModule) ? $strModule : ''));
|
|
|
|
BackRestTestCommon_TestLog();
|
|
|
|
|
|
|
|
if (defined($iModuleTestRunOnly) && $iModuleTestRunOnly != $iRun)
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$strTestLog = 'run ' . sprintf('%03d', $iRun) . ' - ' . $strLog;
|
|
|
|
|
|
|
|
&log(INFO, $strTestLog);
|
2014-07-16 05:32:41 +03:00
|
|
|
|
|
|
|
if ($bDryRun)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$strFullLog = "${strTestLog}\n" . ('=' x length($strTestLog)) . "\n";
|
2015-05-29 20:39:43 +02:00
|
|
|
$oReplaceHash = {};
|
2015-05-05 19:08:48 +02:00
|
|
|
|
|
|
|
$strModule = $strModuleParam;
|
|
|
|
$strModuleTest = $strModuleTestParam;
|
|
|
|
$iModuleTestRun = $iRun;
|
2015-06-14 00:25:49 +02:00
|
|
|
$bValidWalChecksum = defined($bValidWalChecksumParam) ? $bValidWalChecksumParam : true;
|
2015-05-05 19:08:48 +02:00
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2014-10-16 02:11:09 +03:00
|
|
|
# BackRestTestCommon_Cleanup
|
2014-07-16 05:32:41 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_Cleanup
|
|
|
|
{
|
2015-05-05 19:08:48 +02:00
|
|
|
BackRestTestCommon_TestLog();
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
return !$bNoCleanup && !$bDryRun;
|
|
|
|
}
|
2014-06-22 18:56:01 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_TestLogAppendFile
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_TestLogAppendFile
|
|
|
|
{
|
|
|
|
my $strFileName = shift;
|
|
|
|
my $bRemote = shift;
|
2015-09-02 01:05:10 +02:00
|
|
|
my $strDescription = shift;
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
if (defined($strModule))
|
|
|
|
{
|
|
|
|
my $hFile;
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g+x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
|
|
|
|
open($hFile, '<', $strFileName)
|
|
|
|
or confess &log(ERROR, "unable to open ${strFileName} for appending to test log");
|
|
|
|
|
2015-09-02 01:05:10 +02:00
|
|
|
my $strHeader .= "+ supplemental file: " . BackRestTestCommon_ExecuteRegExpAll($strFileName);
|
|
|
|
|
|
|
|
if (defined($strDescription))
|
|
|
|
{
|
|
|
|
$strFullLog .= "\n" . BackRestTestCommon_ExecuteRegExpAll($strDescription) . "\n" . ('=' x '132') . "\n";
|
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
$strFullLog .= "\n${strHeader}\n" . ('-' x length($strHeader)) . "\n";
|
|
|
|
|
|
|
|
while (my $strLine = readline($hFile))
|
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExpAll($strLine);
|
2015-06-14 00:25:49 +02:00
|
|
|
$strFullLog .= $strLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
close($hFile);
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g-x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_TestLog
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_TestLog
|
|
|
|
{
|
|
|
|
if (defined($strModule))
|
|
|
|
{
|
|
|
|
my $hFile;
|
|
|
|
my $strLogFile = BackRestTestCommon_BasePathGet() .
|
|
|
|
sprintf("/test/log/${strModule}-${strModuleTest}-%03d.log", $iModuleTestRun);
|
|
|
|
|
|
|
|
if (!$bLogForce && -e $strLogFile)
|
|
|
|
{
|
|
|
|
mkdir(BackRestTestCommon_TestPathGet() . '/log');
|
|
|
|
|
|
|
|
my $strTestLogFile = BackRestTestCommon_TestPathGet() .
|
|
|
|
sprintf("/log/${strModule}-${strModuleTest}-%03d.log", $iModuleTestRun);
|
|
|
|
|
|
|
|
open($hFile, '>', $strTestLogFile)
|
|
|
|
or die "Could not open file '${strTestLogFile}': $!";
|
|
|
|
|
|
|
|
print $hFile $strFullLog;
|
|
|
|
close $hFile;
|
|
|
|
|
|
|
|
BackRestTestCommon_Execute("diff ${strLogFile} ${strTestLogFile}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
open($hFile, '>', $strLogFile)
|
|
|
|
or die "Could not open file '${strLogFile}': $!";
|
|
|
|
|
|
|
|
print $hFile $strFullLog;
|
|
|
|
close $hFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
undef($strModule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 18:56:01 +03:00
|
|
|
####################################################################################################################################
|
2014-10-16 02:11:09 +03:00
|
|
|
# BackRestTestCommon_ExecuteBegin
|
2014-06-22 18:56:01 +03:00
|
|
|
####################################################################################################################################
|
2014-08-10 22:02:14 +03:00
|
|
|
sub BackRestTestCommon_ExecuteBegin
|
2014-07-03 01:58:38 +03:00
|
|
|
{
|
2014-08-10 22:02:14 +03:00
|
|
|
my $strCommandParam = shift;
|
2014-07-03 01:58:38 +03:00
|
|
|
my $bRemote = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strComment = shift;
|
2014-07-03 01:58:38 +03:00
|
|
|
|
|
|
|
# Set defaults
|
2015-06-14 00:25:49 +02:00
|
|
|
$bExecuteRemote = defined($bRemote) ? $bRemote : false;
|
2014-07-03 01:58:38 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($bExecuteRemote)
|
2014-07-03 01:58:38 +03:00
|
|
|
{
|
2014-08-10 22:02:14 +03:00
|
|
|
$strCommand = "ssh ${strCommonUserBackRest}\@${strCommonHost} '${strCommandParam}'";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strCommand = $strCommandParam;
|
2014-07-03 01:58:38 +03:00
|
|
|
}
|
|
|
|
|
2014-08-10 22:02:14 +03:00
|
|
|
$strErrorLog = '';
|
|
|
|
$hError = undef;
|
|
|
|
$strOutLog = '';
|
|
|
|
$hOut = undef;
|
2014-07-12 17:26:51 +03:00
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$bFullLog = false;
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
if (defined($strModule) &&
|
|
|
|
($strCommandParam =~ /$strCommonCommandMain/ || $strCommandParam =~ /$strCommonCommandRemote/))
|
2015-05-05 19:08:48 +02:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
$strCommandParam = BackRestTestCommon_ExecuteRegExpAll($strCommandParam);
|
2015-05-05 19:08:48 +02:00
|
|
|
|
|
|
|
if (defined($strComment))
|
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
$strComment = BackRestTestCommon_ExecuteRegExpAll($strComment);
|
2015-05-05 19:08:48 +02:00
|
|
|
$strFullLog .= "\n${strComment}";
|
|
|
|
}
|
|
|
|
|
|
|
|
$strFullLog .= "\n> ${strCommandParam}\n" . ('-' x '132') . "\n";
|
|
|
|
$bFullLog = true;
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
&log(DEBUG, "executing command: ${strCommand}");
|
|
|
|
|
2014-07-28 01:13:23 +03:00
|
|
|
# Execute the command
|
2014-08-10 22:02:14 +03:00
|
|
|
$pId = open3(undef, $hOut, $hError, $strCommand);
|
|
|
|
}
|
|
|
|
|
2015-05-29 20:39:43 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_ExecuteRegExp
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_ExecuteRegExp
|
|
|
|
{
|
|
|
|
my $strLine = shift;
|
|
|
|
my $strType = shift;
|
|
|
|
my $strExpression = shift;
|
|
|
|
my $strToken = shift;
|
|
|
|
my $bIndex = shift;
|
|
|
|
|
|
|
|
my @stryReplace = ($strLine =~ /$strExpression/g);
|
|
|
|
|
|
|
|
foreach my $strReplace (@stryReplace)
|
|
|
|
{
|
|
|
|
my $iIndex;
|
|
|
|
my $strTypeReplacement;
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strReplacement;
|
2015-05-29 20:39:43 +02:00
|
|
|
|
|
|
|
if (!defined($bIndex) || $bIndex)
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
if (defined($strToken))
|
2015-05-29 20:39:43 +02:00
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
my @stryReplacement = ($strReplace =~ /$strToken/g);
|
|
|
|
|
|
|
|
if (@stryReplacement != 1)
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "'${strToken}' is not a sub-regexp of '${strExpression}' or matches multiple times on '${strReplace}'");
|
|
|
|
}
|
|
|
|
|
|
|
|
$strReplacement = $stryReplacement[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strReplacement = $strReplace;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($$oReplaceHash{$strType}{$strReplacement}))
|
|
|
|
{
|
|
|
|
$iIndex = $$oReplaceHash{$strType}{$strReplacement}{index};
|
2015-05-29 20:39:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!defined($$oReplaceHash{$strType}{index}))
|
|
|
|
{
|
|
|
|
$$oReplaceHash{$strType}{index} = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$iIndex = $$oReplaceHash{$strType}{index}++;
|
2015-06-14 00:25:49 +02:00
|
|
|
$$oReplaceHash{$strType}{$strReplacement}{index} = $iIndex;
|
2015-05-29 20:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$strTypeReplacement = "[${strType}" . (defined($iIndex) ? "-${iIndex}" : '') . ']';
|
|
|
|
|
|
|
|
if (defined($strToken))
|
|
|
|
{
|
|
|
|
$strReplacement = $strReplace;
|
|
|
|
$strReplacement =~ s/$strToken/$strTypeReplacement/;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strReplacement = $strTypeReplacement;
|
|
|
|
}
|
|
|
|
|
|
|
|
$strLine =~ s/$strReplace/$strReplacement/g;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $strLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_ExecuteRegExpAll
|
|
|
|
####################################################################################################################################
|
2015-08-05 18:32:12 +02:00
|
|
|
sub BackRestTestCommon_ExecuteRegExpAll
|
2015-05-29 20:39:43 +02:00
|
|
|
{
|
|
|
|
my $strLine = shift;
|
|
|
|
|
|
|
|
my $strBinPath = dirname(dirname(abs_path($0))) . '/bin';
|
|
|
|
|
2015-08-27 21:55:29 +02:00
|
|
|
$strLine =~ s/$strCommonCommandMain/[BACKREST_BIN]/g;
|
2015-08-29 20:20:46 +02:00
|
|
|
$strLine =~ s/$strCommonCommandRemote/[BACKREST_BIN]/g;
|
2015-06-14 00:25:49 +02:00
|
|
|
$strLine =~ s/$strPgSqlBin/[PGSQL_BIN_PATH]/g;
|
2015-05-29 20:39:43 +02:00
|
|
|
|
|
|
|
my $strTestPath = BackRestTestCommon_TestPathGet();
|
|
|
|
|
|
|
|
if (defined($strTestPath))
|
|
|
|
{
|
|
|
|
$strLine =~ s/$strTestPath/[TEST_PATH]/g;
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'MODIFICATION-TIME', 'lModificationTime = [0-9]+', '[0-9]+$');
|
2015-06-14 00:25:49 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP', 'timestamp"[ ]{0,1}:[ ]{0,1}[0-9]+','[0-9]+$');
|
2015-05-29 20:39:43 +02:00
|
|
|
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'BACKUP-INCR', '[0-9]{8}\-[0-9]{6}F\_[0-9]{8}\-[0-9]{6}I');
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'BACKUP-DIFF', '[0-9]{8}\-[0-9]{6}F\_[0-9]{8}\-[0-9]{6}D');
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'BACKUP-FULL', '[0-9]{8}\-[0-9]{6}F');
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'GROUP', 'strGroup = [^ \n,\[\]]+', '[^ \n,\[\]]+$');
|
2015-06-14 00:25:49 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'GROUP', 'group"[ ]{0,1}:[ ]{0,1}"[^"]+', '[^"]+$');
|
2015-08-29 20:20:46 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'USER', 'strUser = [^ \n,\[\]]+', '[^ \n,\[\]]+$');
|
2015-06-14 00:25:49 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'USER', 'user"[ ]{0,1}:[ ]{0,1}"[^"]+', '[^"]+$');
|
2015-07-07 03:00:48 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'USER', '^db-user=.+$', '[^=]+$');
|
2015-05-29 20:39:43 +02:00
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'PORT', 'db-port=[0-9]+', '[0-9]+$');
|
2015-05-29 20:39:43 +02:00
|
|
|
|
|
|
|
my $strTimestampRegExp = "[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]";
|
|
|
|
|
2015-06-17 17:26:07 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'VERSION',
|
2015-06-22 19:11:07 +02:00
|
|
|
"version[\"]{0,1}[ ]{0,1}[\:\=)]{1}[ ]{0,1}[\"]{0,1}" . BACKREST_VERSION, BACKREST_VERSION . '$');
|
2015-06-14 00:25:49 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP',
|
|
|
|
"timestamp-[a-z-]+[\"]{0,1}[ ]{0,1}[\:\=)]{1}[ ]{0,1}[\"]{0,1}[0-9]+", '[0-9]+$', false);
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP',
|
|
|
|
"start\" : [0-9]{10}", '[0-9]{10}$', false);
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP',
|
|
|
|
"stop\" : [0-9]{10}", '[0-9]{10}$', false);
|
2015-07-07 03:00:48 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'SIZE',
|
|
|
|
"size\"[ ]{0,1}:[ ]{0,1}[0-9]+", '[0-9]+$', false);
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'DELTA',
|
|
|
|
"delta\"[ ]{0,1}:[ ]{0,1}[0-9]+", '[0-9]+$', false);
|
2015-06-14 00:25:49 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP-STR', "est backup timestamp: $strTimestampRegExp",
|
|
|
|
"${strTimestampRegExp}\$", false);
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'CHECKSUM', 'checksum=[\"]{0,1}[0-f]{40}', '[0-f]{40}$', false);
|
|
|
|
|
|
|
|
if (!$bValidWalChecksum)
|
|
|
|
{
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'CHECKSUM', '[0-F]{24}-[0-f]{40}', '[0-f]{40}$', false);
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'DB-SYSTEM-ID',
|
|
|
|
"db-system-id[\"]{0,1}[ ]{0,1}[\:\=)]{1}[ ]{0,1}[0-9]+", '[0-9]+$');
|
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'BACKUP-INFO',
|
|
|
|
"backup-info-[a-z-]+[\"]{0,1}[ ]{0,1}[\:\=)]{1}[ ]{0,1}[0-9]+", '[0-9]+$', false);
|
|
|
|
}
|
2015-05-29 20:39:43 +02:00
|
|
|
|
|
|
|
return $strLine;
|
|
|
|
}
|
|
|
|
|
2014-08-10 22:02:14 +03:00
|
|
|
####################################################################################################################################
|
2014-10-16 02:11:09 +03:00
|
|
|
# BackRestTestCommon_ExecuteEnd
|
2014-08-10 22:02:14 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_ExecuteEnd
|
|
|
|
{
|
|
|
|
my $strTest = shift;
|
|
|
|
my $bSuppressError = shift;
|
2015-01-03 19:56:44 +02:00
|
|
|
my $bShowOutput = shift;
|
2015-01-24 01:28:39 +02:00
|
|
|
my $iExpectedExitStatus = shift;
|
2014-08-10 22:02:14 +03:00
|
|
|
|
|
|
|
# Set defaults
|
|
|
|
$bSuppressError = defined($bSuppressError) ? $bSuppressError : false;
|
2015-01-03 19:56:44 +02:00
|
|
|
$bShowOutput = defined($bShowOutput) ? $bShowOutput : false;
|
2014-07-28 01:13:23 +03:00
|
|
|
|
|
|
|
# Create select objects
|
2014-07-27 21:03:21 +03:00
|
|
|
my $oErrorSelect = IO::Select->new();
|
|
|
|
$oErrorSelect->add($hError);
|
|
|
|
my $oOutSelect = IO::Select->new();
|
|
|
|
$oOutSelect->add($hOut);
|
2014-07-03 02:15:21 +03:00
|
|
|
|
2014-07-28 01:13:23 +03:00
|
|
|
# While the process is running drain the stdout and stderr streams
|
2014-07-27 21:03:21 +03:00
|
|
|
while(waitpid($pId, WNOHANG) == 0)
|
2014-07-03 01:58:38 +03:00
|
|
|
{
|
2014-07-28 01:13:23 +03:00
|
|
|
# Drain the stderr stream
|
2014-07-27 21:03:21 +03:00
|
|
|
if ($oErrorSelect->can_read(.1))
|
2014-07-12 17:26:51 +03:00
|
|
|
{
|
2014-07-27 21:03:21 +03:00
|
|
|
while (my $strLine = readline($hError))
|
|
|
|
{
|
|
|
|
$strErrorLog .= $strLine;
|
|
|
|
}
|
2014-07-12 17:26:51 +03:00
|
|
|
}
|
|
|
|
|
2014-07-28 01:13:23 +03:00
|
|
|
# Drain the stdout stream
|
2014-07-27 21:03:21 +03:00
|
|
|
if ($oOutSelect->can_read(.1))
|
|
|
|
{
|
|
|
|
while (my $strLine = readline($hOut))
|
|
|
|
{
|
|
|
|
$strOutLog .= $strLine;
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
if (defined($strTest) && testCheck($strLine, $strTest))
|
2014-08-10 22:02:14 +03:00
|
|
|
{
|
|
|
|
&log(DEBUG, "Found test ${strTest}");
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-05 19:08:48 +02:00
|
|
|
|
|
|
|
if ($bFullLog)
|
|
|
|
{
|
2015-05-29 20:39:43 +02:00
|
|
|
$strLine =~ s/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]\.[0-9]{3} T[0-9]{2} //;
|
2015-05-05 19:08:48 +02:00
|
|
|
|
2015-06-30 04:07:42 +02:00
|
|
|
if ($strLine !~ /^ TEST/)
|
2015-05-05 19:08:48 +02:00
|
|
|
{
|
2015-05-29 20:39:43 +02:00
|
|
|
$strLine =~ s/^ //;
|
|
|
|
$strLine =~ s/^ //;
|
2015-06-30 04:07:42 +02:00
|
|
|
$strLine =~ s/\r$//;
|
2015-05-29 20:39:43 +02:00
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
$strLine = BackRestTestCommon_ExecuteRegExpAll($strLine);
|
2015-05-05 19:08:48 +02:00
|
|
|
$strFullLog .= $strLine;
|
|
|
|
}
|
|
|
|
}
|
2014-07-27 21:03:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 01:13:23 +03:00
|
|
|
# Check the exit status and output an error if needed
|
2014-07-27 21:03:21 +03:00
|
|
|
my $iExitStatus = ${^CHILD_ERROR_NATIVE} >> 8;
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
if (defined($iExpectedExitStatus) && ($iExitStatus == $iExpectedExitStatus || $bExecuteRemote && $iExitStatus != 0))
|
2015-01-24 01:28:39 +02:00
|
|
|
{
|
|
|
|
return $iExitStatus;
|
|
|
|
}
|
|
|
|
|
2015-03-04 04:21:07 +02:00
|
|
|
if ($iExitStatus != 0 || (defined($iExpectedExitStatus) && $iExitStatus != $iExpectedExitStatus))
|
2014-07-27 21:03:21 +03:00
|
|
|
{
|
2014-10-08 20:54:31 +03:00
|
|
|
if ($bSuppressError)
|
|
|
|
{
|
|
|
|
&log(DEBUG, "suppressed error was ${iExitStatus}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-24 01:28:39 +02:00
|
|
|
confess &log(ERROR, "command '${strCommand}' returned " . $iExitStatus .
|
|
|
|
(defined($iExpectedExitStatus) ? ", but ${iExpectedExitStatus} was expected" : '') . "\n" .
|
2014-10-08 20:54:31 +03:00
|
|
|
($strOutLog ne '' ? "STDOUT:\n${strOutLog}" : '') .
|
|
|
|
($strErrorLog ne '' ? "STDERR:\n${strErrorLog}" : ''));
|
|
|
|
}
|
2014-10-02 17:55:38 +03:00
|
|
|
}
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2015-01-03 19:56:44 +02:00
|
|
|
if ($bShowOutput)
|
|
|
|
{
|
|
|
|
print "output:\n${strOutLog}\n";
|
|
|
|
}
|
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
if (defined($strTest))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "test point ${strTest} was not found");
|
|
|
|
}
|
|
|
|
|
2014-08-10 22:02:14 +03:00
|
|
|
$hError = undef;
|
|
|
|
$hOut = undef;
|
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
return $iExitStatus;
|
2014-08-10 22:02:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2014-10-16 02:11:09 +03:00
|
|
|
# BackRestTestCommon_Execute
|
2014-08-10 22:02:14 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_Execute
|
|
|
|
{
|
|
|
|
my $strCommand = shift;
|
|
|
|
my $bRemote = shift;
|
|
|
|
my $bSuppressError = shift;
|
2015-01-03 19:56:44 +02:00
|
|
|
my $bShowOutput = shift;
|
2015-01-24 01:28:39 +02:00
|
|
|
my $iExpectedExitStatus = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strComment = shift;
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
BackRestTestCommon_ExecuteBegin($strCommand, $bRemote, $strComment);
|
2015-01-24 01:28:39 +02:00
|
|
|
return BackRestTestCommon_ExecuteEnd(undef, $bSuppressError, $bShowOutput, $iExpectedExitStatus);
|
2014-06-22 18:56:01 +03:00
|
|
|
}
|
|
|
|
|
2014-10-16 02:11:09 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_PathCreate
|
|
|
|
#
|
|
|
|
# Create a path and set mode.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_PathCreate
|
|
|
|
{
|
|
|
|
my $strPath = shift;
|
|
|
|
my $strMode = shift;
|
2015-09-02 01:05:10 +02:00
|
|
|
my $bIgnoreExists = shift;
|
2014-10-16 02:11:09 +03:00
|
|
|
|
|
|
|
# Create the path
|
2015-09-02 01:05:10 +02:00
|
|
|
if (!mkdir($strPath))
|
|
|
|
{
|
|
|
|
if (!(defined($bIgnoreExists) && $bIgnoreExists && -e $strPath))
|
|
|
|
{
|
|
|
|
confess "unable to create ${strPath} path";
|
|
|
|
}
|
|
|
|
}
|
2014-10-16 02:11:09 +03:00
|
|
|
|
2015-03-23 23:17:43 +02:00
|
|
|
# Set the mode
|
2014-10-16 02:11:09 +03:00
|
|
|
chmod(oct(defined($strMode) ? $strMode : '0700'), $strPath)
|
|
|
|
or confess 'unable to set mode ${strMode} for ${strPath}';
|
|
|
|
}
|
|
|
|
|
2014-12-21 17:11:17 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_PathMode
|
|
|
|
#
|
|
|
|
# Set mode of an existing path.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_PathMode
|
|
|
|
{
|
|
|
|
my $strPath = shift;
|
|
|
|
my $strMode = shift;
|
|
|
|
|
2015-03-23 23:17:43 +02:00
|
|
|
# Set the mode
|
2014-12-21 17:11:17 +02:00
|
|
|
chmod(oct($strMode), $strPath)
|
|
|
|
or confess 'unable to set mode ${strMode} for ${strPath}';
|
|
|
|
}
|
|
|
|
|
2014-10-16 20:22:34 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_PathRemove
|
|
|
|
#
|
|
|
|
# Remove a path and all subpaths.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_PathRemove
|
|
|
|
{
|
|
|
|
my $strPath = shift;
|
|
|
|
my $bRemote = shift;
|
|
|
|
my $bSuppressError = shift;
|
|
|
|
|
|
|
|
BackRestTestCommon_Execute('rm -rf ' . $strPath, $bRemote, $bSuppressError);
|
|
|
|
|
|
|
|
# remove_tree($strPath, {result => \my $oError});
|
|
|
|
#
|
|
|
|
# if (@$oError)
|
|
|
|
# {
|
|
|
|
# my $strMessage = "error(s) occurred while removing ${strPath}:";
|
|
|
|
#
|
|
|
|
# for my $strFile (@$oError)
|
|
|
|
# {
|
|
|
|
# $strMessage .= "\nunable to remove: " . $strFile;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# confess $strMessage;
|
|
|
|
# }
|
|
|
|
}
|
|
|
|
|
2014-10-16 02:11:09 +03:00
|
|
|
####################################################################################################################################
|
2015-01-22 01:37:49 +02:00
|
|
|
# BackRestTestCommon_PathCopy
|
|
|
|
#
|
|
|
|
# Copy a path.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_PathCopy
|
|
|
|
{
|
|
|
|
my $strSourcePath = shift;
|
|
|
|
my $strDestinationPath = shift;
|
|
|
|
my $bRemote = shift;
|
|
|
|
my $bSuppressError = shift;
|
|
|
|
|
2015-05-07 02:24:34 +02:00
|
|
|
BackRestTestCommon_Execute("cp -RpP ${strSourcePath} ${strDestinationPath}", $bRemote, $bSuppressError);
|
2015-01-22 01:37:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-01-22 17:54:02 +02:00
|
|
|
# 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2014-10-16 02:11:09 +03:00
|
|
|
# BackRestTestCommon_FileCreate
|
|
|
|
#
|
|
|
|
# Create a file specifying content, mode, and time.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_FileCreate
|
|
|
|
{
|
|
|
|
my $strFile = shift;
|
|
|
|
my $strContent = shift;
|
|
|
|
my $lTime = shift;
|
2014-10-18 20:25:20 +03:00
|
|
|
my $strMode = shift;
|
2014-10-16 02:11:09 +03:00
|
|
|
|
|
|
|
# Open the file and save strContent to it
|
|
|
|
my $hFile = shift;
|
|
|
|
|
|
|
|
open($hFile, '>', $strFile)
|
|
|
|
or confess "unable to open ${strFile} for writing";
|
|
|
|
|
|
|
|
syswrite($hFile, $strContent)
|
2014-10-20 18:44:36 +03:00
|
|
|
or confess "unable to write to ${strFile}: $!";
|
2014-10-16 02:11:09 +03:00
|
|
|
|
|
|
|
close($hFile);
|
|
|
|
|
|
|
|
# Set the time
|
|
|
|
if (defined($lTime))
|
|
|
|
{
|
|
|
|
utime($lTime, $lTime, $strFile)
|
|
|
|
or confess 'unable to set time ${lTime} for ${strPath}';
|
|
|
|
}
|
|
|
|
|
2015-03-23 23:17:43 +02:00
|
|
|
# Set the mode
|
2014-10-16 02:11:09 +03:00
|
|
|
chmod(oct(defined($strMode) ? $strMode : '0600'), $strFile)
|
|
|
|
or confess 'unable to set mode ${strMode} for ${strFile}';
|
|
|
|
}
|
|
|
|
|
2014-10-20 18:44:36 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_FileRemove
|
|
|
|
#
|
|
|
|
# Remove a file.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_FileRemove
|
|
|
|
{
|
|
|
|
my $strFile = shift;
|
|
|
|
|
|
|
|
unlink($strFile)
|
|
|
|
or confess "unable to remove ${strFile}: $!";
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
2014-06-22 17:54:31 +03:00
|
|
|
# BackRestTestCommon_Setup
|
2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_Setup
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
2015-07-11 23:16:35 +02:00
|
|
|
my $strExe = shift;
|
2014-08-11 04:22:17 +03:00
|
|
|
my $strTestPathParam = shift;
|
|
|
|
my $strPgSqlBinParam = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $iModuleTestRunOnlyParam = shift;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bDryRunParam = shift;
|
|
|
|
my $bNoCleanupParam = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $bLogForceParam = shift;
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$strCommonBasePath = dirname(dirname(abs_path($0)));
|
2014-07-27 21:03:21 +03:00
|
|
|
|
2014-08-11 04:22:17 +03:00
|
|
|
$strPgSqlBin = $strPgSqlBinParam;
|
|
|
|
|
2014-09-18 18:28:23 +03:00
|
|
|
$strCommonStanza = 'db';
|
2014-06-22 21:51:28 +03:00
|
|
|
$strCommonHost = '127.0.0.1';
|
2014-06-22 17:30:17 +03:00
|
|
|
$strCommonUser = getpwuid($<);
|
|
|
|
$strCommonGroup = getgrgid($();
|
|
|
|
$strCommonUserBackRest = 'backrest';
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2014-08-11 04:22:17 +03:00
|
|
|
if (defined($strTestPathParam))
|
|
|
|
{
|
|
|
|
$strCommonTestPath = $strTestPathParam;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-11 23:16:35 +02:00
|
|
|
$strCommonTestPath = cwd() . "/test";
|
2014-08-11 04:22:17 +03:00
|
|
|
}
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$strCommonDataPath = "${strCommonBasePath}/test/data";
|
2015-03-12 18:15:19 +02:00
|
|
|
$strCommonRepoPath = "${strCommonTestPath}/backrest";
|
|
|
|
$strCommonLocalPath = "${strCommonTestPath}/local";
|
2014-06-22 21:51:28 +03:00
|
|
|
$strCommonDbPath = "${strCommonTestPath}/db";
|
|
|
|
$strCommonDbCommonPath = "${strCommonTestPath}/db/common";
|
2014-09-20 00:51:51 +03:00
|
|
|
$strCommonDbTablespacePath = "${strCommonTestPath}/db/tablespace";
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2015-07-11 23:16:35 +02:00
|
|
|
$strCommonCommandMain = defined($strExe) ? $strExe : $strCommonBasePath . "/bin/../bin/pg_backrest";
|
|
|
|
$bCommandMainSet = defined($strExe) ? true : false;
|
|
|
|
$strCommonCommandRemote = defined($strExe) ? $strExe : "${strCommonBasePath}/bin/pg_backrest";
|
2015-06-18 21:39:30 +02:00
|
|
|
$strCommonCommandRemoteFull = "${strCommonCommandRemote} --stanza=${strCommonStanza}" .
|
|
|
|
" --repo-remote-path=${strCommonRepoPath} --no-config remote";
|
2014-08-11 04:22:17 +03:00
|
|
|
$strCommonCommandPsql = "${strPgSqlBin}/psql -X %option% -h ${strCommonDbPath}";
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2014-06-22 18:56:01 +03:00
|
|
|
$iCommonDbPort = 6543;
|
2015-05-05 19:08:48 +02:00
|
|
|
$iModuleTestRunOnly = $iModuleTestRunOnlyParam;
|
2014-07-16 05:32:41 +03:00
|
|
|
$bDryRun = $bDryRunParam;
|
|
|
|
$bNoCleanup = $bNoCleanupParam;
|
2015-05-05 19:08:48 +02:00
|
|
|
$bLogForce = $bLogForceParam;
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
BackRestTestCommon_Execute($strPgSqlBin . '/postgres --version');
|
|
|
|
|
|
|
|
# Get the Postgres version
|
2015-08-06 22:36:55 +02:00
|
|
|
my $strVersionRegExp = '(devel|((alpha|beta)[0-9]+))$';
|
2015-04-01 21:58:33 +02:00
|
|
|
my @stryVersionToken = split(/ /, $strOutLog);
|
|
|
|
@stryVersionToken = split(/\./, $stryVersionToken[2]);
|
2015-06-14 16:12:36 +02:00
|
|
|
$strCommonDbVersion = $stryVersionToken[0] . '.' . trim($stryVersionToken[1]);
|
|
|
|
|
2015-08-06 22:36:55 +02:00
|
|
|
# Warn if this is a devel/alpha/beta version
|
|
|
|
if ($strCommonDbVersion =~ /$strVersionRegExp/)
|
2015-06-14 16:12:36 +02:00
|
|
|
{
|
2015-08-06 22:36:55 +02:00
|
|
|
my $strDevVersion = $strCommonDbVersion;
|
|
|
|
$strCommonDbVersion =~ s/$strVersionRegExp//;
|
|
|
|
$strDevVersion = substr($strDevVersion, length($strCommonDbVersion));
|
|
|
|
|
|
|
|
&log(WARN, "Testing against ${strCommonDbVersion} ${strDevVersion} version");
|
2015-06-14 16:12:36 +02:00
|
|
|
}
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2015-04-03 04:07:23 +02:00
|
|
|
# Don't run unit tests for unsupported versions
|
2015-08-29 20:20:46 +02:00
|
|
|
my @stryVersionSupport = versionSupport();
|
2015-04-03 04:07:23 +02:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
if ($strCommonDbVersion < $stryVersionSupport[0])
|
2015-04-01 21:58:33 +02:00
|
|
|
{
|
2015-08-29 20:20:46 +02:00
|
|
|
confess "currently only version $stryVersionSupport[0] and up are supported";
|
2015-04-01 21:58:33 +02:00
|
|
|
}
|
2015-06-14 16:12:36 +02:00
|
|
|
|
|
|
|
return true;
|
2015-04-01 21:58:33 +02:00
|
|
|
}
|
|
|
|
|
2015-05-07 02:24:34 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_manifestLoad
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_manifestLoad
|
|
|
|
{
|
|
|
|
my $strFileName = shift;
|
|
|
|
my $bRemote = shift;
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
$bRemote = defined($bRemote) ? $bRemote : false;
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g+x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $oManifest = new BackRest::Manifest($strFileName);
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g-x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $oManifest;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_manifestSave
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_manifestSave
|
|
|
|
{
|
|
|
|
my $strFileName = shift;
|
|
|
|
my $oManifest = shift;
|
|
|
|
my $bRemote = shift;
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
$bRemote = defined($bRemote) ? $bRemote : false;
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g+x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
BackRestTestCommon_Execute("chmod g+w " . $strFileName, $bRemote);
|
|
|
|
}
|
|
|
|
|
|
|
|
$oManifest->save();
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g-w " . $strFileName, $bRemote);
|
|
|
|
BackRestTestCommon_Execute("chmod g-x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_iniLoad
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_iniLoad
|
|
|
|
{
|
|
|
|
my $strFileName = shift;
|
|
|
|
my $oIniRef = shift;
|
|
|
|
my $bRemote = shift;
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
$bRemote = defined($bRemote) ? $bRemote : false;
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g+x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
iniLoad($strFileName, $oIniRef);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g-x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_iniSave
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_iniSave
|
|
|
|
{
|
|
|
|
my $strFileName = shift;
|
|
|
|
my $oIniRef = shift;
|
|
|
|
my $bRemote = shift;
|
2015-06-14 00:25:49 +02:00
|
|
|
my $bChecksum = shift;
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
# Defaults
|
|
|
|
$bRemote = defined($bRemote) ? $bRemote : false;
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g+x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
BackRestTestCommon_Execute("chmod g+w " . $strFileName, $bRemote);
|
|
|
|
}
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Calculate a new checksum if requested
|
|
|
|
if (defined($bChecksum) && $bChecksum)
|
|
|
|
{
|
|
|
|
delete($$oIniRef{&INI_SECTION_BACKREST}{&INI_KEY_CHECKSUM});
|
|
|
|
|
|
|
|
my $oSHA = Digest::SHA->new('sha1');
|
|
|
|
my $oJSON = JSON::PP->new()->canonical()->allow_nonref();
|
|
|
|
$oSHA->add($oJSON->encode($oIniRef));
|
|
|
|
|
|
|
|
$$oIniRef{&INI_SECTION_BACKREST}{&INI_KEY_CHECKSUM} = $oSHA->hexdigest();
|
|
|
|
}
|
|
|
|
|
|
|
|
iniSave($strFileName, $oIniRef);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g-w " . $strFileName, $bRemote);
|
|
|
|
BackRestTestCommon_Execute("chmod g-x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
2014-06-22 17:30:17 +03:00
|
|
|
}
|
|
|
|
|
2015-01-23 02:04:55 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_ConfigRemap
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_ConfigRemap
|
|
|
|
{
|
|
|
|
my $oRemapHashRef = shift;
|
|
|
|
my $oManifestRef = shift;
|
2015-01-23 03:55:16 +02:00
|
|
|
my $bRemote = shift;
|
2015-01-23 02:04:55 +02:00
|
|
|
|
|
|
|
# Create config filename
|
|
|
|
my $strConfigFile = BackRestTestCommon_DbPathGet() . '/pg_backrest.conf';
|
|
|
|
my $strStanza = BackRestTestCommon_StanzaGet();
|
|
|
|
|
|
|
|
# Load Config file
|
|
|
|
my %oConfig;
|
2015-06-14 00:25:49 +02:00
|
|
|
iniLoad($strConfigFile, \%oConfig, true);
|
2015-01-23 02:04:55 +02:00
|
|
|
|
2015-01-23 03:55:16 +02:00
|
|
|
# Load remote config file
|
|
|
|
my %oRemoteConfig;
|
|
|
|
my $strRemoteConfigFile = BackRestTestCommon_TestPathGet() . '/pg_backrest.conf.remote';
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_Execute("mv " . BackRestTestCommon_RepoPathGet() . "/pg_backrest.conf ${strRemoteConfigFile}", true);
|
2015-06-14 00:25:49 +02:00
|
|
|
iniLoad($strRemoteConfigFile, \%oRemoteConfig, true);
|
2015-01-23 03:55:16 +02:00
|
|
|
}
|
|
|
|
|
2015-01-23 02:04:55 +02:00
|
|
|
# Rewrite remap section
|
2015-03-12 18:15:19 +02:00
|
|
|
delete($oConfig{"${strStanza}:restore:tablespace-map"});
|
2015-01-23 02:04:55 +02:00
|
|
|
|
2015-06-21 18:06:13 +02:00
|
|
|
foreach my $strRemap (sort(keys(%$oRemapHashRef)))
|
2015-01-23 02:04:55 +02:00
|
|
|
{
|
2015-01-23 03:11:33 +02:00
|
|
|
my $strRemapPath = ${$oRemapHashRef}{$strRemap};
|
|
|
|
|
2015-01-23 02:04:55 +02:00
|
|
|
if ($strRemap eq 'base')
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oConfig{$strStanza}{'db-path'} = $strRemapPath;
|
2015-06-14 00:25:49 +02:00
|
|
|
${$oManifestRef}{'backup:path'}{base}{&MANIFEST_SUBKEY_PATH} = $strRemapPath;
|
2015-01-23 03:55:16 +02:00
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oRemoteConfig{$strStanza}{'db-path'} = $strRemapPath;
|
2015-01-23 03:55:16 +02:00
|
|
|
}
|
2015-01-23 02:04:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oConfig{"${strStanza}:restore:tablespace-map"}{$strRemap} = $strRemapPath;
|
2015-01-23 03:11:33 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
${$oManifestRef}{'backup:path'}{"tablespace/${strRemap}"}{&MANIFEST_SUBKEY_PATH} = $strRemapPath;
|
|
|
|
${$oManifestRef}{'base:link'}{"pg_tblspc/${strRemap}"}{destination} = $strRemapPath;
|
2015-01-23 02:04:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Resave the config file
|
2015-06-14 00:25:49 +02:00
|
|
|
iniSave($strConfigFile, \%oConfig, true);
|
2015-01-23 03:55:16 +02:00
|
|
|
|
|
|
|
# Load remote config file
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
iniSave($strRemoteConfigFile, \%oRemoteConfig, true);
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_Execute("mv ${strRemoteConfigFile} " . BackRestTestCommon_RepoPathGet() . '/pg_backrest.conf', true);
|
2015-01-23 03:55:16 +02:00
|
|
|
}
|
2015-01-23 02:04:55 +02:00
|
|
|
}
|
2015-03-04 04:21:07 +02:00
|
|
|
|
2015-01-31 20:48:09 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# 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;
|
2015-06-14 00:25:49 +02:00
|
|
|
iniLoad($strConfigFile, \%oConfig, true);
|
2015-01-31 20:48:09 +02:00
|
|
|
|
|
|
|
# Load remote config file
|
|
|
|
my %oRemoteConfig;
|
|
|
|
my $strRemoteConfigFile = BackRestTestCommon_TestPathGet() . '/pg_backrest.conf.remote';
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_Execute("mv " . BackRestTestCommon_RepoPathGet() . "/pg_backrest.conf ${strRemoteConfigFile}", true);
|
2015-06-14 00:25:49 +02:00
|
|
|
iniLoad($strRemoteConfigFile, \%oRemoteConfig, true);
|
2015-01-31 20:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Rewrite remap section
|
2015-04-01 21:58:33 +02:00
|
|
|
delete($oConfig{"${strStanza}:restore:recovery-setting"});
|
2015-01-31 20:48:09 +02:00
|
|
|
|
2015-06-21 18:06:13 +02:00
|
|
|
foreach my $strOption (sort(keys(%$oRecoveryHashRef)))
|
2015-01-31 20:48:09 +02:00
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
$oConfig{"${strStanza}:restore:recovery-setting"}{$strOption} = ${$oRecoveryHashRef}{$strOption};
|
2015-01-31 20:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Resave the config file
|
2015-06-14 00:25:49 +02:00
|
|
|
iniSave($strConfigFile, \%oConfig, true);
|
2015-01-31 20:48:09 +02:00
|
|
|
|
|
|
|
# Load remote config file
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
iniSave($strRemoteConfigFile, \%oRemoteConfig, true);
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_Execute("mv ${strRemoteConfigFile} " . BackRestTestCommon_RepoPathGet() . '/pg_backrest.conf', true);
|
2015-01-31 20:48:09 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-23 02:04:55 +02:00
|
|
|
|
2014-06-22 21:51:28 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestCommon_ConfigCreate
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestCommon_ConfigCreate
|
|
|
|
{
|
2014-06-22 23:05:00 +03:00
|
|
|
my $strLocal = shift;
|
2014-06-22 21:51:28 +03:00
|
|
|
my $strRemote = shift;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bCompress = shift;
|
|
|
|
my $bChecksum = shift;
|
|
|
|
my $bHardlink = shift;
|
|
|
|
my $iThreadMax = shift;
|
2015-03-12 18:15:19 +02:00
|
|
|
my $bArchiveAsync = shift;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bCompressAsync = shift;
|
2014-06-24 01:54:00 +03:00
|
|
|
|
2014-06-22 21:51:28 +03:00
|
|
|
my %oParamHash;
|
|
|
|
|
2014-07-17 03:07:50 +03:00
|
|
|
if (defined($strRemote))
|
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
$oParamHash{'global:command'}{'[comment]'} = 'backrest command';
|
2015-03-25 00:50:14 +02:00
|
|
|
$oParamHash{'global:command'}{'cmd-remote'} = $strCommonCommandRemote;
|
2014-07-17 03:07:50 +03:00
|
|
|
}
|
|
|
|
|
2014-12-24 01:52:38 +02:00
|
|
|
if (defined($strRemote) && $strRemote eq BACKUP)
|
2014-06-22 21:51:28 +03:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{'global:backup'}{'backup-host'} = $strCommonHost;
|
|
|
|
$oParamHash{'global:backup'}{'backup-user'} = $strCommonUserBackRest;
|
2014-06-22 21:51:28 +03:00
|
|
|
}
|
2014-12-24 01:52:38 +02:00
|
|
|
elsif (defined($strRemote) && $strRemote eq DB)
|
2014-06-22 21:51:28 +03:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{$strCommonStanza}{'db-host'} = $strCommonHost;
|
|
|
|
$oParamHash{$strCommonStanza}{'db-user'} = $strCommonUser;
|
2014-06-22 23:05:00 +03:00
|
|
|
}
|
2014-06-24 01:54:00 +03:00
|
|
|
|
2015-05-26 17:36:03 +02:00
|
|
|
$oParamHash{'global:log'}{'[comment]'} = 'file and console log settings';
|
2015-04-01 21:58:33 +02:00
|
|
|
$oParamHash{'global:log'}{'log-level-console'} = 'debug';
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{'global:log'}{'log-level-file'} = 'trace';
|
2014-07-17 03:07:50 +03:00
|
|
|
|
2015-05-26 17:36:03 +02:00
|
|
|
$oParamHash{'global:general'}{'[comment]'} = 'general settings for all operations';
|
|
|
|
|
2014-12-24 01:52:38 +02:00
|
|
|
if ($strLocal eq BACKUP)
|
2014-10-19 23:30:16 +03:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{'global:general'}{'repo-path'} = $strCommonRepoPath;
|
2014-10-19 23:30:16 +03:00
|
|
|
}
|
2014-12-24 01:52:38 +02:00
|
|
|
elsif ($strLocal eq DB)
|
2014-06-22 23:05:00 +03:00
|
|
|
{
|
2015-03-25 00:50:14 +02:00
|
|
|
$oParamHash{'global:general'}{'repo-path'} = $strCommonLocalPath;
|
|
|
|
|
2014-07-17 03:07:50 +03:00
|
|
|
if (defined($strRemote))
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{'global:general'}{'repo-remote-path'} = $strCommonRepoPath;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oParamHash{'global:general'}{'repo-path'} = $strCommonRepoPath;
|
2014-07-17 03:07:50 +03:00
|
|
|
}
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
if ($bArchiveAsync)
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
2015-05-26 17:36:03 +02:00
|
|
|
$oParamHash{'global:archive'}{'[comment]'} = 'WAL archive settings';
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{'global:archive'}{'archive-async'} = 'y';
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
2014-06-22 23:05:00 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess "invalid local type ${strLocal}";
|
|
|
|
}
|
2014-06-22 21:51:28 +03:00
|
|
|
|
2015-03-25 00:50:14 +02:00
|
|
|
if (defined($iThreadMax) && $iThreadMax > 1)
|
|
|
|
{
|
|
|
|
$oParamHash{'global:general'}{'thread-max'} = $iThreadMax;
|
|
|
|
}
|
|
|
|
|
2014-12-24 01:52:38 +02:00
|
|
|
if (($strLocal eq BACKUP) || ($strLocal eq DB && !defined($strRemote)))
|
2014-07-17 03:07:50 +03:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
# $oParamHash{"${strCommonStanza}:command"}{'[comment]'} = 'cluster-specific command options';
|
|
|
|
# $oParamHash{"${strCommonStanza}:command"}{'cmd-psql-option'} = "--port=${iCommonDbPort}";
|
2014-12-24 01:52:38 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
if (defined($bHardlink) && $bHardlink)
|
2014-12-24 01:52:38 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{'global:backup'}{'hardlink'} = 'y';
|
2014-12-24 01:52:38 +02:00
|
|
|
}
|
2015-05-22 20:49:14 +02:00
|
|
|
|
|
|
|
$oParamHash{'global:backup'}{'archive-copy'} = 'y';
|
2015-05-26 18:26:59 +02:00
|
|
|
$oParamHash{'global:backup'}{'start-fast'} = 'y';
|
2014-07-17 03:07:50 +03:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
if (defined($bCompress) && !$bCompress)
|
|
|
|
{
|
2015-03-23 21:45:25 +02:00
|
|
|
$oParamHash{'global:general'}{'compress'} = 'n';
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
|
|
|
|
2015-05-26 17:36:03 +02:00
|
|
|
# Stanza settings
|
|
|
|
$oParamHash{$strCommonStanza}{'[comment]'} = "cluster-specific settings";
|
2015-03-12 18:15:19 +02:00
|
|
|
$oParamHash{$strCommonStanza}{'db-path'} = $strCommonDbCommonPath;
|
2015-08-05 18:32:12 +02:00
|
|
|
$oParamHash{$strCommonStanza}{'db-port'} = $iCommonDbPort;
|
|
|
|
$oParamHash{$strCommonStanza}{'db-socket-path'} = BackRestTestCommon_DbPathGet();
|
2014-06-24 01:54:00 +03:00
|
|
|
|
2015-05-26 17:36:03 +02:00
|
|
|
# Comments
|
|
|
|
if (defined($oParamHash{'global:backup'}))
|
|
|
|
{
|
|
|
|
$oParamHash{'global:backup'}{'[comment]'} = "backup settings";
|
|
|
|
}
|
|
|
|
|
2014-06-29 17:53:39 +03:00
|
|
|
# Write out the configuration file
|
|
|
|
my $strFile = BackRestTestCommon_TestPathGet() . '/pg_backrest.conf';
|
2015-06-14 00:25:49 +02:00
|
|
|
iniSave($strFile, \%oParamHash, true);
|
2014-06-24 01:54:00 +03:00
|
|
|
|
2014-06-29 17:53:39 +03:00
|
|
|
# Move the configuration file based on local
|
|
|
|
if ($strLocal eq 'db')
|
|
|
|
{
|
|
|
|
rename($strFile, BackRestTestCommon_DbPathGet() . '/pg_backrest.conf')
|
|
|
|
or die "unable to move ${strFile} to " . BackRestTestCommon_DbPathGet() . '/pg_backrest.conf path';
|
|
|
|
}
|
|
|
|
elsif ($strLocal eq 'backup' && !defined($strRemote))
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
rename($strFile, BackRestTestCommon_RepoPathGet() . '/pg_backrest.conf')
|
|
|
|
or die "unable to move ${strFile} to " . BackRestTestCommon_RepoPathGet() . '/pg_backrest.conf path';
|
2014-06-29 17:53:39 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_Execute("mv ${strFile} " . BackRestTestCommon_RepoPathGet() . '/pg_backrest.conf', true);
|
2014-06-29 17:53:39 +03:00
|
|
|
}
|
2014-06-22 21:51:28 +03:00
|
|
|
}
|
|
|
|
|
2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# Get Methods
|
|
|
|
####################################################################################################################################
|
2014-08-11 04:22:17 +03:00
|
|
|
sub BackRestTestCommon_PgSqlBinPathGet
|
|
|
|
{
|
|
|
|
return $strPgSqlBin;
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_StanzaGet
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
return $strCommonStanza;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:36:59 +02:00
|
|
|
sub BackRestTestCommon_CommandPsqlGet
|
|
|
|
{
|
|
|
|
return $strCommonCommandPsql;
|
|
|
|
}
|
|
|
|
|
2014-06-22 21:51:28 +03:00
|
|
|
sub BackRestTestCommon_CommandMainGet
|
|
|
|
{
|
|
|
|
return $strCommonCommandMain;
|
|
|
|
}
|
|
|
|
|
2015-05-08 00:37:25 +02:00
|
|
|
sub BackRestTestCommon_CommandMainAbsGet
|
|
|
|
{
|
2015-07-11 23:16:35 +02:00
|
|
|
if ($bCommandMainSet)
|
|
|
|
{
|
|
|
|
return BackRestTestCommon_CommandMainGet()
|
|
|
|
}
|
|
|
|
|
|
|
|
return abs_path(BackRestTestCommon_CommandMainGet());
|
2015-05-08 00:37:25 +02:00
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_CommandRemoteGet
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
return $strCommonCommandRemote;
|
|
|
|
}
|
|
|
|
|
2015-06-18 21:39:30 +02:00
|
|
|
sub BackRestTestCommon_CommandRemoteFullGet
|
|
|
|
{
|
|
|
|
return $strCommonCommandRemoteFull;
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_HostGet
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
return $strCommonHost;
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_UserGet
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
return $strCommonUser;
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_GroupGet
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
return $strCommonGroup;
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_UserBackRestGet
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
return $strCommonUserBackRest;
|
|
|
|
}
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
sub BackRestTestCommon_BasePathGet
|
|
|
|
{
|
|
|
|
return $strCommonBasePath;
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
sub BackRestTestCommon_TestPathGet
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
return $strCommonTestPath;
|
|
|
|
}
|
|
|
|
|
2014-07-13 16:13:19 +03:00
|
|
|
sub BackRestTestCommon_DataPathGet
|
|
|
|
{
|
|
|
|
return $strCommonDataPath;
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
sub BackRestTestCommon_RepoPathGet
|
2014-06-22 21:51:28 +03:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
return $strCommonRepoPath;
|
2014-06-22 21:51:28 +03:00
|
|
|
}
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
sub BackRestTestCommon_LocalPathGet
|
2014-06-29 17:53:39 +03:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
return $strCommonLocalPath;
|
2014-06-29 17:53:39 +03:00
|
|
|
}
|
|
|
|
|
2014-06-22 21:51:28 +03:00
|
|
|
sub BackRestTestCommon_DbPathGet
|
|
|
|
{
|
|
|
|
return $strCommonDbPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub BackRestTestCommon_DbCommonPathGet
|
|
|
|
{
|
2015-01-23 03:11:33 +02:00
|
|
|
my $iIndex = shift;
|
|
|
|
|
|
|
|
return $strCommonDbCommonPath . (defined($iIndex) ? "-${iIndex}" : '');
|
2014-06-22 21:51:28 +03:00
|
|
|
}
|
|
|
|
|
2014-09-20 00:51:51 +03:00
|
|
|
sub BackRestTestCommon_DbTablespacePathGet
|
|
|
|
{
|
2015-01-23 03:11:33 +02:00
|
|
|
my $iTablespace = shift;
|
|
|
|
my $iIndex = shift;
|
|
|
|
|
|
|
|
return $strCommonDbTablespacePath . (defined($iTablespace) ? "/ts${iTablespace}" . (defined($iIndex) ? "-${iIndex}" : '') : '');
|
2014-09-20 00:51:51 +03:00
|
|
|
}
|
|
|
|
|
2014-06-22 18:56:01 +03:00
|
|
|
sub BackRestTestCommon_DbPortGet
|
|
|
|
{
|
|
|
|
return $iCommonDbPort;
|
|
|
|
}
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
sub BackRestTestCommon_DbVersion
|
|
|
|
{
|
|
|
|
return $strCommonDbVersion;
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:30:17 +03:00
|
|
|
1;
|