mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Working on getting backup running again.
This commit is contained in:
parent
0dd15dd216
commit
0b597d8da9
@ -15,11 +15,11 @@ use Getopt::Long;
|
||||
use Config::IniFiles;
|
||||
use Carp;
|
||||
|
||||
use lib dirname($0);
|
||||
use pg_backrest_utility;
|
||||
use pg_backrest_file;
|
||||
use pg_backrest_backup;
|
||||
use pg_backrest_db;
|
||||
use lib dirname($0) . "/../lib";
|
||||
use BackRest::Utility;
|
||||
use BackRest::File;
|
||||
use BackRest::Backup;
|
||||
use BackRest::Db;
|
||||
|
||||
####################################################################################################################################
|
||||
# Operation constants - basic operations that are allowed in backrest
|
||||
@ -56,14 +56,15 @@ use constant
|
||||
CONFIG_KEY_ARCHIVE_REQUIRED => "archive-required",
|
||||
CONFIG_KEY_ARCHIVE_MAX_MB => "archive-max-mb",
|
||||
CONFIG_KEY_START_FAST => "start_fast",
|
||||
CONFIG_KEY_COMPRESS_ASYNC => "compress-async",
|
||||
|
||||
CONFIG_KEY_LEVEL_FILE => "level-file",
|
||||
CONFIG_KEY_LEVEL_CONSOLE => "level-console",
|
||||
|
||||
CONFIG_KEY_COMPRESS => "compress",
|
||||
CONFIG_KEY_COMPRESS_ASYNC => "compress-async",
|
||||
CONFIG_KEY_DECOMPRESS => "decompress",
|
||||
CONFIG_KEY_PSQL => "psql"
|
||||
CONFIG_KEY_CHECKSUM => "checksum",
|
||||
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")),
|
||||
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
|
||||
####################################################################################################################################
|
||||
@ -224,12 +264,9 @@ if ($strOperation eq OP_ARCHIVE_GET)
|
||||
my $oFile = pg_backrest_file->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
bNoCompression => true,
|
||||
strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER),
|
||||
strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST),
|
||||
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
|
||||
strCommand => $0,
|
||||
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, true)
|
||||
strRemote => $strRemote,
|
||||
oRemote => $oRemote,
|
||||
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true)
|
||||
);
|
||||
|
||||
# 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
|
||||
my $oFile = pg_backrest_file->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
bNoCompression => !$bCompress,
|
||||
strBackupUser => config_load($strSection, CONFIG_KEY_USER),
|
||||
strBackupHost => config_load($strSection, CONFIG_KEY_HOST),
|
||||
strBackupPath => config_load($strSection, CONFIG_KEY_PATH, true),
|
||||
strCommand => $0,
|
||||
strCommandChecksum => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_CHECKSUM, $bChecksum),
|
||||
strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
|
||||
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress)
|
||||
# strStanza => $strStanza,
|
||||
# bNoCompression => !$bCompress,
|
||||
# strBackupUser => config_load($strSection, CONFIG_KEY_USER),
|
||||
# strBackupHost => config_load($strSection, CONFIG_KEY_HOST),
|
||||
# strBackupPath => config_load($strSection, CONFIG_KEY_PATH, true),
|
||||
# strCommand => $0,
|
||||
# strCommandChecksum => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_CHECKSUM, $bChecksum),
|
||||
# strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
|
||||
# strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress)
|
||||
);
|
||||
|
||||
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
|
||||
my $oFile = pg_backrest_file->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
bNoCompression => !$bCompress,
|
||||
strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER),
|
||||
strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST),
|
||||
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
|
||||
strCommand => $0,
|
||||
strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
|
||||
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress),
|
||||
strLockPath => $strLockPath
|
||||
# strStanza => $strStanza,
|
||||
# bNoCompression => !$bCompress,
|
||||
# strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER),
|
||||
# strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST),
|
||||
# strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
|
||||
# strCommand => $0,
|
||||
# strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
|
||||
# strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress),
|
||||
# strLockPath => $strLockPath
|
||||
);
|
||||
|
||||
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
|
||||
my $oFile = pg_backrest_file->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
bNoCompression => false,
|
||||
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
|
||||
strCommand => $0,
|
||||
strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
|
||||
strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress)
|
||||
# strStanza => $strStanza,
|
||||
# bNoCompression => false,
|
||||
# strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true),
|
||||
# strCommand => $0,
|
||||
# strCommandCompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_COMPRESS, $bCompress),
|
||||
# strCommandDecompress => config_load(CONFIG_SECTION_COMMAND, CONFIG_KEY_DECOMPRESS, $bCompress)
|
||||
);
|
||||
|
||||
backup_init
|
||||
@ -461,6 +498,12 @@ log_file_set(config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true) . "/log/$
|
||||
####################################################################################################################################
|
||||
# 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
|
||||
if (!defined($strType))
|
||||
{
|
||||
@ -496,17 +539,9 @@ if (!lock_file_create($strLockPath))
|
||||
my $oFile = pg_backrest_file->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
bNoCompression => !$bCompress,
|
||||
strBackupUser => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_USER),
|
||||
strBackupHost => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST),
|
||||
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
|
||||
strRemote => $strRemote,
|
||||
oRemote => $oRemote,
|
||||
strBackupPath => config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true)
|
||||
);
|
||||
|
||||
my $oDb = pg_backrest_db->new
|
||||
|
@ -1,9 +1,5 @@
|
||||
[global:command]
|
||||
backrest_command=
|
||||
#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
|
||||
remote=/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl
|
||||
psql=/Library/PostgreSQL/9.3/bin/psql -X %option%
|
||||
|
||||
[global:log]
|
||||
|
@ -16,9 +16,9 @@ use Storable;
|
||||
use Thread::Queue;
|
||||
|
||||
use lib dirname($0);
|
||||
use pg_backrest_utility;
|
||||
use pg_backrest_file;
|
||||
use pg_backrest_db;
|
||||
use BackRest::Utility;
|
||||
use BackRest::File;
|
||||
use BackRest::Db;
|
||||
|
||||
use Exporter qw(import);
|
||||
|
||||
|
@ -14,7 +14,7 @@ use File::Basename;
|
||||
use IPC::System::Simple qw(capture);
|
||||
|
||||
use lib dirname($0);
|
||||
use pg_backrest_utility;
|
||||
use BackRest::Utility;
|
||||
|
||||
# Command strings
|
||||
has strCommandPsql => (is => 'bare'); # PSQL command
|
||||
@ -105,7 +105,7 @@ sub tablespace_map_get
|
||||
####################################################################################################################################
|
||||
# VERSION_GET
|
||||
####################################################################################################################################
|
||||
sub version_get
|
||||
sub db_version_get
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
|
@ -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
|
||||
|
||||
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_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'
|
||||
};
|
||||
|
||||
####################################################################################################################################
|
||||
# File copy block size constant
|
||||
####################################################################################################################################
|
||||
use constant
|
||||
{
|
||||
BLOCK_SIZE => 8192
|
||||
};
|
||||
|
||||
####################################################################################################################################
|
||||
# STD Pipe Constants
|
||||
####################################################################################################################################
|
||||
use constant
|
||||
{
|
||||
PIPE_STDIN => "<STDIN>",
|
||||
PIPE_STDOUT => "<STDOUT>",
|
||||
PIPE_STDERR => "<STDERR>"
|
||||
PIPE_STDIN => '<STDIN>',
|
||||
PIPE_STDOUT => '<STDOUT>',
|
||||
PIPE_STDERR => '<STDERR>'
|
||||
};
|
||||
|
||||
####################################################################################################################################
|
||||
@ -110,7 +104,8 @@ use constant
|
||||
use constant
|
||||
{
|
||||
REMOTE_DB => PATH_DB,
|
||||
REMOTE_BACKUP => PATH_BACKUP
|
||||
REMOTE_BACKUP => PATH_BACKUP,
|
||||
REMOTE_NONE => 'none'
|
||||
};
|
||||
|
||||
####################################################################################################################################
|
||||
@ -118,17 +113,17 @@ use constant
|
||||
####################################################################################################################################
|
||||
use constant
|
||||
{
|
||||
OP_FILE_LIST => "File->list",
|
||||
OP_FILE_EXISTS => "File->exists",
|
||||
OP_FILE_HASH => "File->hash",
|
||||
OP_FILE_REMOVE => "File->remove",
|
||||
OP_FILE_MANIFEST => "File->manifest",
|
||||
OP_FILE_COMPRESS => "File->compress",
|
||||
OP_FILE_MOVE => "File->move",
|
||||
OP_FILE_COPY => "File->copy",
|
||||
OP_FILE_COPY_OUT => "File->copy_out",
|
||||
OP_FILE_COPY_IN => "File->copy_in",
|
||||
OP_FILE_PATH_CREATE => "File->path_create"
|
||||
OP_FILE_LIST => 'File->list',
|
||||
OP_FILE_EXISTS => 'File->exists',
|
||||
OP_FILE_HASH => 'File->hash',
|
||||
OP_FILE_REMOVE => 'File->remove',
|
||||
OP_FILE_MANIFEST => 'File->manifest',
|
||||
OP_FILE_COMPRESS => 'File->compress',
|
||||
OP_FILE_MOVE => 'File->move',
|
||||
OP_FILE_COPY => 'File->copy',
|
||||
OP_FILE_COPY_OUT => 'File->copy_out',
|
||||
OP_FILE_COPY_IN => 'File->copy_in',
|
||||
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))
|
||||
{
|
||||
confess &log(ASSERT, "temp file not supported on path " . $strType);
|
||||
confess &log(ASSERT, 'temp file not supported on path ' . $strType);
|
||||
}
|
||||
|
||||
# Get absolute path
|
||||
@ -233,7 +228,7 @@ sub path_get
|
||||
{
|
||||
if (defined($bTemp) && $bTemp)
|
||||
{
|
||||
return $strFile . ".backrest.tmp";
|
||||
return $strFile . '.backrest.tmp';
|
||||
}
|
||||
|
||||
return $strFile;
|
||||
@ -242,7 +237,7 @@ sub path_get
|
||||
# Make sure the base backup path is defined (since all other path types are backup)
|
||||
if (!defined($self->{strBackupPath}))
|
||||
{
|
||||
confess &log(ASSERT, "\$strBackupPath not yet defined");
|
||||
confess &log(ASSERT, 'strBackupPath not defined');
|
||||
}
|
||||
|
||||
# Get base backup path
|
||||
@ -254,7 +249,7 @@ sub path_get
|
||||
# Make sure the cluster is defined
|
||||
if (!defined($self->{strStanza}))
|
||||
{
|
||||
confess &log(ASSERT, "\$strStanza not yet defined");
|
||||
confess &log(ASSERT, 'strStanza not defined');
|
||||
}
|
||||
|
||||
# Get the backup tmp path
|
||||
|
238
test/lib/BackRestTest/BackupTest.pm
Executable file
238
test/lib/BackRestTest/BackupTest.pm
Executable 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;
|
82
test/lib/BackRestTest/CommonTest.pm
Executable file
82
test/lib/BackRestTest/CommonTest.pm
Executable 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;
|
@ -2,6 +2,7 @@
|
||||
####################################################################################################################################
|
||||
# FileTest.pl - Unit Tests for BackRest::File
|
||||
####################################################################################################################################
|
||||
package BackRestTest::FileTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -17,6 +18,9 @@ use File::stat;
|
||||
use Fcntl ':mode';
|
||||
use Scalar::Util 'blessed';
|
||||
|
||||
#use lib dirname($0) . "/../lib";
|
||||
use BackRestTest::CommonTest;
|
||||
|
||||
use lib dirname($0) . "/../lib";
|
||||
use BackRest::Utility;
|
||||
use BackRest::File;
|
||||
@ -25,9 +29,9 @@ use BackRest::Remote;
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw(BackRestFileTest);
|
||||
|
||||
my $strTestPath;
|
||||
my $strHost;
|
||||
my $strUserBackRest;
|
||||
# my $strTestPath;
|
||||
# my $strHost;
|
||||
# my $strUserBackRest;
|
||||
|
||||
####################################################################################################################################
|
||||
# BackRestFileTestSetup
|
||||
@ -37,6 +41,10 @@ sub BackRestFileTestSetup
|
||||
my $bPrivate = shift;
|
||||
my $bDropOnly = shift;
|
||||
|
||||
my $strTestPath = BackRestCommonTestPathGet();
|
||||
my $strUserBackRest = BackRestCommonUserBackRestGet();
|
||||
my $strHost = BackRestCommonHostGet();
|
||||
|
||||
# Remove the backrest private directory
|
||||
if (-e "${strTestPath}/private")
|
||||
{
|
||||
@ -72,32 +80,27 @@ sub BackRestFileTest
|
||||
$strTest = 'all';
|
||||
}
|
||||
|
||||
# Setup test paths
|
||||
$strTestPath = dirname(abs_path($0)) . "/test";
|
||||
# Setup test variables
|
||||
my $iRun;
|
||||
my $strTestPath = BackRestCommonTestPathGet();
|
||||
my $strStanza = BackRestCommonStanzaGet();
|
||||
my $strUser = BackRestCommonUserGet();
|
||||
my $strGroup = BackRestCommonGroupGet();
|
||||
|
||||
my $strStanza = "db";
|
||||
my $strCommand = "/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl";
|
||||
$strHost = "127.0.0.1";
|
||||
my $strUser = getpwuid($<);
|
||||
my $strGroup = getgrgid($();
|
||||
$strUserBackRest = 'backrest';
|
||||
# $strHost = "127.0.0.1";
|
||||
# $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 => $strHost,
|
||||
strHost => BackRestCommonHostGet(),
|
||||
strUser => $strUser,
|
||||
strCommand => $strCommand,
|
||||
strCommand => BackRestCommonCommandRemoteGet(),
|
||||
);
|
||||
|
||||
#-------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -115,8 +118,8 @@ sub BackRestFileTest
|
||||
# Create the file object
|
||||
my $oFile = (BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupPath => ${strTestPath},
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
))->clone();
|
||||
@ -239,8 +242,8 @@ sub BackRestFileTest
|
||||
# Create the file object
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupPath => ${strTestPath},
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
@ -339,8 +342,8 @@ sub BackRestFileTest
|
||||
# Create the file object
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupPath => ${strTestPath},
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
@ -444,8 +447,8 @@ sub BackRestFileTest
|
||||
# Create the file object
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupPath => ${strTestPath},
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
@ -588,8 +591,8 @@ sub BackRestFileTest
|
||||
# Create the file object
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupPath => ${strTestPath},
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
@ -715,7 +718,7 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => ${strTestPath},
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
@ -820,7 +823,7 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => ${strTestPath},
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
@ -902,7 +905,7 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => ${strTestPath},
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
@ -1001,8 +1004,8 @@ sub BackRestFileTest
|
||||
# Create the file object
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupPath => ${strTestPath},
|
||||
strStanza => $strStanza,
|
||||
strBackupPath => $strTestPath,
|
||||
strRemote => $strRemote,
|
||||
oRemote => $bBackupRemote || $bDbRemote ? $oRemote : undef
|
||||
);
|
||||
|
@ -14,7 +14,11 @@ use File::Basename;
|
||||
use Getopt::Long;
|
||||
use Carp;
|
||||
|
||||
use lib dirname($0) . "/../lib";
|
||||
use BackRest::Utility;
|
||||
|
||||
use lib dirname($0) . "/lib";
|
||||
use BackRestTest::CommonTest;
|
||||
use BackRestTest::FileTest;
|
||||
|
||||
####################################################################################################################################
|
||||
@ -43,6 +47,8 @@ if ($strModuleTest ne 'all' && $strModule eq 'all')
|
||||
confess "--module must be provided for test \"${strModuleTest}\"";
|
||||
}
|
||||
|
||||
BackRestCommonTestSetup();
|
||||
|
||||
####################################################################################################################################
|
||||
# Clean whitespace
|
||||
####################################################################################################################################
|
||||
@ -78,6 +84,8 @@ if (!$bMatch)
|
||||
####################################################################################################################################
|
||||
# Runs tests
|
||||
####################################################################################################################################
|
||||
#&log(INFO, "Testing with test_path = ${strTestPath}, host = ${strHost}, user = ${strUser}, group = ${strGroup}");
|
||||
|
||||
if ($strModule eq 'all' || $strModule eq "file")
|
||||
{
|
||||
BackRestFileTest($strModuleTest);
|
||||
|
Loading…
Reference in New Issue
Block a user