You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-05-18 10:01:29 +02:00
Thread files are no longer in an array
This commit is contained in:
+74
-68
@@ -29,7 +29,7 @@ use Exporter qw(import);
|
||||
our @EXPORT = qw(backup_init backup_thread_kill archive_push archive_pull archive_compress backup backup_expire archive_list_get);
|
||||
|
||||
my $oDb;
|
||||
my @oFile;
|
||||
my $oFile;
|
||||
my $strType = "incremental"; # Type of backup: full, differential (diff), incremental (incr)
|
||||
my $bHardLink;
|
||||
my $bNoChecksum;
|
||||
@@ -42,6 +42,7 @@ my $bArchiveRequired;
|
||||
# Thread variables
|
||||
my @oThread;
|
||||
my @oThreadQueue;
|
||||
my @oThreadFile;
|
||||
my $oMasterQueue;
|
||||
my %oFileCopyMap;
|
||||
|
||||
@@ -58,13 +59,13 @@ sub backup_init
|
||||
my $iThreadMaxParam = shift;
|
||||
my $bArchiveRequiredParam = shift;
|
||||
|
||||
for (my $iFileIdx = 0; $iFileIdx < scalar @oFile; $iFileIdx++)
|
||||
{
|
||||
undef($oFile[$iFileIdx]);
|
||||
}
|
||||
# for (my $iFileIdx = 0; $iFileIdx < scalar @oFile; $iFileIdx++)
|
||||
# {
|
||||
# undef($oFile[$iFileIdx]);
|
||||
# }
|
||||
|
||||
$oDb = $oDbParam;
|
||||
$oFile[0] = $oFileParam;
|
||||
$oFile = $oFileParam;
|
||||
$strType = $strTypeParam;
|
||||
$bHardLink = $bHardLinkParam;
|
||||
$bNoChecksum = $bNoChecksumParam;
|
||||
@@ -109,10 +110,10 @@ sub thread_init
|
||||
{
|
||||
$oThreadQueue[$iThreadIdx] = Thread::Queue->new();
|
||||
|
||||
if (!defined($oFile[$iThreadIdx + 1]))
|
||||
{
|
||||
$oFile[$iThreadIdx + 1] = $oFile[0]->clone($iThreadIdx + 1);
|
||||
}
|
||||
# if (!defined($oFile[$iThreadIdx + 1]))
|
||||
# {
|
||||
# $oFileThread[$iThreadIdx] = $oFile->clone($iThreadIdx + 1);
|
||||
# }
|
||||
}
|
||||
|
||||
$oMasterQueue = Thread::Queue->new();
|
||||
@@ -192,8 +193,8 @@ sub backup_thread_complete
|
||||
$oThread[$iThreadIdx]->join();
|
||||
&log(TRACE, "thread ${iThreadIdx} object undef");
|
||||
undef($oThread[$iThreadIdx]);
|
||||
&log(TRACE, "thread ${iThreadIdx} file object undef");
|
||||
undef($oFile[$iThreadIdx + 1]);
|
||||
# &log(TRACE, "thread ${iThreadIdx} file object undef");
|
||||
# undef($oFile[$iThreadIdx + 1]);
|
||||
$iThreadComplete++;
|
||||
}
|
||||
}
|
||||
@@ -221,11 +222,11 @@ sub archive_push
|
||||
# Append the checksum (if requested)
|
||||
if ($bArchiveFile && !$bNoChecksum)
|
||||
{
|
||||
$strDestinationFile .= "-" . $oFile[0]->file_hash_get(PATH_DB_ABSOLUTE, $strSourceFile);
|
||||
$strDestinationFile .= "-" . $oFile->file_hash_get(PATH_DB_ABSOLUTE, $strSourceFile);
|
||||
}
|
||||
|
||||
# Copy the archive file
|
||||
$oFile[0]->file_copy(PATH_DB_ABSOLUTE, $strSourceFile, PATH_BACKUP_ARCHIVE, $strDestinationFile,
|
||||
$oFile->file_copy(PATH_DB_ABSOLUTE, $strSourceFile, PATH_BACKUP_ARCHIVE, $strDestinationFile,
|
||||
$bArchiveFile ? undef : true);
|
||||
}
|
||||
|
||||
@@ -240,7 +241,7 @@ sub archive_pull
|
||||
my $iArchiveMaxMB = shift;
|
||||
|
||||
# Load the archive manifest - all the files that need to be pushed
|
||||
my %oManifestHash = $oFile[0]->manifest_get(PATH_DB_ABSOLUTE, $strArchivePath);
|
||||
my %oManifestHash = $oFile->manifest_get(PATH_DB_ABSOLUTE, $strArchivePath);
|
||||
|
||||
# Get all the files to be transferred and calculate the total size
|
||||
my @stryFile;
|
||||
@@ -310,7 +311,7 @@ sub archive_pull
|
||||
|
||||
&log(DEBUG, "local archive path max = ${strPathMax}");
|
||||
|
||||
foreach my $strPath ($oFile[0]->file_list_get(PATH_DB_ABSOLUTE, $strArchivePath, "^[0-F]{16}\$"))
|
||||
foreach my $strPath ($oFile->file_list_get(PATH_DB_ABSOLUTE, $strArchivePath, "^[0-F]{16}\$"))
|
||||
{
|
||||
if ($strPath lt $strPathMax)
|
||||
{
|
||||
@@ -330,6 +331,8 @@ sub archive_pull_copy_thread
|
||||
my $iThreadIdx = $args[0];
|
||||
my $strArchivePath = $args[1];
|
||||
|
||||
my $oFileThread = $oFile->clone($iThreadIdx); # Thread local file object
|
||||
|
||||
while (my $strFile = $oThreadQueue[$iThreadIdx]->dequeue())
|
||||
{
|
||||
&log(INFO, "thread ${iThreadIdx} backing up archive file ${strFile}");
|
||||
@@ -337,10 +340,10 @@ sub archive_pull_copy_thread
|
||||
my $strArchiveFile = "${strArchivePath}/${strFile}";
|
||||
|
||||
# Copy the file
|
||||
$oFile[$iThreadIdx + 1]->file_copy(PATH_DB_ABSOLUTE, $strArchiveFile,
|
||||
$oFileThread->file_copy(PATH_DB_ABSOLUTE, $strArchiveFile,
|
||||
PATH_BACKUP_ARCHIVE, basename($strFile),
|
||||
undef, undef,
|
||||
undef); # cannot set permissions remotely yet $oFile[0]->{strDefaultFilePermission});
|
||||
undef); # cannot set permissions remotely yet $oFile->{strDefaultFilePermission});
|
||||
|
||||
# Remove the source archive file
|
||||
unlink($strArchiveFile) or confess &log(ERROR, "unable to remove ${strArchiveFile}");
|
||||
@@ -354,7 +357,7 @@ sub archive_compress
|
||||
my $iFileCompressMax = shift;
|
||||
|
||||
# Load the archive manifest - all the files that need to be pushed
|
||||
my %oManifestHash = $oFile[0]->manifest_get(PATH_DB_ABSOLUTE, $strArchivePath);
|
||||
my %oManifestHash = $oFile->manifest_get(PATH_DB_ABSOLUTE, $strArchivePath);
|
||||
|
||||
# Get all the files to be compressed and calculate the total size
|
||||
my @stryFile;
|
||||
@@ -419,12 +422,14 @@ sub archive_pull_compress_thread
|
||||
my $iThreadIdx = $args[0];
|
||||
my $strArchivePath = $args[1];
|
||||
|
||||
my $oFileThread = $oFile->clone($iThreadIdx); # Thread local file object
|
||||
|
||||
while (my $strFile = $oThreadQueue[$iThreadIdx]->dequeue())
|
||||
{
|
||||
&log(INFO, "thread ${iThreadIdx} compressing archive file ${strFile}");
|
||||
|
||||
# Compress the file
|
||||
$oFile[$iThreadIdx + 1]->file_compress(PATH_DB_ABSOLUTE, "${strArchivePath}/${strFile}");
|
||||
$oFileThread->file_compress(PATH_DB_ABSOLUTE, "${strArchivePath}/${strFile}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,12 +501,12 @@ sub backup_type_find
|
||||
|
||||
if ($strType eq 'incremental')
|
||||
{
|
||||
$strDirectory = ($oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 1, 1), "reverse"))[0];
|
||||
$strDirectory = ($oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 1, 1), "reverse"))[0];
|
||||
}
|
||||
|
||||
if (!defined($strDirectory) && $strType ne "full")
|
||||
{
|
||||
$strDirectory = ($oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 0, 0), "reverse"))[0];
|
||||
$strDirectory = ($oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 0, 0), "reverse"))[0];
|
||||
}
|
||||
|
||||
return $strDirectory;
|
||||
@@ -536,7 +541,7 @@ sub backup_file_not_in_manifest
|
||||
my $strPathType = shift;
|
||||
my $oManifestRef = shift;
|
||||
|
||||
my %oFileHash = $oFile[0]->manifest_get($strPathType);
|
||||
my %oFileHash = $oFile->manifest_get($strPathType);
|
||||
my @stryFile;
|
||||
my $iFileTotal = 0;
|
||||
|
||||
@@ -629,15 +634,15 @@ sub backup_tmp_clean
|
||||
&log(INFO, "cleaning backup tmp path");
|
||||
|
||||
# Remove the pg_xlog directory since it contains nothing useful for the new backup
|
||||
if (-e $oFile[0]->path_get(PATH_BACKUP_TMP, "base/pg_xlog"))
|
||||
if (-e $oFile->path_get(PATH_BACKUP_TMP, "base/pg_xlog"))
|
||||
{
|
||||
rmtree($oFile[0]->path_get(PATH_BACKUP_TMP, "base/pg_xlog")) or confess &log(ERROR, "unable to delete tmp pg_xlog path");
|
||||
rmtree($oFile->path_get(PATH_BACKUP_TMP, "base/pg_xlog")) or confess &log(ERROR, "unable to delete tmp pg_xlog path");
|
||||
}
|
||||
|
||||
# Remove the pg_tblspc directory since it is trivial to rebuild, but hard to compare
|
||||
if (-e $oFile[0]->path_get(PATH_BACKUP_TMP, "base/pg_tblspc"))
|
||||
if (-e $oFile->path_get(PATH_BACKUP_TMP, "base/pg_tblspc"))
|
||||
{
|
||||
rmtree($oFile[0]->path_get(PATH_BACKUP_TMP, "base/pg_tblspc")) or confess &log(ERROR, "unable to delete tmp pg_tblspc path");
|
||||
rmtree($oFile->path_get(PATH_BACKUP_TMP, "base/pg_tblspc")) or confess &log(ERROR, "unable to delete tmp pg_tblspc path");
|
||||
}
|
||||
|
||||
# Get the list of files that should be deleted from temp
|
||||
@@ -645,7 +650,7 @@ sub backup_tmp_clean
|
||||
|
||||
foreach my $strFile (sort {$b cmp $a} @stryFile)
|
||||
{
|
||||
my $strDelete = $oFile[0]->path_get(PATH_BACKUP_TMP, $strFile);
|
||||
my $strDelete = $oFile->path_get(PATH_BACKUP_TMP, $strFile);
|
||||
|
||||
# If a path then delete it, all the files should have already been deleted since we are going in reverse order
|
||||
if (-d $strDelete)
|
||||
@@ -679,7 +684,7 @@ sub backup_manifest_build
|
||||
$strLevel = "base";
|
||||
}
|
||||
|
||||
my %oManifestHash = $oFile[0]->manifest_get(PATH_DB_ABSOLUTE, $strDbClusterPath);
|
||||
my %oManifestHash = $oFile->manifest_get(PATH_DB_ABSOLUTE, $strDbClusterPath);
|
||||
my $strName;
|
||||
|
||||
foreach $strName (sort(keys $oManifestHash{name}))
|
||||
@@ -835,7 +840,7 @@ sub backup_file
|
||||
$strSectionFile = "base:file";
|
||||
|
||||
# Create the archive log directory
|
||||
$oFile[0]->path_create(PATH_BACKUP_TMP, "base/pg_xlog");
|
||||
$oFile->path_create(PATH_BACKUP_TMP, "base/pg_xlog");
|
||||
}
|
||||
# Process each tablespace
|
||||
elsif ($strSectionPath =~ /^tablespace\:/)
|
||||
@@ -849,9 +854,9 @@ sub backup_file
|
||||
# Create the tablespace directory and link
|
||||
if ($bPathCreate)
|
||||
{
|
||||
$oFile[0]->path_create(PATH_BACKUP_TMP, $strBackupDestinationPath);
|
||||
$oFile->path_create(PATH_BACKUP_TMP, $strBackupDestinationPath);
|
||||
|
||||
$oFile[0]->link_create(PATH_BACKUP_TMP, ${strBackupDestinationPath},
|
||||
$oFile->link_create(PATH_BACKUP_TMP, ${strBackupDestinationPath},
|
||||
PATH_BACKUP_TMP,
|
||||
"base/pg_tblspc/" . ${$oBackupManifestRef}{"base:tablespace"}{"${strTablespaceName}"}{oid},
|
||||
false, true);
|
||||
@@ -876,7 +881,7 @@ sub backup_file
|
||||
}
|
||||
else
|
||||
{
|
||||
$oFile[0]->path_create(PATH_BACKUP_TMP, "${strBackupDestinationPath}/${strPath}",
|
||||
$oFile->path_create(PATH_BACKUP_TMP, "${strBackupDestinationPath}/${strPath}",
|
||||
${$oBackupManifestRef}{"${strSectionPath}"}{"$strPath"}{permission});
|
||||
}
|
||||
}
|
||||
@@ -913,7 +918,7 @@ sub backup_file
|
||||
{
|
||||
&log(DEBUG, "hard-linking ${strBackupSourceFile} from ${strReference}");
|
||||
|
||||
$oFile[0]->link_create(PATH_BACKUP_CLUSTER, "${strReference}/${strBackupDestinationPath}/${strFile}",
|
||||
$oFile->link_create(PATH_BACKUP_CLUSTER, "${strReference}/${strBackupDestinationPath}/${strFile}",
|
||||
PATH_BACKUP_TMP, "${strBackupDestinationPath}/${strFile}", true, false, !$bPathCreate);
|
||||
}
|
||||
}
|
||||
@@ -1086,8 +1091,9 @@ sub backup_file_thread
|
||||
my $bPathCreate = $args[2]; # Should paths be created automatically?
|
||||
my $lSizeTotal = $args[3]; # Total size of the files to be copied by this thread
|
||||
|
||||
my $lSize = 0; # Size of files currently copied by this thread
|
||||
my $strLog; # Store the log message
|
||||
my $lSize = 0; # Size of files currently copied by this thread
|
||||
my $strLog; # Store the log message
|
||||
my $oFileThread = $oFile->clone($iThreadIdx); # Thread local file object
|
||||
|
||||
# When a KILL signal is received, immediately abort
|
||||
$SIG{'KILL'} = sub {threads->exit();};
|
||||
@@ -1104,20 +1110,20 @@ sub backup_file_thread
|
||||
($lSizeTotal > 0 ? ", " . int($lSize * 100 / $lSizeTotal) . "%" : "") . ")";
|
||||
|
||||
# Copy the file from the database to the backup
|
||||
unless($oFile[$iThreadIdx + 1]->file_copy(PATH_DB_ABSOLUTE, $oFileCopyMap{$strFile}{db_file},
|
||||
unless($oFileThread->file_copy(PATH_DB_ABSOLUTE, $oFileCopyMap{$strFile}{db_file},
|
||||
PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file},
|
||||
undef, $oFileCopyMap{$strFile}{modification_time},
|
||||
undef, $bPathCreate, false))
|
||||
{
|
||||
# If the copy fails then see if the file still exists on the database
|
||||
if (!$oFile[$iThreadIdx + 1]->file_exists(PATH_DB_ABSOLUTE, $oFileCopyMap{$strFile}{db_file}))
|
||||
if (!$oFileThread->file_exists(PATH_DB_ABSOLUTE, $oFileCopyMap{$strFile}{db_file}))
|
||||
{
|
||||
# If it is missing then the database must have removed it (or is now corrupt)
|
||||
&log(INFO, "thread ${iThreadIdx} skipped file removed by database: " . $oFileCopyMap{$strFile}{db_file});
|
||||
|
||||
# Remove the destination file and the temp file just in case they had already been written
|
||||
$oFile[$iThreadIdx + 1]->file_remove(PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file}, true);
|
||||
$oFile[$iThreadIdx + 1]->file_remove(PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file});
|
||||
$oFileThread->file_remove(PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file}, true);
|
||||
$oFileThread->file_remove(PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file});
|
||||
}
|
||||
|
||||
# Write a message into the master queue to have the file removed from the manifest
|
||||
@@ -1131,7 +1137,7 @@ sub backup_file_thread
|
||||
if ($bChecksum)
|
||||
{
|
||||
# Generate the checksum
|
||||
my $strChecksum = $oFile[$iThreadIdx + 1]->file_hash_get(PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file});
|
||||
my $strChecksum = $oFileThread->file_hash_get(PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file});
|
||||
|
||||
# Write the checksum message into the master queue
|
||||
$oMasterQueue->enqueue("checksum|$oFileCopyMap{$strFile}{file_section}|$oFileCopyMap{$strFile}{file}|${strChecksum}");
|
||||
@@ -1157,7 +1163,7 @@ sub backup
|
||||
my $strDbClusterPath = shift;
|
||||
|
||||
# Not supporting remote backup hosts yet
|
||||
if ($oFile[0]->is_remote(PATH_BACKUP))
|
||||
if ($oFile->is_remote(PATH_BACKUP))
|
||||
{
|
||||
confess &log(ERROR, "remote backup host not currently supported");
|
||||
}
|
||||
@@ -1170,16 +1176,16 @@ sub backup
|
||||
&log(DEBUG, "cluster path is $strDbClusterPath");
|
||||
|
||||
# Create the cluster backup path
|
||||
$oFile[0]->path_create(PATH_BACKUP_CLUSTER);
|
||||
$oFile->path_create(PATH_BACKUP_CLUSTER);
|
||||
|
||||
# Find the previous backup based on the type
|
||||
my $strBackupLastPath = backup_type_find($strType, $oFile[0]->path_get(PATH_BACKUP_CLUSTER));
|
||||
my $strBackupLastPath = backup_type_find($strType, $oFile->path_get(PATH_BACKUP_CLUSTER));
|
||||
|
||||
my %oLastManifest;
|
||||
|
||||
if (defined($strBackupLastPath))
|
||||
{
|
||||
%oLastManifest = backup_manifest_load($oFile[0]->path_get(PATH_BACKUP_CLUSTER) . "/$strBackupLastPath/backup.manifest");
|
||||
%oLastManifest = backup_manifest_load($oFile->path_get(PATH_BACKUP_CLUSTER) . "/$strBackupLastPath/backup.manifest");
|
||||
|
||||
if (!defined($oLastManifest{backup}{label}))
|
||||
{
|
||||
@@ -1216,8 +1222,8 @@ sub backup
|
||||
&log(INFO, "new backup label: ${strBackupPath}");
|
||||
|
||||
# Build backup tmp and config
|
||||
my $strBackupTmpPath = $oFile[0]->path_get(PATH_BACKUP_TMP);
|
||||
my $strBackupConfFile = $oFile[0]->path_get(PATH_BACKUP_TMP, "backup.manifest");
|
||||
my $strBackupTmpPath = $oFile->path_get(PATH_BACKUP_TMP);
|
||||
my $strBackupConfFile = $oFile->path_get(PATH_BACKUP_TMP, "backup.manifest");
|
||||
|
||||
# Start backup
|
||||
my %oBackupManifest;
|
||||
@@ -1231,7 +1237,7 @@ sub backup
|
||||
# Build the backup manifest
|
||||
my %oTablespaceMap = $oDb->tablespace_map_get();
|
||||
|
||||
backup_manifest_build($oFile[0]->{strCommandManifest}, $strDbClusterPath, \%oBackupManifest, \%oLastManifest, \%oTablespaceMap);
|
||||
backup_manifest_build($oFile->{strCommandManifest}, $strDbClusterPath, \%oBackupManifest, \%oLastManifest, \%oTablespaceMap);
|
||||
|
||||
# If the backup tmp path already exists, remove invalid files
|
||||
if (-e $strBackupTmpPath)
|
||||
@@ -1245,7 +1251,7 @@ sub backup
|
||||
else
|
||||
{
|
||||
&log(DEBUG, "creating backup path $strBackupTmpPath");
|
||||
$oFile[0]->path_create(PATH_BACKUP_TMP);
|
||||
$oFile->path_create(PATH_BACKUP_TMP);
|
||||
}
|
||||
|
||||
# Save the backup conf file first time - so we can see what is happening in the backup
|
||||
@@ -1277,12 +1283,12 @@ sub backup
|
||||
|
||||
foreach my $strArchive (@stryArchive)
|
||||
{
|
||||
my $strArchivePath = dirname($oFile[0]->path_get(PATH_BACKUP_ARCHIVE, $strArchive));
|
||||
my $strArchivePath = dirname($oFile->path_get(PATH_BACKUP_ARCHIVE, $strArchive));
|
||||
|
||||
wait_for_file($strArchivePath, "^${strArchive}(-[0-f]+){0,1}(\\.$oFile[0]->{strCompressExtension}){0,1}\$", 600);
|
||||
wait_for_file($strArchivePath, "^${strArchive}(-[0-f]+){0,1}(\\.$oFile->{strCompressExtension}){0,1}\$", 600);
|
||||
|
||||
my @stryArchiveFile = $oFile[0]->file_list_get(PATH_BACKUP_ABSOLUTE, $strArchivePath,
|
||||
"^${strArchive}(-[0-f]+){0,1}(\\.$oFile[0]->{strCompressExtension}){0,1}\$");
|
||||
my @stryArchiveFile = $oFile->file_list_get(PATH_BACKUP_ABSOLUTE, $strArchivePath,
|
||||
"^${strArchive}(-[0-f]+){0,1}(\\.$oFile->{strCompressExtension}){0,1}\$");
|
||||
|
||||
if (scalar @stryArchiveFile != 1)
|
||||
{
|
||||
@@ -1291,7 +1297,7 @@ sub backup
|
||||
|
||||
&log(DEBUG, "archiving: ${strArchive} (${stryArchiveFile[0]})");
|
||||
|
||||
$oFile[0]->file_copy(PATH_BACKUP_ARCHIVE, $stryArchiveFile[0], PATH_BACKUP_TMP, "base/pg_xlog/${strArchive}");
|
||||
$oFile->file_copy(PATH_BACKUP_ARCHIVE, $stryArchiveFile[0], PATH_BACKUP_TMP, "base/pg_xlog/${strArchive}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1302,8 +1308,8 @@ sub backup
|
||||
backup_manifest_save($strBackupConfFile, \%oBackupManifest);
|
||||
|
||||
# Rename the backup tmp path to complete the backup
|
||||
&log(DEBUG, "moving ${strBackupTmpPath} to " . $oFile[0]->path_get(PATH_BACKUP_CLUSTER, $strBackupPath));
|
||||
$oFile[0]->file_move(PATH_BACKUP_TMP, undef, PATH_BACKUP_CLUSTER, $strBackupPath);
|
||||
&log(DEBUG, "moving ${strBackupTmpPath} to " . $oFile->path_get(PATH_BACKUP_CLUSTER, $strBackupPath));
|
||||
$oFile->file_move(PATH_BACKUP_TMP, undef, PATH_BACKUP_CLUSTER, $strBackupPath);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
@@ -1399,7 +1405,7 @@ sub backup_expire
|
||||
}
|
||||
|
||||
my $iIndex = $iFullRetention;
|
||||
@stryPath = $oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 0, 0), "reverse");
|
||||
@stryPath = $oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 0, 0), "reverse");
|
||||
|
||||
while (defined($stryPath[$iIndex]))
|
||||
{
|
||||
@@ -1407,7 +1413,7 @@ sub backup_expire
|
||||
|
||||
# Delete all backups that depend on the full backup. Done in reverse order so that remaining backups will still
|
||||
# be consistent if the process dies
|
||||
foreach $strPath ($oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, "^" . $stryPath[$iIndex] . ".*", "reverse"))
|
||||
foreach $strPath ($oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, "^" . $stryPath[$iIndex] . ".*", "reverse"))
|
||||
{
|
||||
system("rm -rf ${strBackupClusterPath}/${strPath}") == 0 or confess &log(ERROR, "unable to delete backup ${strPath}");
|
||||
}
|
||||
@@ -1425,12 +1431,12 @@ sub backup_expire
|
||||
confess &log(ERROR, "differential_rentention must be a number >= 1");
|
||||
}
|
||||
|
||||
@stryPath = $oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(0, 1, 0), "reverse");
|
||||
@stryPath = $oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(0, 1, 0), "reverse");
|
||||
|
||||
if (defined($stryPath[$iDifferentialRetention]))
|
||||
{
|
||||
# Get a list of all differential and incremental backups
|
||||
foreach $strPath ($oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(0, 1, 1), "reverse"))
|
||||
foreach $strPath ($oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(0, 1, 1), "reverse"))
|
||||
{
|
||||
# Remove all differential and incremental backups before the oldest valid differential
|
||||
if (substr($strPath, 0, length($strPath) - 1) lt $stryPath[$iDifferentialRetention])
|
||||
@@ -1452,15 +1458,15 @@ sub backup_expire
|
||||
# Determine which backup type to use for archive retention (full, differential, incremental)
|
||||
if ($strArchiveRetentionType eq "full")
|
||||
{
|
||||
@stryPath = $oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 0, 0), "reverse");
|
||||
@stryPath = $oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 0, 0), "reverse");
|
||||
}
|
||||
elsif ($strArchiveRetentionType eq "differential" || $strArchiveRetentionType eq "diff")
|
||||
{
|
||||
@stryPath = $oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 1, 0), "reverse");
|
||||
@stryPath = $oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 1, 0), "reverse");
|
||||
}
|
||||
elsif ($strArchiveRetentionType eq "incremental" || $strArchiveRetentionType eq "incr")
|
||||
{
|
||||
@stryPath = $oFile[0]->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 1, 1), "reverse");
|
||||
@stryPath = $oFile->file_list_get(PATH_BACKUP_CLUSTER, undef, backup_regexp_get(1, 1, 1), "reverse");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1499,7 +1505,7 @@ sub backup_expire
|
||||
# even though they are also in the pg_xlog directory (since they have been copied more than once).
|
||||
&log(INFO, "archive retention based on backup " . $strArchiveRetentionBackup);
|
||||
|
||||
my %oManifest = backup_manifest_load($oFile[0]->path_get(PATH_BACKUP_CLUSTER) . "/$strArchiveRetentionBackup/backup.manifest");
|
||||
my %oManifest = backup_manifest_load($oFile->path_get(PATH_BACKUP_CLUSTER) . "/$strArchiveRetentionBackup/backup.manifest");
|
||||
my $strArchiveLast = ${oManifest}{backup}{"archive-start"};
|
||||
|
||||
if (!defined($strArchiveLast))
|
||||
@@ -1510,12 +1516,12 @@ sub backup_expire
|
||||
&log(INFO, "archive retention starts at " . $strArchiveLast);
|
||||
|
||||
# Remove any archive directories or files that are out of date
|
||||
foreach $strPath ($oFile[0]->file_list_get(PATH_BACKUP_ARCHIVE, undef, "^[0-F]{16}\$"))
|
||||
foreach $strPath ($oFile->file_list_get(PATH_BACKUP_ARCHIVE, undef, "^[0-F]{16}\$"))
|
||||
{
|
||||
# If less than first 16 characters of current archive file, then remove the directory
|
||||
if ($strPath lt substr($strArchiveLast, 0, 16))
|
||||
{
|
||||
system("rm -rf " . $oFile[0]->{strBackupClusterPath} . "/archive/" . $strPath) == 0
|
||||
system("rm -rf " . $oFile->{strBackupClusterPath} . "/archive/" . $strPath) == 0
|
||||
or confess &log(ERROR, "unable to remove " . $strPath);
|
||||
&log(DEBUG, "removed major archive directory " . $strPath);
|
||||
}
|
||||
@@ -1525,12 +1531,12 @@ sub backup_expire
|
||||
my $strSubPath;
|
||||
|
||||
# Look for archive files in the archive directory
|
||||
foreach $strSubPath ($oFile[0]->file_list_get(PATH_BACKUP_ARCHIVE, $strPath, "^[0-F]{24}.*\$"))
|
||||
foreach $strSubPath ($oFile->file_list_get(PATH_BACKUP_ARCHIVE, $strPath, "^[0-F]{24}.*\$"))
|
||||
{
|
||||
# Delete if the first 24 characters less than the current archive file
|
||||
if ($strSubPath lt substr($strArchiveLast, 0, 24))
|
||||
{
|
||||
unlink($oFile[0]->path_get(PATH_BACKUP_ARCHIVE, $strSubPath)) or confess &log(ERROR, "unable to remove " . $strSubPath);
|
||||
unlink($oFile->path_get(PATH_BACKUP_ARCHIVE, $strSubPath)) or confess &log(ERROR, "unable to remove " . $strSubPath);
|
||||
&log(DEBUG, "removed expired archive file " . $strSubPath);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -112,10 +112,10 @@ sub clone
|
||||
strCommandDecompress => $self->{strCommandDecompress},
|
||||
strCommandCat => $self->{strCommandCat},
|
||||
strCommandManifest => $self->{strCommandManifest},
|
||||
oDbSSH => $self->{strDbSSH},
|
||||
# oDbSSH => $self->{strDbSSH},
|
||||
strDbUser => $self->{strDbUser},
|
||||
strDbHost => $self->{strDbHost},
|
||||
oBackupSSH => $self->{strBackupSSH},
|
||||
# oBackupSSH => $self->{strBackupSSH},
|
||||
strBackupUser => $self->{strBackupUser},
|
||||
strBackupHost => $self->{strBackupHost},
|
||||
strBackupPath => $self->{strBackupPath},
|
||||
|
||||
Reference in New Issue
Block a user