1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-09-16 09:06:18 +02:00

First fully working backup in a while.

This commit is contained in:
David Steele
2014-06-23 18:54:00 -04:00
parent 88bbbb4222
commit e1829bb2d2
7 changed files with 95 additions and 70 deletions

View File

@@ -356,7 +356,7 @@ if ($strOperation eq OP_ARCHIVE_PUSH || $strOperation eq OP_ARCHIVE_PULL)
&log(INFO, "pushing archive log " . $ARGV[1] . ($bCompressAsync ? " asynchronously" : ""));
archive_push($ARGV[1]);
archive_push(config_load(CONFIG_SECTION_STANZA, CONFIG_KEY_PATH), $ARGV[1]);
# Only continue if we are archiving local and a backup server is defined
if (!($strSection eq CONFIG_SECTION_ARCHIVE && defined(config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST))))

View File

@@ -258,8 +258,20 @@ sub archive_get
####################################################################################################################################
sub archive_push
{
my $strDbClusterPath = shift;
my $strSourceFile = shift;
# If the source file path is not absolute then it is relative to the data path
if (index($strSourceFile, '/',) != 0)
{
if (!defined($strDbClusterPath))
{
confess &log(ERROR, "database path must be set if relative xlog paths are used");
}
$strSourceFile = "${strDbClusterPath}/${strSourceFile}";
}
# Get the destination file
my $strDestinationFile = basename($strSourceFile);
@@ -273,7 +285,7 @@ sub archive_push
}
# Copy the archive file
$oFile->file_copy(PATH_DB_ABSOLUTE, $strSourceFile, # Source file
$oFile->copy(PATH_DB_ABSOLUTE, $strSourceFile, # Source file
PATH_BACKUP_ARCHIVE, $strDestinationFile, # Destination file
false, # Source is not compressed
false, # !!! For now, compress destination
@@ -1377,7 +1389,10 @@ sub backup
&log(DEBUG, "archiving: ${strArchive} (${stryArchiveFile[0]})");
$oFile->file_copy(PATH_BACKUP_ARCHIVE, $stryArchiveFile[0], PATH_BACKUP_TMP, "base/pg_xlog/${strArchive}");
$oFile->copy(PATH_BACKUP_ARCHIVE, $stryArchiveFile[0],
PATH_BACKUP_TMP, "base/pg_xlog/${strArchive}",
$stryArchiveFile[0] =~ "^.*\.$oFile->{strCompressExtension}\$",
false); # !!! THIS NEEDS TO BE FIXED
}
}
@@ -1389,7 +1404,7 @@ sub backup
# Rename the backup tmp path to complete the backup
&log(DEBUG, "moving ${strBackupTmpPath} to " . $oFile->path_get(PATH_BACKUP_CLUSTER, $strBackupPath));
$oFile->file_move(PATH_BACKUP_TMP, undef, PATH_BACKUP_CLUSTER, $strBackupPath);
$oFile->move(PATH_BACKUP_TMP, undef, PATH_BACKUP_CLUSTER, $strBackupPath);
}
####################################################################################################################################

View File

