You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-11-06 08:49:29 +02:00
Working on unit tests for archiving.
This commit is contained in:
@@ -162,11 +162,11 @@ my %oConfig;
|
||||
tie %oConfig, 'Config::IniFiles', (-file => $strConfigFile) or die "Unable to find config file";
|
||||
|
||||
####################################################################################################################################
|
||||
# ARCHIVE-LOCAL Command !!! This should become archive-push with no hostname
|
||||
# ARCHIVE-PUSH Command
|
||||
####################################################################################################################################
|
||||
if ($strOperation eq "archive-local")
|
||||
if ($strOperation eq "archive-push")
|
||||
{
|
||||
# archive-local command must have three arguments
|
||||
# archive-push command must have three arguments
|
||||
if (@ARGV != 3)
|
||||
{
|
||||
die "not enough arguments - show usage";
|
||||
|
||||
96
test/test.pl
96
test/test.pl
@@ -4,6 +4,7 @@
|
||||
use DBI;
|
||||
use IPC::System::Simple qw(capture);
|
||||
use Config::IniFiles;
|
||||
use File::Find;
|
||||
|
||||
sub trim
|
||||
{
|
||||
@@ -57,8 +58,8 @@ sub pg_start
|
||||
|
||||
sub pg_password_set
|
||||
{
|
||||
local($strPgBinPath, $strPath, $strUser) = @_;
|
||||
my $strCommand = "$strPgBinPath/psql --port=6000 -c \"alter user $strUser with password 'password'\" postgres";
|
||||
local($strPgBinPath, $strPath, $strUser, $strPort) = @_;
|
||||
my $strCommand = "$strPgBinPath/psql --port=$strPort -c \"alter user $strUser with password 'password'\" postgres";
|
||||
|
||||
execute($strCommand);
|
||||
}
|
||||
@@ -66,7 +67,7 @@ sub pg_password_set
|
||||
sub pg_stop
|
||||
{
|
||||
local($strPgBinPath, $strPath) = @_;
|
||||
my $strCommand = "$strPgBinPath/pg_ctl stop -D $strPath -w -s";
|
||||
my $strCommand = "$strPgBinPath/pg_ctl stop -D $strPath -w -s -m fast";
|
||||
|
||||
execute($strCommand);
|
||||
}
|
||||
@@ -91,6 +92,58 @@ sub pg_execute
|
||||
print(" ... complete\n\n");
|
||||
}
|
||||
|
||||
sub archive_command_build
|
||||
{
|
||||
my $strBackRestBinPath = shift;
|
||||
my $strDestinationPath = shift;
|
||||
my $bCompression = shift;
|
||||
my $bChecksum = shift;
|
||||
|
||||
my $strCommand = "$strBackRestBinPath/pg_backrest.pl archive-push --config=$strBackRestBinPath/pg_backrest.conf";
|
||||
|
||||
if (!$bCompression)
|
||||
{
|
||||
$strCommand .= " --no-compression"
|
||||
}
|
||||
|
||||
if (!$bChecksum)
|
||||
{
|
||||
$strCommand .= " --no-checksum"
|
||||
}
|
||||
|
||||
return $strCommand . " %p $strDestinationPath/%f";
|
||||
}
|
||||
|
||||
sub wait_for_file
|
||||
{
|
||||
my $strDir = shift;
|
||||
my $strRegEx = shift;
|
||||
my $iSeconds = shift;
|
||||
|
||||
my $lTime = time();
|
||||
my $hDir;
|
||||
|
||||
while ($lTime > time() - $iSeconds)
|
||||
{
|
||||
opendir $hDir, $strDir or die "Could not open dir: $!\n";
|
||||
my @stryFile = grep(/$strRegEx/i, readdir $hDir);
|
||||
close $hDir;
|
||||
|
||||
if (scalar @stryFile == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
# if (glob($strFile))
|
||||
# {
|
||||
# return;
|
||||
# }
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
die "could not find $strDir/$strRegEx after $iSeconds second(s)";
|
||||
}
|
||||
|
||||
my $strUser = execute('whoami');
|
||||
|
||||
my $strTestPath = "/Users/dsteele/test";
|
||||
@@ -99,10 +152,10 @@ my $strArchiveDir = "archive";
|
||||
my $strBackupDir = "backup";
|
||||
|
||||
my $strPgBinPath = "/Library/PostgreSQL/9.3/bin";
|
||||
my $strPort = "6000";
|
||||
my $strPort = "6001";
|
||||
|
||||
my $strBackRestBinPath = "/Users/dsteele/pg_backrest";
|
||||
my $strArchiveCommand = "$strBackRestBinPath/pg_backrest.pl archive-local %p $strTestPath/$strArchiveDir/%f";
|
||||
my $strArchiveCommand = archive_command_build($strBackRestBinPath, "$strTestPath/$strArchiveDir", 1, 1);
|
||||
|
||||
################################################################################
|
||||
# Stop the current test cluster if it is running and create a new one
|
||||
@@ -117,12 +170,12 @@ if ($@)
|
||||
pg_drop($strTestPath);
|
||||
pg_create($strPgBinPath, $strTestPath, $strDbDir, $strArchiveDir, $strBackupDir);
|
||||
pg_start($strPgBinPath, "$strTestPath/$strDbDir/common", $strPort, $strArchiveCommand);
|
||||
pg_password_set($strPgBinPath, "$strTestPath/$strDbDir/common", $strUser);
|
||||
pg_password_set($strPgBinPath, "$strTestPath/$strDbDir/common", $strUser, $strPort);
|
||||
|
||||
################################################################################
|
||||
# Connect and start tests
|
||||
################################################################################
|
||||
$dbh = DBI->connect("dbi:Pg:dbname=postgres;port=6000;host=127.0.0.1", $strUser,
|
||||
$dbh = DBI->connect("dbi:Pg:dbname=postgres;port=$strPort;host=127.0.0.1", $strUser,
|
||||
'password', {AutoCommit => 1});
|
||||
|
||||
pg_execute($dbh, "create tablespace ts1 location '$strTestPath/$strDbDir/ts1'");
|
||||
@@ -135,15 +188,42 @@ pg_execute($dbh, "create table test_ts2 (id int) tablespace ts1");
|
||||
pg_execute($dbh, "insert into test values (1)");
|
||||
pg_execute($dbh, "select pg_switch_xlog()");
|
||||
|
||||
# Test for archive log file 000000010000000000000001
|
||||
wait_for_file("$strTestPath/$strArchiveDir", "^000000010000000000000001-([a-f]|[0-9]){40}\\.gz\$", 5);
|
||||
|
||||
# Turn off log compression for the next test
|
||||
$dbh->disconnect();
|
||||
pg_stop($strPgBinPath, "$strTestPath/$strDbDir/common");
|
||||
$strArchiveCommand = archive_command_build($strBackRestBinPath, "$strTestPath/$strArchiveDir", 0, 1);
|
||||
pg_start($strPgBinPath, "$strTestPath/$strDbDir/common", $strPort, $strArchiveCommand);
|
||||
$dbh = DBI->connect("dbi:Pg:dbname=postgres;port=$strPort;host=127.0.0.1", $strUser,
|
||||
'password', {AutoCommit => 1});
|
||||
|
||||
# Write another value into the test table
|
||||
pg_execute($dbh, "insert into test values (2)");
|
||||
pg_execute($dbh, "select pg_switch_xlog()");
|
||||
|
||||
# Test for archive log file 000000010000000000000002
|
||||
wait_for_file("$strTestPath/$strArchiveDir", "^000000010000000000000002-([a-f]|[0-9]){40}\$", 5);
|
||||
|
||||
# Turn off log compression and checksum for the next test
|
||||
$dbh->disconnect();
|
||||
pg_stop($strPgBinPath, "$strTestPath/$strDbDir/common");
|
||||
$strArchiveCommand = archive_command_build($strBackRestBinPath, "$strTestPath/$strArchiveDir", 0, 0);
|
||||
pg_start($strPgBinPath, "$strTestPath/$strDbDir/common", $strPort, $strArchiveCommand);
|
||||
$dbh = DBI->connect("dbi:Pg:dbname=postgres;port=$strPort;host=127.0.0.1", $strUser,
|
||||
'password', {AutoCommit => 1});
|
||||
|
||||
# Write another value into the test table
|
||||
pg_execute($dbh, "insert into test values (3)");
|
||||
pg_execute($dbh, "select pg_switch_xlog()");
|
||||
|
||||
# Test for archive log file 000000010000000000000003
|
||||
wait_for_file("$strTestPath/$strArchiveDir", "^000000010000000000000003\$", 5);
|
||||
|
||||
$dbh->disconnect();
|
||||
|
||||
################################################################################
|
||||
# Stop the server
|
||||
################################################################################
|
||||
#pg_stop($strPgBinPath, "$strTestPath/$strDbDir/common");
|
||||
pg_stop($strPgBinPath, "$strTestPath/$strDbDir/common");
|
||||
|
||||
Reference in New Issue
Block a user