1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-06 08:49:29 +02:00

Working on getting backup running again.

This commit is contained in:
David Steele
2014-06-22 10:30:17 -04:00
parent 0dd15dd216
commit 0b597d8da9
9 changed files with 475 additions and 118 deletions

View File

@@ -15,11 +15,11 @@ use Getopt::Long;
use Config::IniFiles; use Config::IniFiles;
use Carp; use Carp;
use lib dirname($0); use lib dirname($0) . "/../lib";
use pg_backrest_utility; use BackRest::Utility;
use pg_backrest_file; use BackRest::File;
use pg_backrest_backup; use BackRest::Backup;
use pg_backrest_db; use BackRest::Db;
#################################################################################################################################### ####################################################################################################################################
# Operation constants - basic operations that are allowed in backrest # Operation constants - basic operations that are allowed in backrest
@@ -56,14 +56,15 @@ use constant
CONFIG_KEY_ARCHIVE_REQUIRED => "archive-required", CONFIG_KEY_ARCHIVE_REQUIRED => "archive-required",
CONFIG_KEY_ARCHIVE_MAX_MB => "archive-max-mb", CONFIG_KEY_ARCHIVE_MAX_MB => "archive-max-mb",
CONFIG_KEY_START_FAST => "start_fast", CONFIG_KEY_START_FAST => "start_fast",
CONFIG_KEY_COMPRESS_ASYNC => "compress-async",
CONFIG_KEY_LEVEL_FILE => "level-file", CONFIG_KEY_LEVEL_FILE => "level-file",
CONFIG_KEY_LEVEL_CONSOLE => "level-console", CONFIG_KEY_LEVEL_CONSOLE => "level-console",
CONFIG_KEY_COMPRESS => "compress", CONFIG_KEY_COMPRESS => "compress",
CONFIG_KEY_COMPRESS_ASYNC => "compress-async", CONFIG_KEY_CHECKSUM => "checksum",
CONFIG_KEY_DECOMPRESS => "decompress", CONFIG_KEY_PSQL => "psql",
CONFIG_KEY_PSQL => "psql" CONFIG_KEY_REMOTE => "remote"
}; };
#################################################################################################################################### ####################################################################################################################################
@@ -203,6 +204,45 @@ if (!defined($strStanza))
log_level_set(uc(config_load(CONFIG_SECTION_LOG, CONFIG_KEY_LEVEL_FILE, true, "INFO")), log_level_set(uc(config_load(CONFIG_SECTION_LOG, CONFIG_KEY_LEVEL_FILE, true, "INFO")),
uc(config_load(CONFIG_SECTION_LOG, CONFIG_KEY_LEVEL_CONSOLE, true, "ERROR"))); uc(config_load(CONFIG_SECTION_LOG, CONFIG_KEY_LEVEL_CONSOLE, true, "ERROR")));
####################################################################################################################################
# DETERMINE IF THERE IS A REMOTE
####################################################################################################################################
my $strRemote;
# First check if backup is remote
if (defined(config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST)))
{
$strRemote = REMOTE_BACKUP;
}
# Else check if db is remote
elsif (defined(config_load(CONFIG_SECTION_STANZA, CONFIG_KEY_HOST)))
{
# Don't allow both sides to be remote
if (defined($strRemote))
{
confess &log(ERROR, 'db and backup cannot both be configured as remote');
}
$strRemote = REMOTE_DB;
}
else
{
$strRemote = REMOTE_NONE;
}
# Create the remote object
my $oRemote;
if ($strRemote ne REMOTE_NONE)
{
my $oRemote = BackRest::Remote->new
(
strHost => config_load($strRemote eq REMOTE_DB ? CONFIG_SECTION_STANZA : CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST, true),
strUser => config_load($strRemote eq REMOTE_DB ? CONFIG_SECTION_STANZA : CONFIG_SECTION_BACKUP, CONFIG_KEY_USER, true),
strCommand => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_REMOTE, true)
);
}
#################################################################################################################################### ####################################################################################################################################
# ARCHIVE-GET Command # ARCHIVE-GET Command
#################################################################################################################################### ####################################################################################################################################
@@ -224,12 +264,9 @@ if ($strOperation eq OP_ARCHIVE_GET)
my $oFile = pg_backrest_file->new my $oFile = pg_backrest_file->new
( (
strStanza => $strStanza, strStanza => $strStanza,
bNoCompression => true, strRemote => $strRemote,
strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER), oRemote => $oRemote,
strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST), strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true)
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
strCommand => $0,
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, true)
); );
# Init the backup object # Init the backup object
@@ -302,15 +339,15 @@ if ($strOperation eq OP_ARCHIVE_PUSH || $strOperation eq OP_ARCHIVE_PULL)
# Run file_init_archive - this is the minimal config needed to run archiving # Run file_init_archive - this is the minimal config needed to run archiving
my $oFile = pg_backrest_file->new my $oFile = pg_backrest_file->new
( (
strStanza => $strStanza, # strStanza => $strStanza,
bNoCompression => !$bCompress, # bNoCompression => !$bCompress,
strBackupUser => config_load($strSection, CONFIG_KEY_USER), # strBackupUser => config_load($strSection, CONFIG_KEY_USER),
strBackupHost => config_load($strSection, CONFIG_KEY_HOST), # strBackupHost => config_load($strSection, CONFIG_KEY_HOST),
strBackupPath => config_load($strSection, CONFIG_KEY_PATH, true), # strBackupPath => config_load($strSection, CONFIG_KEY_PATH, true),
strCommand => $0, # strCommand => $0,
strCommandChecksum => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_CHECKSUM, $bChecksum), # strCommandChecksum => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_CHECKSUM, $bChecksum),
strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress), # strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress) # strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress)
); );
backup_init backup_init
@@ -373,15 +410,15 @@ if ($strOperation eq OP_ARCHIVE_PUSH || $strOperation eq OP_ARCHIVE_PULL)
# Run file_init_archive - this is the minimal config needed to run archive pulling # Run file_init_archive - this is the minimal config needed to run archive pulling
my $oFile = pg_backrest_file->new my $oFile = pg_backrest_file->new
( (
strStanza => $strStanza, # strStanza => $strStanza,
bNoCompression => !$bCompress, # bNoCompression => !$bCompress,
strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER), # strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER),
strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST), # strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST),
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true), # strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
strCommand => $0, # strCommand => $0,
strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress), # strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress), # strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress),
strLockPath => $strLockPath # strLockPath => $strLockPath
); );
backup_init backup_init
@@ -414,12 +451,12 @@ if ($strOperation eq OP_ARCHIVE_PUSH || $strOperation eq OP_ARCHIVE_PULL)
# Run file_init_archive - this is the minimal config needed to run archive pulling !!! need to close the old file # Run file_init_archive - this is the minimal config needed to run archive pulling !!! need to close the old file
my $oFile = pg_backrest_file->new my $oFile = pg_backrest_file->new
( (
strStanza => $strStanza, # strStanza => $strStanza,
bNoCompression => false, # bNoCompression => false,
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true), # strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
strCommand => $0, # strCommand => $0,
strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress), # strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress) # strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress)
); );
backup_init backup_init
@@ -461,6 +498,12 @@ log_file_set(config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true) . "/log/$
#################################################################################################################################### ####################################################################################################################################
# GET MORE CONFIG INFO # GET MORE CONFIG INFO
#################################################################################################################################### ####################################################################################################################################
# Make sure backup and expire operations happen on the db side
if ($strRemote eq backup)
{
confess &log(ERROR, 'backup and expire operations must run on the backup host');
}
# Set the backup type # Set the backup type
if (!defined($strType)) if (!defined($strType))
{ {
@@ -496,17 +539,9 @@ if (!lock_file_create($strLockPath))
my $oFile = pg_backrest_file->new my $oFile = pg_backrest_file->new
( (
strStanza => $strStanza, strStanza => $strStanza,
bNoCompression => !$bCompress, strRemote => $strRemote,
strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER), oRemote => $oRemote,
strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST), strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true)
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
strDbUser => config_load(CONFIG_SECTION_STANZA, CONFIG_KEY_USER),
strDbHost => config_load(CONFIG_SECTION_STANZA, CONFIG_KEY_HOST),
strCommand => $0,
strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress),
strCommandPsql => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_PSQL),
strLockPath => $strLockPath
); );
my $oDb = pg_backrest_db->new my $oDb = pg_backrest_db->new