@@ -442,38 +442,19 @@ sub move
# Run locally
else
{
# If the destination path does not exist, create it or error out
if (!$self->exists($strDestinationPathType, dirname($strDestinationFile)))
{
if ($bDestinationPathCreate)
{
$self->path_create($strDestinationPathType, dirname($strDestinationFile));
}
else
{
my $strError = "destination " . dirname($strPathOpDestination) . " does not exist";
if ($strSourcePathType eq PATH_ABSOLUTE)
{
print $strError;
exit (COMMAND_ERR_PATH_MISSING);
}
confess &log(ERROR, "${strDebug}: " . $strError);
}
}
if (!rename($strPathOpSource, $strPathOpDestination))
{
my $strError = "${strPathOpSource} could not be moved: " . $!;
my $iErrorCode = COMMAND_ERR_FILE_MOVE;
my $strError = "${strPathOpDestination} could not be moved: " . $!;
my $iErrorCode = COMMAND_ERR_FILE_READ;
if (!$self->exists($strSourcePathType, dirname($strSourceFile)))
if (!$self->exists(PATH_ABSOLUTE, dirname($strPathOpDestination)))
{
$strError = "${strPathOpSource} does not exist";
$strError = "${strPathOpDestination} does not exist";
$iErrorCode = COMMAND_ERR_FILE_MISSING;
}
if (!($bDestinationPathCreate && $iErrorCode == COMMAND_ERR_FILE_MISSING))
{
if ($strSourcePathType eq PATH_ABSOLUTE)
{
confess &log(ERROR, $strError, $iErrorCode);
@@ -481,6 +462,14 @@ sub move
confess &log(ERROR, "${strDebug}: " . $strError);
}
$self->path_create(PATH_ABSOLUTE, dirname($strPathOpDestination));
if (!rename($strPathOpSource, $strPathOpDestination))
{
confess &log(ERROR, "unable to open move file ${strPathOpSource}: " . $!);
}
}
}
}
@@ -1110,12 +1099,13 @@ sub copy
my $bIgnoreMissingSource = shift;
my $lModificationTime = shift;
my $strPermission = shift;
my $bPathCreate = shift;
my $bDestinationPathCreate = shift;
# Set defaults
$bSourceCompressed = defined($bSourceCompressed) ? $bSourceCompressed : false;
$bDestinationCompress = defined($bDestinationCompress) ? $bDestinationCompress : false;
$bIgnoreMissingSource = defined($bIgnoreMissingSource) ? $bIgnoreMissingSource : false;
$bDestinationPathCreate = defined($bDestinationPathCreate) ? $bDestinationPathCreate : false;
# Set working variables
my $bSourceRemote = $self->is_remote($strSourcePathType) || $strSourcePathType eq PIPE_STDIN;
@@ -1134,7 +1124,8 @@ sub copy
(defined($strDestinationOp) ? ":${strDestinationFile}" : "") .
", source_compressed = " . ($bSourceCompressed ? "true" : "false") .
", destination_compress = " . ($bDestinationCompress ? "true" : "false") .
", ignore_missing_source = " . ($bIgnoreMissingSource ? "true" : "false");
", ignore_missing_source = " . ($bIgnoreMissingSource ? "true" : "false") .
", destination_path_create = " . ($bDestinationPathCreate ? "true" : "false");
&log(DEBUG, OP_FILE_COPY . ": ${strDebug}");
# Open the source and destination files (if needed)
@@ -1177,8 +1168,35 @@ sub copy
if (!$bDestinationRemote)
{
open($hDestinationFile, ">", $strDestinationTmpOp)
or confess &log(ERROR, "cannot open ${strDestinationTmpOp}: " . $!);
# Open the destination temp file
if (!open($hDestinationFile, ">", $strDestinationTmpOp))
{
my $strError = "${strDestinationTmpOp} could not be opened: " . $!;
my $iErrorCode = COMMAND_ERR_FILE_READ;
if (!$self->exists(PATH_ABSOLUTE, dirname($strDestinationOp)))
{
$strError = "${strDestinationOp} does not exist";
$iErrorCode = COMMAND_ERR_FILE_MISSING;
}
if (!($bDestinationPathCreate && $iErrorCode == COMMAND_ERR_FILE_MISSING))
{
if ($strSourcePathType eq PATH_ABSOLUTE)
{
confess &log(ERROR, $strError, $iErrorCode);
}
confess &log(ERROR, "${strDebug}: " . $strError);
}
$self->path_create(PATH_ABSOLUTE, dirname($strDestinationOp));
if (!open($hDestinationFile, ">", $strDestinationTmpOp))
{
confess &log(ERROR, "unable to open destination file ${strDestinationOp}: " . $!);
}
}
}
# If source or destination are remote
@@ -1357,7 +1375,7 @@ sub copy
}
# Move the file from tmp to final destination
$self->move(PATH_ABSOLUTE, $strDestinationTmpOp, PATH_ABSOLUTE, $strDestinationOp, $bPathCreate);
$self->move(PATH_ABSOLUTE, $strDestinationTmpOp, PATH_ABSOLUTE, $strDestinationOp, false);
}
return true;

View File

@@ -121,7 +121,6 @@ sub BackRestTestCommon_ConfigCreate
if ($strLocal eq REMOTE_BACKUP)
{
$oParamHash{$strCommonStanza}{'path'} = $strCommonDbCommonPath;
$oParamHash{'db:command:option'}{'psql'} = "--port=${iCommonDbPort}";
}
elsif ($strLocal eq REMOTE_DB)
@@ -132,6 +131,7 @@ sub BackRestTestCommon_ConfigCreate
confess "invalid local type ${strLocal}";
}
$oParamHash{$strCommonStanza}{'path'} = $strCommonDbCommonPath;
$oParamHash{'global:backup'}{'path'} = $strCommonBackupPath;
$oParamHash{'global:log'}{'level-console'} = 'debug';

View File

@@ -119,14 +119,11 @@ sub BackRestTestFile_Test
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?)
# Loop through error
for (my $bError = 0; $bError <= 1; $bError++)
{
# Loop through permission (permission will be set on true)
for (my $bPermission = 0; $bPermission <= $bExists; $bPermission++)
for (my $bPermission = 0; $bPermission <= 1; $bPermission++)
{
my $strPathType = PATH_BACKUP_CLUSTER;
@@ -138,7 +135,7 @@ sub BackRestTestFile_Test
}
&log(INFO, "run ${iRun} - " .
"remote ${bRemote}, exists ${bExists}, error ${bError}, permission ${bPermission}");
"remote ${bRemote}, error ${bError}, permission ${bPermission}");
# Setup test directory
BackRestTestFile_Setup($bError);
@@ -161,13 +158,9 @@ sub BackRestTestFile_Test
$strPath = "${strTestPath}/private/path";
$strPathType = PATH_BACKUP_ABSOLUTE;
}
elsif (!$bExists)
{
$strPath = "error/path";
}
# Execute in eval to catch errors
my $bErrorExpected = !$bExists || $bError;
my $bErrorExpected = $bError;
eval
{
@@ -218,7 +211,6 @@ sub BackRestTestFile_Test
}
}
}
}
#-------------------------------------------------------------------------------------------------------------------------------
# Test move()
@@ -960,7 +952,7 @@ sub BackRestTestFile_Test
$strMessage = $oMessage;
}
if ($bError && defined($iCode) && $iCode == COMMAND_ERR_FILE_READ)
if ($bError)
{
next;
}