1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-05 15:05:48 +02:00

Moved tmp path.

This commit is contained in:
David Steele 2014-02-05 13:10:36 -05:00
parent 7ffade2453
commit a15fcb8c23
3 changed files with 59 additions and 38 deletions

View File

@ -10,7 +10,7 @@ psql=/Library/PostgreSQL/9.3/bin/psql -X --port=6001
[backup]
user=backrest
host=localhost
path=/Users/backrest/test/backup
path=/Users/backrest/test
[retention]
full_retention=2

View File

@ -481,8 +481,6 @@ sub backup
&log(DEBUG, "cluster path is $strDbClusterPath");
path_create(PATH_BACKUP_CLUSTER);
# unless (-e $strDbClusterPath)
# {
# confess &log(ERROR, "cluster data path '${strDbClusterPath}' does not exist");
@ -524,8 +522,8 @@ sub backup
}
# Build backup tmp and config
my $strBackupTmpPath = "${pg_backrest_file::strBackupClusterPath}/backup.tmp";
my $strBackupConfFile = "${strBackupTmpPath}/backup.manifest";
my $strBackupTmpPath = path_get(PATH_BACKUP_TMP);
my $strBackupConfFile = path_get(PATH_BACKUP_TMP, "backup.manifest");
# If the backup tmp path already exists, delete the conf file
if (-e $strBackupTmpPath)
@ -533,7 +531,8 @@ sub backup
&log(WARNING, "backup path $strBackupTmpPath already exists");
# !!! This is temporary until we can clean backup dirs
rmtree($strBackupTmpPath) or confess &log(ERROR, "unable to delete backup.tmp");
rmtree($strBackupTmpPath) or confess &log(ERROR, "unable to delete ${strBackupTmpPath}");
path_create(PATH_BACKUP_TMP);
#if (-e $strBackupConfFile)
#{
# unlink $strBackupConfFile or die &log(ERROR, "backup config ${strBackupConfFile} could not be deleted");
@ -543,7 +542,7 @@ sub backup
else
{
&log(INFO, "creating backup path $strBackupTmpPath");
mkdir $strBackupTmpPath or confess &log(ERROR, "backup path ${strBackupTmpPath} could not be created");
path_create(PATH_BACKUP_TMP);
}
# Create a new backup manifest hash
@ -602,7 +601,8 @@ sub backup
backup_manifest_save($strBackupConfFile, \%oBackupManifest);
# Rename the backup tmp path to complete the backup
rename($strBackupTmpPath, "${pg_backrest_file::strBackupClusterPath}/${strBackupPath}") or confess &log(ERROR, "unable to ${strBackupTmpPath} rename to ${strBackupPath}");
file_move(PATH_BACKUP_TMP, undef, PATH_BACKUP_CLUSTER, $strBackupPath);
# rename($strBackupTmpPath, "${pg_backrest_file::strBackupClusterPath}/${strBackupPath}") or confess &log(ERROR, "unable to ${strBackupTmpPath} rename to ${strBackupPath}");
# Expire backups (!!! Need to read this from config file)
backup_expire($pg_backrest_file::strBackupClusterPath, 2, 2, "full", 2);

View File