View File

@@ -1,9 +1,5 @@
[global:command] [global:command]
backrest_command= remote=/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl
#compress=pigz --rsyncable --best --stdout %file% # Ubuntu Linux
compress=/usr/bin/gzip --stdout %file%
decompress=/usr/bin/gzip -dc %file%
#checksum=sha1sum %file% | awk '{print $1}' # Ubuntu Linux
psql=/Library/PostgreSQL/9.3/bin/psql -X %option% psql=/Library/PostgreSQL/9.3/bin/psql -X %option%
[global:log] [global:log]

View File

@@ -16,9 +16,9 @@ use Storable;
use Thread::Queue; use Thread::Queue;
use lib dirname($0); use lib dirname($0);
use pg_backrest_utility; use BackRest::Utility;
use pg_backrest_file; use BackRest::File;
use pg_backrest_db; use BackRest::Db;
use Exporter qw(import); use Exporter qw(import);

View File

@@ -14,7 +14,7 @@ use File::Basename;
use IPC::System::Simple qw(capture); use IPC::System::Simple qw(capture);
use lib dirname($0); use lib dirname($0);
use pg_backrest_utility; use BackRest::Utility;
# Command strings # Command strings
has strCommandPsql => (is => 'bare'); # PSQL command has strCommandPsql => (is => 'bare'); # PSQL command
@@ -105,7 +105,7 @@ sub tablespace_map_get
#################################################################################################################################### ####################################################################################################################################
# VERSION_GET # VERSION_GET
#################################################################################################################################### ####################################################################################################################################
sub version_get sub db_version_get
{ {
my $self = shift; my $self = shift;

View File

@@ -34,6 +34,8 @@ our @EXPORT = qw(PATH_ABSOLUTE PATH_DB PATH_DB_ABSOLUTE PATH_BACKUP PATH_BACKUP_
COMMAND_ERR_LINK_READ COMMAND_ERR_PATH_MISSING COMMAND_ERR_PATH_CREATE COMMAND_ERR_PARAM COMMAND_ERR_LINK_READ COMMAND_ERR_PATH_MISSING COMMAND_ERR_PATH_CREATE COMMAND_ERR_PARAM
PIPE_STDIN PIPE_STDOUT PIPE_STDERR PIPE_STDIN PIPE_STDOUT PIPE_STDERR
REMOTE_DB REMOTE_BACKUP REMOTE_NONE
OP_FILE_LIST OP_FILE_EXISTS OP_FILE_HASH OP_FILE_REMOVE OP_FILE_MANIFEST OP_FILE_COMPRESS OP_FILE_LIST OP_FILE_EXISTS OP_FILE_HASH OP_FILE_REMOVE OP_FILE_MANIFEST OP_FILE_COMPRESS
OP_FILE_MOVE OP_FILE_COPY OP_FILE_COPY_OUT OP_FILE_COPY_IN OP_FILE_PATH_CREATE); OP_FILE_MOVE OP_FILE_COPY OP_FILE_COPY_OUT OP_FILE_COPY_IN OP_FILE_PATH_CREATE);
@@ -86,22 +88,14 @@ use constant
PATH_BACKUP_ARCHIVE => 'backup:archive' PATH_BACKUP_ARCHIVE => 'backup:archive'
}; };
####################################################################################################################################
# File copy block size constant
####################################################################################################################################
use constant
{
BLOCK_SIZE => 8192
};
#################################################################################################################################### ####################################################################################################################################
# STD Pipe Constants # STD Pipe Constants
#################################################################################################################################### ####################################################################################################################################
use constant use constant
{ {
PIPE_STDIN => "<STDIN>", PIPE_STDIN => '<STDIN>',
PIPE_STDOUT => "<STDOUT>", PIPE_STDOUT => '<STDOUT>',
PIPE_STDERR => "<STDERR>" PIPE_STDERR => '<STDERR>'
}; };
#################################################################################################################################### ####################################################################################################################################
@@ -110,7 +104,8 @@ use constant
use constant use constant
{ {
REMOTE_DB => PATH_DB, REMOTE_DB => PATH_DB,
REMOTE_BACKUP => PATH_BACKUP REMOTE_BACKUP => PATH_BACKUP,
REMOTE_NONE => 'none'
}; };
#################################################################################################################################### ####################################################################################################################################
@@ -118,17 +113,17 @@ use constant
#################################################################################################################################### ####################################################################################################################################
use constant use constant
{ {
OP_FILE_LIST => "File->list", OP_FILE_LIST => 'File->list',
OP_FILE_EXISTS => "File->exists", OP_FILE_EXISTS => 'File->exists',
OP_FILE_HASH => "File->hash", OP_FILE_HASH => 'File->hash',
OP_FILE_REMOVE => "File->remove", OP_FILE_REMOVE => 'File->remove',
OP_FILE_MANIFEST => "File->manifest", OP_FILE_MANIFEST => 'File->manifest',
OP_FILE_COMPRESS => "File->compress", OP_FILE_COMPRESS => 'File->compress',
OP_FILE_MOVE => "File->move", OP_FILE_MOVE => 'File->move',
OP_FILE_COPY => "File->copy", OP_FILE_COPY => 'File->copy',
OP_FILE_COPY_OUT => "File->copy_out", OP_FILE_COPY_OUT => 'File->copy_out',
OP_FILE_COPY_IN => "File->copy_in", OP_FILE_COPY_IN => 'File->copy_in',
OP_FILE_PATH_CREATE => "File->path_create" OP_FILE_PATH_CREATE => 'File->path_create'
}; };
#################################################################################################################################### ####################################################################################################################################
@@ -225,7 +220,7 @@ sub path_get
if ($bTemp && !($strType eq PATH_BACKUP_ARCHIVE || $strType eq PATH_BACKUP_TMP || $bAbsolute)) if ($bTemp && !($strType eq PATH_BACKUP_ARCHIVE || $strType eq PATH_BACKUP_TMP || $bAbsolute))
{ {
confess &log(ASSERT, "temp file not supported on path " . $strType); confess &log(ASSERT, 'temp file not supported on path ' . $strType);
} }
# Get absolute path # Get absolute path
@@ -233,7 +228,7 @@ sub path_get
{ {
if (defined($bTemp) && $bTemp) if (defined($bTemp) && $bTemp)
{ {
return $strFile . ".backrest.tmp"; return $strFile . '.backrest.tmp';
} }
return $strFile; return $strFile;
@@ -242,7 +237,7 @@ sub path_get
# Make sure the base backup path is defined (since all other path types are backup) # Make sure the base backup path is defined (since all other path types are backup)
if (!defined($self->{strBackupPath})) if (!defined($self->{strBackupPath}))
{ {
confess &log(ASSERT, "\$strBackupPath not yet defined"); confess &log(ASSERT, 'strBackupPath not defined');
} }
# Get base backup path # Get base backup path
@@ -254,7 +249,7 @@ sub path_get
# Make sure the cluster is defined # Make sure the cluster is defined
if (!defined($self->{strStanza})) if (!defined($self->{strStanza}))
{ {
confess &log(ASSERT, "\$strStanza not yet defined"); confess &log(ASSERT, 'strStanza not defined');
} }
# Get the backup tmp path # Get the backup tmp path

View File

@@ -0,0 +1,238 @@
#!/usr/bin/perl
####################################################################################################################################
# BackupTest.pl - Unit Tests for BackRest::Backup
####################################################################################################################################
use BackRestTest::BackupTest;
####################################################################################################################################
# Perl includes
####################################################################################################################################
use strict;
use warnings;
use english;
use Carp;
use File::Basename;
use Cwd 'abs_path';
use File::stat;
use Fcntl ':mode';
use Scalar::Util 'blessed';
use lib dirname($0) . "/../lib";
use BackRest::Utility;
use BackRest::File;
use BackRest::Remote;
use Exporter qw(import);
our @EXPORT = qw(BackRestFileTest);
# my $strTestPath;
# my $strHost;
# my $strUserBackRest;
####################################################################################################################################
# BackRestFileBackupSetup
####################################################################################################################################
sub BackRestFileBackupSetup
{
my $bPrivate = shift;
my $bDropOnly = shift;
my $strTestPath = BackRestCommonTestPathGet();
# Remove the backrest private directory
if (-e "${strTestPath}/private")
{
system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/private'");
}
# Remove the test directory
system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path';
if (!defined($bDropOnly) || !$bDropOnly)
{
# Create the test directory
mkdir($strTestPath, oct("0770")) or confess "Unable to create test directory";
# Create the backrest private directory
if (defined($bPrivate) && $bPrivate)
{
system("ssh backrest\@${strHost} 'mkdir -m 700 ${strTestPath}/private'") == 0 or die 'unable to create test/private path';
}
}
}
####################################################################################################################################
# BackRestBackupTest
####################################################################################################################################
sub BackRestBackupTest
{
my $strStanza = shift;
my $strCommand = shift;
my $strHost = shift;
my $strUser = shift;
my $strGroup = shift;
my $strUserBackRest = shift;
my $strTestPath = shift;
my $strTest = shift;
# If no test was specified, then run them all
if (!defined($strTest))
{
$strTest = 'all';
}
# Setup test variables
my $iRun;
my $strTestPath = BackRestCommonTestPathGet();
my $strStanza = BackRestCommonStanzaGet();
# my $strHost = "127.0.0.1";
# my $strUser = getpwuid($<);
# my $strGroup = getgrgid($();
# $strUserBackRest = 'backrest';
# Print test parameters
&log(INFO, "Testing with test_path = ${strTestPath}, host = ${strHost}, user = ${strUser}, group = ${strGroup}");
&log(INFO, "FILE MODULE ********************************************************************");
system("ssh backrest\@${strHost} 'rm -rf ${strTestPath}/private'");
#-------------------------------------------------------------------------------------------------------------------------------
# Create remote
#-------------------------------------------------------------------------------------------------------------------------------
my $oRemote = BackRest::Remote->new
(
strHost => BackRestCommonHostGet(),
strUser => BackRestCommonUserGet(),
strCommand => $strCommand,
);
# #-------------------------------------------------------------------------------------------------------------------------------
# # Test path_create()
# #-------------------------------------------------------------------------------------------------------------------------------
# if ($strTest eq 'all' || $strTest eq 'path_create')
# {
# $iRun = 0;
#
# &log(INFO, "Test File->path_create()\n");
#
# # Loop through local/remote
# for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
# {
# # Create the file object
# my $oFile = (BackRest::File->new
# (
# strStanza => "db",
# strBackupPath => ${strTestPath},
# strRemote => $bRemote ? 'backup' : undef,
# oRemote => $bRemote ? $oRemote : undef
# ))->clone();
#
# # Loop through exists (does the paren path exist?)
# for (my $bExists = 0; $bExists <= 1; $bExists++)
# {
# # Loop through exists (does the paren path exist?)
# for (my $bError = 0; $bError <= 1; $bError++)
# {
# # Loop through permission (permission will be set on true)
# for (my $bPermission = 0; $bPermission <= $bExists; $bPermission++)
# {
# my $strPathType = PATH_BACKUP_CLUSTER;
#
# $iRun++;
#
# &log(INFO, "run ${iRun} - " .
# "remote ${bRemote}, exists ${bExists}, error ${bError}, permission ${bPermission}");
#
# # Setup test directory
# BackRestFileTestSetup($bError);
#
# mkdir("$strTestPath/backup") or confess "Unable to create test/backup directory";
# mkdir("$strTestPath/backup/db") or confess "Unable to create test/backup/db directory";
#
# my $strPath = "path";
# my $strPermission;
#
# # If permission then set one (other than the default)
# if ($bPermission)
# {
# $strPermission = "0700";
#
# # # Make sure that we are not testing with the default permission
# # if ($strPermission eq $oFile->{strDefaultPathPermission})
# # {
# # confess 'cannot set test permission ${strPermission} equal to default permission' .
# # $oFile->{strDefaultPathPermission};
# # }
# }
#
# # If not exists then set the path to something bogus
# if ($bError)
# {
# $strPath = "${strTestPath}/private/path";
# $strPathType = PATH_BACKUP_ABSOLUTE;
# }
# elsif (!$bExists)
# {
# $strPath = "error/path";
# }
#
# # Execute in eval to catch errors
# my $bErrorExpected = !$bExists || $bError;
#
# eval
# {
# $oFile->path_create($strPathType, $strPath, $strPermission);
# };
#
# # Check for errors
# if ($@)
# {
# # Ignore errors if the path did not exist
# if ($bErrorExpected)
# {
# next;
# }
#
# confess "error raised: " . $@ . "\n";
# }
#
# if ($bErrorExpected)
# {
# confess 'error was expected';
# }
#
# # Make sure the path was actually created
# my $strPathCheck = $oFile->path_get($strPathType, $strPath);
#
# unless (-e $strPathCheck)
# {
# confess "path was not created";
# }
#
# # Check that the permissions were set correctly
# my $oStat = lstat($strPathCheck);
#
# if (!defined($oStat))
# {
# confess "unable to stat ${strPathCheck}";
# }
#
# if ($bPermission)
# {
# if ($strPermission ne sprintf("%04o", S_IMODE($oStat->mode)))
# {
# confess "permissions were not set to {$strPermission}";
# }
# }
# }
# }
# }
# }
# }
#
# BackRestFileTestSetup(false, true);
}
1;

View File

@@ -0,0 +1,82 @@
#!/usr/bin/perl
####################################################################################################################################
# CommonTest.pm - Common globals used for testing
####################################################################################################################################
package BackRestTest::CommonTest;
####################################################################################################################################
# Perl includes
####################################################################################################################################
use strict;
use warnings;
use english;
use Carp;
use File::Basename;
use Cwd 'abs_path';
use Exporter qw(import);
our @EXPORT = qw(BackRestCommonTestSetup BackRestCommonStanzaGet BackRestCommonCommandRemoteGet BackRestCommonHostGet
BackRestCommonUserGet BackRestCommonGroupGet BackRestCommonUserBackRestGet BackRestCommonTestPathGet);
my $strCommonStanza;
my $strCommonCommandRemote;
my $strCommonHost;
my $strCommonUser;
my $strCommonGroup;
my $strCommonUserBackRest;
my $strCommonTestPath;
####################################################################################################################################
# BackRestCommonTestSetup
####################################################################################################################################
sub BackRestCommonTestSetup
{
$strCommonStanza = "db";
$strCommonCommandRemote = "/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl";
$strCommonHost = "127.0.0.1";
$strCommonUser = getpwuid($<);
$strCommonGroup = getgrgid($();
$strCommonUserBackRest = 'backrest';
$strCommonTestPath = dirname(abs_path($0)) . "/test";
}
####################################################################################################################################
# Get Methods
####################################################################################################################################
sub BackRestCommonStanzaGet
{
return $strCommonStanza;
}
sub BackRestCommonCommandRemoteGet
{
return $strCommonCommandRemote;
}
sub BackRestCommonHostGet
{
return $strCommonHost;
}
sub BackRestCommonUserGet
{
return $strCommonUser;
}
sub BackRestCommonGroupGet
{
return $strCommonGroup;
}
sub BackRestCommonUserBackRestGet
{
return $strCommonUserBackRest;
}
sub BackRestCommonTestPathGet
{
return $strCommonTestPath;
}
1;

View File

@@ -2,6 +2,7 @@
#################################################################################################################################### ####################################################################################################################################
# FileTest.pl - Unit Tests for BackRest::File # FileTest.pl - Unit Tests for BackRest::File
#################################################################################################################################### ####################################################################################################################################
package BackRestTest::FileTest;
#################################################################################################################################### ####################################################################################################################################
# Perl includes # Perl includes
@@ -17,6 +18,9 @@ use File::stat;
use Fcntl ':mode'; use Fcntl ':mode';
use Scalar::Util 'blessed'; use Scalar::Util 'blessed';
#use lib dirname($0) . "/../lib";
use BackRestTest::CommonTest;
use lib dirname($0) . "/../lib"; use lib dirname($0) . "/../lib";
use BackRest::Utility; use BackRest::Utility;
use BackRest::File; use BackRest::File;
@@ -25,9 +29,9 @@ use BackRest::Remote;
use Exporter qw(import); use Exporter qw(import);
our @EXPORT = qw(BackRestFileTest); our @EXPORT = qw(BackRestFileTest);
my $strTestPath; # my $strTestPath;
my $strHost; # my $strHost;
my $strUserBackRest; # my $strUserBackRest;
#################################################################################################################################### ####################################################################################################################################
# BackRestFileTestSetup # BackRestFileTestSetup
@@ -37,6 +41,10 @@ sub BackRestFileTestSetup
my $bPrivate = shift; my $bPrivate = shift;
my $bDropOnly = shift; my $bDropOnly = shift;
my $strTestPath = BackRestCommonTestPathGet();
my $strUserBackRest = BackRestCommonUserBackRestGet();
my $strHost = BackRestCommonHostGet();
# Remove the backrest private directory # Remove the backrest private directory
if (-e "${strTestPath}/private") if (-e "${strTestPath}/private")
{ {
@@ -72,32 +80,27 @@ sub BackRestFileTest
$strTest = 'all'; $strTest = 'all';
} }
# Setup test paths # Setup test variables
$strTestPath = dirname(abs_path($0)) . "/test";
my $iRun; my $iRun;
my $strTestPath = BackRestCommonTestPathGet();
my $strStanza = BackRestCommonStanzaGet();
my $strUser = BackRestCommonUserGet();
my $strGroup = BackRestCommonGroupGet();
my $strStanza = "db"; # $strHost = "127.0.0.1";
my $strCommand = "/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl"; # $strUserBackRest = 'backrest';
$strHost = "127.0.0.1";
my $strUser = getpwuid($<);
my $strGroup = getgrgid($();
$strUserBackRest = 'backrest';
# Print test parameters # Print test parameters
&log(INFO, "Testing with test_path = ${strTestPath}, host = ${strHost}, user = ${strUser}, group = ${strGroup}");
&log(INFO, "FILE MODULE ********************************************************************"); &log(INFO, "FILE MODULE ********************************************************************");
system("ssh backrest\@${strHost} 'rm -rf ${strTestPath}/private'");
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------
# Create remote # Create remote
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------
my $oRemote = BackRest::Remote->new my $oRemote = BackRest::Remote->new
( (
strHost => $strHost, strHost => BackRestCommonHostGet(),
strUser => $strUser, strUser => $strUser,
strCommand => $strCommand, strCommand => BackRestCommonCommandRemoteGet(),
); );
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------
@@ -115,8 +118,8 @@ sub BackRestFileTest
# Create the file object # Create the file object
my $oFile = (BackRest::File->new my $oFile = (BackRest::File->new
( (
strStanza => "db", strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
))->clone(); ))->clone();
@@ -239,8 +242,8 @@ sub BackRestFileTest
# Create the file object # Create the file object
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => "db", strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
); );
@@ -339,8 +342,8 @@ sub BackRestFileTest
# Create the file object # Create the file object
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => "db", strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
); );
@@ -444,8 +447,8 @@ sub BackRestFileTest
# Create the file object # Create the file object
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => "db", strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
); );
@@ -588,8 +591,8 @@ sub BackRestFileTest
# Create the file object # Create the file object
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => "db", strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
); );
@@ -715,7 +718,7 @@ sub BackRestFileTest
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => $strStanza, strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
); );
@@ -820,7 +823,7 @@ sub BackRestFileTest
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => $strStanza, strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
); );
@@ -902,7 +905,7 @@ sub BackRestFileTest
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => $strStanza, strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $bRemote ? 'backup' : undef, strRemote => $bRemote ? 'backup' : undef,
oRemote => $bRemote ? $oRemote : undef oRemote => $bRemote ? $oRemote : undef
); );
@@ -1001,8 +1004,8 @@ sub BackRestFileTest
# Create the file object # Create the file object
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => "db", strStanza => $strStanza,
strBackupPath => ${strTestPath}, strBackupPath => $strTestPath,
strRemote => $strRemote, strRemote => $strRemote,
oRemote => $bBackupRemote || $bDbRemote ? $oRemote : undef oRemote => $bBackupRemote || $bDbRemote ? $oRemote : undef
); );

