You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Cleanup.
This commit is contained in:
@ -25,6 +25,7 @@ use BackRest::Exception;
|
||||
use BackRest::Utility;
|
||||
use BackRest::Remote;
|
||||
|
||||
# Exports
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw(PATH_ABSOLUTE PATH_DB PATH_DB_ABSOLUTE PATH_BACKUP PATH_BACKUP_ABSOLUTE
|
||||
PATH_BACKUP_CLUSTER PATH_BACKUP_TMP PATH_BACKUP_ARCHIVE
|
||||
@ -37,7 +38,6 @@ our @EXPORT = qw(PATH_ABSOLUTE PATH_DB PATH_DB_ABSOLUTE PATH_BACKUP PATH_BACKUP_
|
||||
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);
|
||||
|
||||
|
||||
# Extension and permissions
|
||||
has strCompressExtension => (is => 'ro', default => 'gz');
|
||||
has strDefaultPathPermission => (is => 'bare', default => '0750');
|
||||
@ -51,7 +51,6 @@ has strRemote => (is => 'bare'); # Remote type (db or backup)
|
||||
has oRemote => (is => 'bare'); # Remote object
|
||||
|
||||
has strBackupPath => (is => 'bare'); # Backup base path
|
||||
has strBackupClusterPath => (is => 'bare'); # Backup cluster path
|
||||
|
||||
# Process flags
|
||||
has strStanza => (is => 'bare');
|
||||
@ -139,13 +138,6 @@ sub BUILD
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Make sure the backup path is defined
|
||||
if (defined($self->{strBackupPath}))
|
||||
{
|
||||
# Create the backup cluster path
|
||||
$self->{strBackupClusterPath} = $self->{strBackupPath} . "/" . $self->{strStanza};
|
||||
}
|
||||
|
||||
# If remote is defined check parameters and open session
|
||||
if (defined($self->{strRemote}))
|
||||
{
|
||||
@ -171,18 +163,12 @@ sub clone
|
||||
my $self = shift;
|
||||
my $iThreadIdx = shift;
|
||||
|
||||
return pg_backrest_file->new
|
||||
return BackRest::File->new
|
||||
(
|
||||
strCompressExtension => $self->{strCompressExtension},
|
||||
strDefaultPathPermission => $self->{strDefaultPathPermission},
|
||||
strDefaultFilePermission => $self->{strDefaultFilePermission},
|
||||
strCommand => $self->{strCommand},
|
||||
strDbUser => $self->{strDbUser},
|
||||
strDbHost => $self->{strDbHost},
|
||||
strBackupUser => $self->{strBackupUser},
|
||||
strBackupHost => $self->{strBackupHost},
|
||||
strRemote => $self->{strRemote},
|
||||
oRemote => defined($self->{oRemote}) ? $self->{oRemote}->clone() : undef,
|
||||
strBackupPath => $self->{strBackupPath},
|
||||
strBackupClusterPath => $self->{strBackupClusterPath},
|
||||
strStanza => $self->{strStanza},
|
||||
iThreadIdx => $iThreadIdx
|
||||
);
|
||||
@ -569,7 +555,7 @@ sub path_create
|
||||
|
||||
# Set operation and debug strings
|
||||
my $strOperation = OP_FILE_PATH_CREATE;
|
||||
my $strDebug = " ${strPathType}:${strPath}, permission " . (defined($strPermission) ? $strPermission : "[undef]");
|
||||
my $strDebug = " ${strPathType}:${strPathOp}, permission " . (defined($strPermission) ? $strPermission : "[undef]");
|
||||
&log(DEBUG, "${strOperation}: ${strDebug}");
|
||||
|
||||
if ($self->is_remote($strPathType))
|
||||
@ -609,7 +595,7 @@ sub path_create
|
||||
if (!$bResult)
|
||||
{
|
||||
# Capture the error
|
||||
my $strError = "${strPath} could not be created: " . $!;
|
||||
my $strError = "${strPathOp} could not be created: " . $!;
|
||||
|
||||
# If running on command line the return directly
|
||||
if ($strPathType eq PATH_ABSOLUTE)
|
||||
@ -934,12 +920,13 @@ sub manifest
|
||||
# Run locally
|
||||
else
|
||||
{
|
||||
manifest_recurse($strPathType, $strPathOp, undef, 0, $oManifestHashRef);
|
||||
$self->manifest_recurse($strPathType, $strPathOp, undef, 0, $oManifestHashRef);
|
||||
}
|
||||
}
|
||||
|
||||
sub manifest_recurse
|
||||
{
|
||||
my $self = shift;
|
||||
my $strPathType = shift;
|
||||
my $strPathOp = shift;
|
||||
my $strPathFileOp = shift;
|
||||
@ -953,18 +940,17 @@ sub manifest_recurse
|
||||
if (!opendir($hPath, $strPathRead))
|
||||
{
|
||||
my $strError = "${strPathRead} could not be read: " . $!;
|
||||
my $iErrorCode = 2;
|
||||
my $iErrorCode = COMMAND_ERR_PATH_READ;
|
||||
|
||||
unless (-e $strPathRead)
|
||||
if (!$self->exists($strPathType, $strPathOp))
|
||||
{
|
||||
$strError = "${strPathRead} does not exist";
|
||||
$iErrorCode = 1;
|
||||
$iErrorCode = COMMAND_ERR_PATH_MISSING;
|
||||
}
|
||||
|
||||
if ($strPathType eq PATH_ABSOLUTE)
|
||||
{
|
||||
print $strError;
|
||||
exit ($iErrorCode);
|
||||
confess &log(ERROR, $strError, $iErrorCode);
|
||||
}
|
||||
|
||||
confess &log(ERROR, "${strErrorPrefix}: " . $strError);
|
||||
@ -995,21 +981,22 @@ sub manifest_recurse
|
||||
my $oStat = lstat($strPathFile);
|
||||
|
||||
if (!defined($oStat))
|
||||
{
|
||||
if (-e $strPathFile)
|
||||
{
|
||||
my $strError = "${strPathFile} could not be read: " . $!;
|
||||
my $iErrorCode = COMMAND_ERR_FILE_READ;
|
||||
|
||||
if (!$self->exists($strPathType, $strPathOp))
|
||||
{
|
||||
$strError = "${strPathRead} does not exist";
|
||||
$iErrorCode = COMMAND_ERR_FILE_MISSING;
|
||||
}
|
||||
|
||||
if ($strPathType eq PATH_ABSOLUTE)
|
||||
{
|
||||
print $strError;
|
||||
exit COMMAND_ERR_FILE_READ;
|
||||
confess &log(ERROR, $strError, COMMAND_ERR_FILE_READ);
|
||||
}
|
||||
|
||||
confess &log(ERROR, "${strErrorPrefix}: " . $strError);
|
||||
}
|
||||
|
||||
next;
|
||||
confess &log(ERROR, "${strErrorPrefix}: " . $strError, COMMAND_ERR_FILE_READ);
|
||||
}
|
||||
|
||||
# Check for regular file
|
||||
@ -1083,9 +1070,7 @@ sub manifest_recurse
|
||||
# Recurse into directories
|
||||
if (${$oManifestHashRef}{name}{"${strFile}"}{type} eq "d" && !$bCurrentDir)
|
||||
{
|
||||
manifest_recurse($strPathType, $strPathOp,
|
||||
$strFile,
|
||||
$iDepth + 1, $oManifestHashRef);
|
||||
$self->manifest_recurse($strPathType, $strPathOp, $strFile, $iDepth + 1, $oManifestHashRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1132,9 +1117,9 @@ sub copy
|
||||
|
||||
# Set debug string and log
|
||||
my $strDebug = ($bSourceRemote ? " remote" : " local") . " ${strSourcePathType}" .
|
||||
(defined($strSourceFile) ? ":${strSourceFile}" : "") .
|
||||
(defined($strSourceOp) ? ":${strSourceFile}" : "") .
|
||||
" to" . ($bDestinationRemote ? " remote" : " local") . " ${strDestinationPathType}" .
|
||||
(defined($strDestinationFile) ? ":${strDestinationFile}" : "") .
|
||||
(defined($strDestinationOp) ? ":${strDestinationFile}" : "") .
|
||||
", source_compressed = " . ($bSourceCompressed ? "true" : "false") .
|
||||
", destination_compress = " . ($bDestinationCompress ? "true" : "false") .
|
||||
", ignore_missing_source = " . ($bIgnoreMissingSource ? "true" : "false");
|
||||
|
@ -90,10 +90,6 @@ sub BUILD
|
||||
|
||||
$self->greeting_read();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
@ -103,11 +99,11 @@ sub clone
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
return pg_backrest_remote->new
|
||||
return BackRest::Remote->new
|
||||
(
|
||||
strCommand => $self->{strCommand},
|
||||
strHost => $self->{strUser},
|
||||
strUser => $self->{strHost},
|
||||
strHost => $self->{strHost},
|
||||
strUser => $self->{strUser},
|
||||
iBlockSize => $self->{iBlockSize}
|
||||
);
|
||||
}
|
||||
|
@ -113,14 +113,13 @@ sub BackRestFileTest
|
||||
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
||||
{
|
||||
# Create the file object
|
||||
my $oFile = BackRest::File->new
|
||||
my $oFile = (BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupClusterPath => undef,
|
||||
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++)
|
||||
@ -131,6 +130,8 @@ sub BackRestFileTest
|
||||
# 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} - " .
|
||||
@ -139,7 +140,10 @@ sub BackRestFileTest
|
||||
# Setup test directory
|
||||
BackRestFileTestSetup($bError);
|
||||
|
||||
my $strPath = "${strTestPath}/path";
|
||||
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)
|
||||
@ -159,10 +163,11 @@ sub BackRestFileTest
|
||||
if ($bError)
|
||||
{
|
||||
$strPath = "${strTestPath}/private/path";
|
||||
$strPathType = PATH_BACKUP_ABSOLUTE;
|
||||
}
|
||||
elsif (!$bExists)
|
||||
{
|
||||
$strPath = "${strTestPath}/error/path";
|
||||
$strPath = "error/path";
|
||||
}
|
||||
|
||||
# Execute in eval to catch errors
|
||||
@ -170,7 +175,7 @@ sub BackRestFileTest
|
||||
|
||||
eval
|
||||
{
|
||||
$oFile->path_create(PATH_BACKUP_ABSOLUTE, $strPath, $strPermission);
|
||||
$oFile->path_create($strPathType, $strPath, $strPermission);
|
||||
};
|
||||
|
||||
# Check for errors
|
||||
@ -191,17 +196,19 @@ sub BackRestFileTest
|
||||
}
|
||||
|
||||
# Make sure the path was actually created
|
||||
unless (-e $strPath)
|
||||
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($strPath);
|
||||
my $oStat = lstat($strPathCheck);
|
||||
|
||||
if (!defined($oStat))
|
||||
{
|
||||
confess "unable to stat ${strPath}";
|
||||
confess "unable to stat ${strPathCheck}";
|
||||
}
|
||||
|
||||
if ($bPermission)
|
||||
@ -233,7 +240,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupClusterPath => undef,
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
@ -334,7 +340,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupClusterPath => undef,
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
@ -440,7 +445,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupClusterPath => undef,
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
@ -585,7 +589,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupClusterPath => undef,
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
@ -712,7 +715,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
strBackupClusterPath => ${strTestPath},
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
@ -818,7 +820,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
strBackupClusterPath => ${strTestPath},
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
@ -901,7 +902,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
strBackupClusterPath => ${strTestPath},
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
@ -1002,7 +1002,6 @@ sub BackRestFileTest
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => "db",
|
||||
strBackupClusterPath => undef,
|
||||
strBackupPath => ${strTestPath},
|
||||
strRemote => $strRemote,
|
||||
oRemote => $bBackupRemote || $bDbRemote ? $oRemote : undef
|
||||
|
Reference in New Issue
Block a user