@ -17,7 +17,8 @@ use pg_backrest_utility;
use Exporter qw(import);
our @EXPORT = qw(file_init_archive file_init_backup
path_get path_type_get link_create path_create file_copy file_list_get manifest_get file_hash_get is_remote
path_get path_type_get is_remote
link_create path_create file_move file_copy file_list_get manifest_get file_hash_get
psql_execute
PATH_DB PATH_DB_ABSOLUTE PATH_BACKUP PATH_BACKUP_ABSOLUTE PATH_BACKUP_CLUSTER PATH_BACKUP_TMP PATH_BACKUP_ARCHIVE);
@ -47,6 +48,7 @@ our $strBackupClusterPath; # Backup cluster path
# Process flags
my $bNoCompression;
my $strCluster;
####################################################################################################################################
# FILE_INIT_ARCHIVE
@ -60,7 +62,7 @@ sub file_init_archive
my $strBackupUserParam = shift;
my $strBackupHostParam = shift;
my $strBackupPathParam = shift;
my $strCluster = shift;
my $strClusterParam = shift;
# Assign parameters to module variables
$bNoCompression = $bNoCompressionParam;
@ -68,7 +70,7 @@ sub file_init_archive
$strCommandCompress = $strCommandCompressParam;
$strCommandDecompress = $strCommandDecompressParam;
$strBackupPath = $strBackupPathParam;
#$strCluster = $strClusterParam;
$strCluster = $strClusterParam;
$strBackupUser = $strBackupUserParam;
$strBackupHost = $strBackupHostParam;
@ -164,22 +166,42 @@ sub path_get
{
return $strFile;
}
# Parse absolute backup path
elsif ($strType eq PATH_BACKUP_ABSOLUTE)
{
return $strFile;
}
# Parse paths on the backup side
elsif ($strType eq PATH_BACKUP)
elsif ($strType eq PATH_BACKUP || $strType eq PATH_BACKUP_TMP)
{
if (!defined($strBackupPath))
{
confess &log(ASSERT, "\$strBackupPath not yet defined");
}
return $strBackupPath;
if ($strType eq PATH_BACKUP)
{
return $strBackupPath;
}
if ($strType eq PATH_BACKUP_TMP)
{
if (!defined($strCluster))
{
confess &log(ASSERT, "\$strCluster not yet defined");
}
my $strTempPath = "tmp/${strCluster}.tmp";
if (defined($bTemp) && $bTemp)
{
return $strBackupPath . "/${strTempPath}/file.tmp";
}
return $strBackupPath . "/${strTempPath}" . (defined($strFile) ? "/${strFile}" : "");
}
}
# Parse absolute db path
if ($strType eq PATH_BACKUP_ABSOLUTE)
{
return $strFile;
}
elsif ($strType eq PATH_BACKUP_CLUSTER || $strType eq PATH_BACKUP_TMP || $strType eq PATH_BACKUP_ARCHIVE)
elsif ($strType eq PATH_BACKUP_CLUSTER || $strType eq PATH_BACKUP_ARCHIVE)
{
if (!defined($strBackupClusterPath))
{
@ -190,15 +212,6 @@ sub path_get
{
return $strBackupClusterPath . (defined($strFile) ? "/${strFile}" : "");
}
elsif ($strType eq PATH_BACKUP_TMP)
{
if (defined($bTemp) && $bTemp)
{
return $strBackupClusterPath . "/backup.tmp/file.tmp";
}
return $strBackupClusterPath . "/backup.tmp" . (defined($strFile) ? "/${strFile}" : "");
}
elsif ($strType eq PATH_BACKUP_ARCHIVE)
{
if (defined($bTemp) && $bTemp)
@ -416,15 +429,21 @@ sub remote_get
####################################################################################################################################
sub file_move
{
my $strPathType = shift;
my $strSourcePathType = shift;
my $strSourceFile = shift;
my $strDestinationPathType = shift;
my $strDestinationFile = shift;
my $strSource = path_get($strPathType, $strSourceFile);
my $strDestination = path_get($strPathType, $strDestinationFile);
if (path_type_get($strSourcePathType) ne path_type_get($strSourcePathType))
{
confess &log(ASSERT, "source and destination path types must be equal");
}
my $strSource = path_get($strSourcePathType, $strSourceFile);
my $strDestination = path_get($strDestinationPathType, $strDestinationFile);
# If the destination path is backup and does not exist, create it
if (path_type_get($strPathType) eq PATH_BACKUP)
if (path_type_get($strDestinationPathType) eq PATH_BACKUP)
{
path_create(PATH_BACKUP_ABSOLUTE, dirname($strDestination));
}
@ -432,12 +451,13 @@ sub file_move
my $strCommand = "mv ${strSource} ${strDestination}";
# Run remotely
if (is_remote($strPathType))
if (is_remote($strDestinationPathType))
{
&log(DEBUG, " file_move: remote ${strPathType} '${strCommand}'");
&log(DEBUG, " file_move: remote ${strDestinationPathType} '${strCommand}'");
my $oSSH = remote_get($strPathType);
$oSSH->system($strCommand) or confess &log("unable to move remote ${strPathType}:${strSourceFile} to ${strDestinationFile}");
my $oSSH = remote_get($strDestinationPathType);
$oSSH->system($strCommand)
or confess &log("unable to move remote ${strDestinationPathType}:${strSourceFile} to ${strDestinationFile}");
}
# Run locally
else
@ -599,7 +619,8 @@ sub file_copy
}
# Move the file from tmp to final destination
file_move(path_type_get($strDestinationPathType) . ":absolute", $strDestinationTmp, $strDestination);
file_move(path_type_get($strSourcePathType) . ":absolute", $strDestinationTmp,
path_type_get($strDestinationPathType) . ":absolute", $strDestination);
}
####################################################################################################################################