View File

@@ -14,7 +14,11 @@ use File::Basename;
use Getopt::Long; use Getopt::Long;
use Carp; use Carp;
use lib dirname($0) . "/../lib";
use BackRest::Utility;
use lib dirname($0) . "/lib"; use lib dirname($0) . "/lib";
use BackRestTest::CommonTest;
use BackRestTest::FileTest; use BackRestTest::FileTest;
#################################################################################################################################### ####################################################################################################################################
@@ -43,6 +47,8 @@ if ($strModuleTest ne 'all' && $strModule eq 'all')
confess "--module must be provided for test \"${strModuleTest}\""; confess "--module must be provided for test \"${strModuleTest}\"";
} }
BackRestCommonTestSetup();
#################################################################################################################################### ####################################################################################################################################
# Clean whitespace # Clean whitespace
#################################################################################################################################### ####################################################################################################################################
@@ -78,6 +84,8 @@ if (!$bMatch)
#################################################################################################################################### ####################################################################################################################################
# Runs tests # Runs tests
#################################################################################################################################### ####################################################################################################################################
#&log(INFO, "Testing with test_path = ${strTestPath}, host = ${strHost}, user = ${strUser}, group = ${strGroup}");
if ($strModule eq 'all' || $strModule eq "file") if ($strModule eq 'all' || $strModule eq "file")
{ {
BackRestFileTest($strModuleTest); BackRestFileTest($strModuleTest);