2014-12-18 18:42:54 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# RESTORE MODULE
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRest::Restore;
|
|
|
|
|
|
|
|
use threads;
|
2014-12-22 18:24:32 +02:00
|
|
|
use threads::shared;
|
|
|
|
use Thread::Queue;
|
2014-12-18 18:42:54 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Carp;
|
|
|
|
|
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
use lib dirname($0);
|
|
|
|
use BackRest::Utility;
|
2014-12-22 18:24:32 +02:00
|
|
|
use BackRest::ThreadGroup;
|
2014-12-18 18:42:54 +02:00
|
|
|
use BackRest::Config;
|
|
|
|
use BackRest::File;
|
2014-12-22 18:24:32 +02:00
|
|
|
|
2014-12-18 18:42:54 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# CONSTRUCTOR
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
my $strDbClusterPath = shift; # Database cluster path
|
2014-12-23 18:48:51 +02:00
|
|
|
my $strBackupPath = shift; # Backup to restore
|
2014-12-23 22:03:06 +02:00
|
|
|
my $oRemapRef = shift; # Tablespace remaps
|
2014-12-23 19:48:25 +02:00
|
|
|
my $oFile = shift; # Default file object
|
2014-12-22 18:24:32 +02:00
|
|
|
my $iThreadTotal = shift; # Total threads to run for restore
|
2014-12-19 19:49:56 +02:00
|
|
|
my $bForce = shift; # Force the restore even if files are present
|
2014-12-18 18:42:54 +02:00
|
|
|
|
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Initialize variables
|
|
|
|
$self->{strDbClusterPath} = $strDbClusterPath;
|
2014-12-23 19:48:25 +02:00
|
|
|
$self->{oFile} = $oFile;
|
2014-12-22 18:24:32 +02:00
|
|
|
$self->{thread_total} = $iThreadTotal;
|
2014-12-19 19:49:56 +02:00
|
|
|
$self->{bForce} = $bForce;
|
2014-12-23 22:03:06 +02:00
|
|
|
$self->{oRemapRef} = $oRemapRef;
|
2014-12-18 18:42:54 +02:00
|
|
|
|
2014-12-19 19:49:56 +02:00
|
|
|
# If backup path is not specified then default to latest
|
2014-12-23 18:48:51 +02:00
|
|
|
if (defined($strBackupPath))
|
2014-12-18 18:42:54 +02:00
|
|
|
{
|
2014-12-23 18:48:51 +02:00
|
|
|
$self->{strBackupPath} = $strBackupPath;
|
2014-12-18 18:42:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-23 18:48:51 +02:00
|
|
|
$self->{strBackupPath} = PATH_LATEST;
|
2014-12-18 18:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2014-12-23 22:03:06 +02:00
|
|
|
# MANIFEST_LOAD
|
2014-12-23 19:48:25 +02:00
|
|
|
#
|
2014-12-23 22:03:06 +02:00
|
|
|
# Loads the backup manifest and performs requested tablespace remaps.
|
2014-12-18 18:42:54 +02:00
|
|
|
####################################################################################################################################
|
2014-12-23 22:03:06 +02:00
|
|
|
sub manifest_load
|
2014-12-18 18:42:54 +02:00
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
my $self = shift; # Class hash
|
|
|
|
my $oManifestRef = shift; # Backup manifest
|
2014-12-23 19:48:25 +02:00
|
|
|
|
|
|
|
if ($self->{oFile}->exists(PATH_BACKUP_CLUSTER, $self->{strBackupPath}))
|
2014-12-18 18:42:54 +02:00
|
|
|
{
|
|
|
|
# Copy the backup manifest to the db cluster path
|
2014-12-23 19:48:25 +02:00
|
|
|
$self->{oFile}->copy(PATH_BACKUP_CLUSTER, $self->{strBackupPath} . '/' . FILE_MANIFEST,
|
2014-12-19 00:05:06 +02:00
|
|
|
PATH_DB_ABSOLUTE, $self->{strDbClusterPath} . '/' . FILE_MANIFEST);
|
2014-12-18 18:42:54 +02:00
|
|
|
|
|
|
|
# Load the manifest into a hash
|
2014-12-23 22:03:06 +02:00
|
|
|
ini_load($self->{oFile}->path_get(PATH_DB_ABSOLUTE, $self->{strDbClusterPath} . '/' . FILE_MANIFEST), $oManifestRef);
|
2014-12-18 18:42:54 +02:00
|
|
|
|
|
|
|
# Remove the manifest now that it is in memory
|
2014-12-23 19:48:25 +02:00
|
|
|
$self->{oFile}->remove(PATH_DB_ABSOLUTE, $self->{strDbClusterPath} . '/' . FILE_MANIFEST);
|
2014-12-23 18:48:51 +02:00
|
|
|
|
2014-12-23 22:03:06 +02:00
|
|
|
# If tablespaces have been remapped, update the manifest
|
|
|
|
if (defined($self->{oRemapRef}))
|
2014-12-23 18:48:51 +02:00
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
foreach my $strPathKey (sort(keys $self->{oRemapRef}))
|
|
|
|
{
|
|
|
|
my $strRemapPath = ${$self->{oRemapRef}}{$strPathKey};
|
|
|
|
|
|
|
|
if ($strPathKey eq 'base')
|
|
|
|
{
|
|
|
|
&log(INFO, "remapping base to ${strRemapPath}");
|
|
|
|
${$oManifestRef}{'backup:path'}{$strPathKey} = $strRemapPath;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# If the tablespace beigns with prefix 'tablespace:' then strip the prefix. This only needs to be used in
|
|
|
|
# the case that there is a tablespace called 'base'
|
|
|
|
if (index($strPathKey, 'tablespace:') == 0)
|
|
|
|
{
|
|
|
|
$strPathKey = substr($strPathKey, length('tablespace:'));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure that the tablespace exists in the manifest
|
|
|
|
if (!defined(${$oManifestRef}{'backup:tablespace'}{$strPathKey}))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "cannot remap invalid tablespace ${strPathKey} to ${strRemapPath}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remap the tablespace in the manifest
|
|
|
|
&log(INFO, "remapping tablespace to ${strRemapPath}");
|
|
|
|
|
|
|
|
my $strTablespaceLink = ${$oManifestRef}{'backup:tablespace'}{$strPathKey}{link};
|
|
|
|
|
|
|
|
${$oManifestRef}{'backup:path'}{"tablespace:${strPathKey}"} = $strRemapPath;
|
|
|
|
${$oManifestRef}{'backup:tablespace'}{$strPathKey}{path} = $strRemapPath;
|
|
|
|
${$oManifestRef}{'base:link'}{"pg_tblspc/${strTablespaceLink}"}{link_destination} = $strRemapPath;
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 18:48:51 +02:00
|
|
|
}
|
2014-12-18 18:42:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-23 18:48:51 +02:00
|
|
|
confess &log(ERROR, 'backup ' . $self->{strBackupPath} . ' does not exist');
|
2014-12-18 18:42:54 +02:00
|
|
|
}
|
2014-12-23 22:03:06 +02:00
|
|
|
}
|
2014-12-19 19:49:56 +02:00
|
|
|
|
2014-12-23 22:03:06 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# CLEAN
|
|
|
|
#
|
|
|
|
# Checks that the restore paths are empty, or if --force was used then it cleans files/paths/links from the restore directories that
|
|
|
|
# are not present in the manifest.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub clean
|
|
|
|
{
|
|
|
|
my $self = shift; # Class hash
|
|
|
|
my $oManifestRef = shift; # Backup manifest
|
2014-12-22 18:24:32 +02:00
|
|
|
|
2014-12-19 19:49:56 +02:00
|
|
|
# Check each restore directory in the manifest and make sure that it exists and is empty.
|
|
|
|
# The --force option can be used to override the empty requirement.
|
2014-12-23 22:03:06 +02:00
|
|
|
foreach my $strPathKey (sort(keys ${$oManifestRef}{'backup:path'}))
|
2014-12-19 19:49:56 +02:00
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
my $strPath = ${$oManifestRef}{'backup:path'}{$strPathKey};
|
2014-12-19 19:49:56 +02:00
|
|
|
|
2014-12-23 22:03:06 +02:00
|
|
|
&log(INFO, "checking/cleaning db path ${strPath}");
|
2014-12-21 17:11:17 +02:00
|
|
|
|
2014-12-23 19:48:25 +02:00
|
|
|
if (!$self->{oFile}->exists(PATH_DB_ABSOLUTE, $strPath))
|
2014-12-19 19:49:56 +02:00
|
|
|
{
|
|
|
|
confess &log(ERROR, "required db path '${strPath}' does not exist");
|
|
|
|
}
|
|
|
|
|
2014-12-23 22:03:06 +02:00
|
|
|
# Load path manifest so it can be compared to deleted files/paths/links that are not in the backup
|
2014-12-19 19:49:56 +02:00
|
|
|
my %oPathManifest;
|
2014-12-23 19:48:25 +02:00
|
|
|
$self->{oFile}->manifest(PATH_DB_ABSOLUTE, $strPath, \%oPathManifest);
|
2014-12-19 19:49:56 +02:00
|
|
|
|
|
|
|
foreach my $strName (sort {$b cmp $a} (keys $oPathManifest{name}))
|
|
|
|
{
|
|
|
|
# Skip the root path
|
|
|
|
if ($strName eq '.')
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# If force was not specified then error if any file is found
|
|
|
|
if (!$self->{bForce})
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "db path '${strPath}' contains files");
|
|
|
|
}
|
|
|
|
|
2014-12-21 17:11:17 +02:00
|
|
|
my $strFile = "${strPath}/${strName}";
|
|
|
|
|
2014-12-19 19:49:56 +02:00
|
|
|
# Determine the file/path/link type
|
|
|
|
my $strType = 'file';
|
|
|
|
|
|
|
|
if ($oPathManifest{name}{$strName}{type} eq 'd')
|
|
|
|
{
|
|
|
|
$strType = 'path';
|
|
|
|
}
|
|
|
|
elsif ($oPathManifest{name}{$strName}{type} eq 'l')
|
|
|
|
{
|
|
|
|
$strType = 'link';
|
|
|
|
}
|
|
|
|
|
2014-12-21 17:11:17 +02:00
|
|
|
# Check to see if the file/path/link exists in the manifest
|
2014-12-23 22:03:06 +02:00
|
|
|
if (defined(${$oManifestRef}{"${strPathKey}:${strType}"}{$strName}))
|
2014-12-19 19:49:56 +02:00
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
my $strMode = ${$oManifestRef}{"${strPathKey}:${strType}"}{$strName}{permission};
|
2014-12-21 17:11:17 +02:00
|
|
|
|
|
|
|
# If file/path mode does not match, fix it
|
|
|
|
if ($strType ne 'link' && $strMode ne $oPathManifest{name}{$strName}{permission})
|
|
|
|
{
|
|
|
|
&log(DEBUG, "setting ${strFile} mode to ${strMode}");
|
|
|
|
|
|
|
|
chmod(oct($strMode), $strFile)
|
|
|
|
or confess 'unable to set mode ${strMode} for ${strFile}';
|
|
|
|
}
|
|
|
|
|
2014-12-23 22:03:06 +02:00
|
|
|
my $strUser = ${$oManifestRef}{"${strPathKey}:${strType}"}{$strName}{user};
|
|
|
|
my $strGroup = ${$oManifestRef}{"${strPathKey}:${strType}"}{$strName}{group};
|
2014-12-21 17:11:17 +02:00
|
|
|
|
|
|
|
# If ownership does not match, fix it
|
|
|
|
if ($strUser ne $oPathManifest{name}{$strName}{user} ||
|
|
|
|
$strGroup ne $oPathManifest{name}{$strName}{group})
|
|
|
|
{
|
|
|
|
&log(DEBUG, "setting ${strFile} ownership to ${strUser}:${strGroup}");
|
|
|
|
|
|
|
|
# !!! Need to decide if it makes sense to set the user to anything other than the db owner
|
|
|
|
}
|
2014-12-19 19:49:56 +02:00
|
|
|
|
2014-12-21 17:11:17 +02:00
|
|
|
# If a link does not have the same destination, then delete it (it will be recreated later)
|
2014-12-23 22:03:06 +02:00
|
|
|
if ($strType eq 'link' && ${$oManifestRef}{"${strPathKey}:${strType}"}{$strName}{link_destination} ne
|
2014-12-21 17:11:17 +02:00
|
|
|
$oPathManifest{name}{$strName}{link_destination})
|
|
|
|
{
|
|
|
|
&log(DEBUG, "removing link ${strFile} - destination changed");
|
|
|
|
unlink($strFile) or confess &log(ERROR, "unable to delete file ${strFile}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# If it does not then remove it
|
|
|
|
else
|
|
|
|
{
|
2014-12-19 19:49:56 +02:00
|
|
|
# If a path then remove it, all the files should have already been deleted since we are going in reverse order
|
|
|
|
if ($strType eq 'path')
|
|
|
|
{
|
2014-12-21 17:11:17 +02:00
|
|
|
&log(DEBUG, "removing path ${strFile}");
|
|
|
|
rmdir($strFile) or confess &log(ERROR, "unable to delete path ${strFile}, is it empty?");
|
2014-12-19 19:49:56 +02:00
|
|
|
}
|
2014-12-21 17:11:17 +02:00
|
|
|
# Else delete a file/link
|
2014-12-19 19:49:56 +02:00
|
|
|
else
|
|
|
|
{
|
2014-12-21 17:11:17 +02:00
|
|
|
&log(DEBUG, "removing file ${strFile}");
|
|
|
|
unlink($strFile) or confess &log(ERROR, "unable to delete file ${strFile}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 22:03:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BUILD
|
|
|
|
#
|
|
|
|
# Creates missing paths and links and corrects ownership/mode on existing paths and links.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub build
|
|
|
|
{
|
|
|
|
my $self = shift; # Class hash
|
|
|
|
my $oManifestRef = shift; # Backup manifest
|
|
|
|
|
|
|
|
# Build paths/links in each restore path
|
|
|
|
foreach my $strPathKey (sort(keys ${$oManifestRef}{'backup:path'}))
|
|
|
|
{
|
|
|
|
my $strPath = ${$oManifestRef}{'backup:path'}{$strPathKey};
|
2014-12-21 17:11:17 +02:00
|
|
|
|
|
|
|
# Create all paths in the manifest that do not already exist
|
2014-12-23 22:03:06 +02:00
|
|
|
foreach my $strName (sort (keys ${$oManifestRef}{"${strPathKey}:path"}))
|
2014-12-21 17:11:17 +02:00
|
|
|
{
|
|
|
|
# Skip the root path
|
|
|
|
if ($strName eq '.')
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create the Path
|
2014-12-23 19:48:25 +02:00
|
|
|
$self->{oFile}->path_create(PATH_DB_ABSOLUTE, "${strPath}/${strName}",
|
2014-12-23 22:03:06 +02:00
|
|
|
${$oManifestRef}{"${strPathKey}:path"}{$strName}{permission});
|
2014-12-21 17:11:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create all links in the manifest that do not already exist
|
2014-12-23 22:03:06 +02:00
|
|
|
if (defined(${$oManifestRef}{"${strPathKey}:link"}))
|
2014-12-21 17:11:17 +02:00
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
foreach my $strName (sort (keys ${$oManifestRef}{"${strPathKey}:link"}))
|
2014-12-21 17:11:17 +02:00
|
|
|
{
|
2014-12-23 19:48:25 +02:00
|
|
|
if (!$self->{oFile}->exists(PATH_DB_ABSOLUTE, "${strPath}/${strName}"))
|
2014-12-21 17:11:17 +02:00
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
$self->{oFile}->link_create(PATH_DB_ABSOLUTE,
|
|
|
|
${$oManifestRef}{"${strPathKey}:link"}{$strName}{link_destination},
|
2014-12-23 19:48:25 +02:00
|
|
|
PATH_DB_ABSOLUTE, "${strPath}/${strName}");
|
2014-12-19 19:49:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 22:03:06 +02:00
|
|
|
}
|
|
|
|
}
|
2014-12-22 18:24:32 +02:00
|
|
|
|
2014-12-23 22:03:06 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# RESTORE
|
|
|
|
#
|
|
|
|
# Takes a backup and restores it back to the original or a remapped location.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub restore
|
|
|
|
{
|
|
|
|
my $self = shift; # Class hash
|
|
|
|
|
|
|
|
# Make sure that Postgres is not running
|
|
|
|
if ($self->{oFile}->exists(PATH_DB_ABSOLUTE, $self->{strDbClusterPath} . '/' . FILE_POSTMASTER_PID))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'unable to restore while Postgres is running');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure the backup path is valid and load the manifest
|
|
|
|
my %oManifest;
|
|
|
|
$self->manifest_load(\%oManifest);
|
|
|
|
|
|
|
|
# Clean the restore paths
|
|
|
|
$self->clean(\%oManifest);
|
|
|
|
|
|
|
|
# Build paths/links in the restore paths
|
|
|
|
$self->build(\%oManifest);
|
|
|
|
|
|
|
|
# Assign the files in each path to a thread queue
|
|
|
|
my @oyRestoreQueue;
|
|
|
|
|
|
|
|
foreach my $strPathKey (sort(keys $oManifest{'backup:path'}))
|
|
|
|
{
|
2014-12-22 18:24:32 +02:00
|
|
|
if (defined($oManifest{"${strPathKey}:file"}))
|
|
|
|
{
|
2014-12-23 19:48:25 +02:00
|
|
|
$oyRestoreQueue[@oyRestoreQueue] = Thread::Queue->new();
|
2014-12-22 18:24:32 +02:00
|
|
|
|
|
|
|
foreach my $strName (sort (keys $oManifest{"${strPathKey}:file"}))
|
|
|
|
{
|
2014-12-23 19:48:25 +02:00
|
|
|
$oyRestoreQueue[@oyRestoreQueue - 1]->enqueue("${strPathKey}|${strName}");
|
2014-12-22 18:24:32 +02:00
|
|
|
}
|
|
|
|
|
2014-12-23 19:48:25 +02:00
|
|
|
$oyRestoreQueue[@oyRestoreQueue - 1]->end();
|
2014-12-22 18:24:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create threads to process the thread queues
|
|
|
|
my $oThreadGroup = new BackRest::ThreadGroup();
|
|
|
|
|
|
|
|
for (my $iThreadIdx = 0; $iThreadIdx < $self->{thread_total}; $iThreadIdx++)
|
|
|
|
{
|
2014-12-23 19:48:25 +02:00
|
|
|
$oThreadGroup->add(threads->create(\&restore_thread, $self, $iThreadIdx, \@oyRestoreQueue, \%oManifest));
|
2014-12-22 18:24:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oThreadGroup->complete();
|
|
|
|
}
|
|
|
|
|
2014-12-23 19:48:25 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# RESTORE_THREAD
|
|
|
|
#
|
|
|
|
# Worker threads for the restore process.
|
|
|
|
####################################################################################################################################
|
2014-12-22 18:24:32 +02:00
|
|
|
sub restore_thread
|
|
|
|
{
|
2014-12-23 19:48:25 +02:00
|
|
|
my $self = shift; # Class hash
|
|
|
|
my $iThreadIdx = shift; # Defines the index of this thread
|
2014-12-23 22:03:06 +02:00
|
|
|
my $oyRestoreQueueRef = shift; # Restore queues
|
|
|
|
my $oManifestRef = shift; # Backup manifest
|
2014-12-22 18:24:32 +02:00
|
|
|
|
2014-12-23 19:48:25 +02:00
|
|
|
my $iDirection = $iThreadIdx % 2 == 0 ? 1 : -1; # Size of files currently copied by this thread
|
|
|
|
my $oFileThread = $self->{oFile}->clone($iThreadIdx); # Thread local file object
|
2014-12-22 18:24:32 +02:00
|
|
|
|
2014-12-23 18:48:51 +02:00
|
|
|
# Initialize the starting and current queue index based in the total number of threads in relation to this thread
|
2014-12-23 22:03:06 +02:00
|
|
|
my $iQueueStartIdx = int((@{$oyRestoreQueueRef} / $self->{thread_total}) * $iThreadIdx);
|
2014-12-22 18:24:32 +02:00
|
|
|
my $iQueueIdx = $iQueueStartIdx;
|
|
|
|
|
2014-12-23 22:03:06 +02:00
|
|
|
# Set source compression
|
|
|
|
my $bSourceCompression = ${$oManifestRef}{'backup:option'}{compress} eq 'y';
|
|
|
|
|
2014-12-22 18:24:32 +02:00
|
|
|
# When a KILL signal is received, immediately abort
|
|
|
|
$SIG{'KILL'} = sub {threads->exit();};
|
|
|
|
|
2014-12-23 18:48:51 +02:00
|
|
|
# Loop through all the queues to restore files (exit when the original queue is reached
|
2014-12-22 18:24:32 +02:00
|
|
|
do
|
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
while (my $strMessage = ${$oyRestoreQueueRef}[$iQueueIdx]->dequeue())
|
2014-12-22 18:24:32 +02:00
|
|
|
{
|
2014-12-23 19:48:25 +02:00
|
|
|
my $strSourcePath = (split(/\|/, $strMessage))[0]; # Source path from backup
|
|
|
|
my $strSection = "${strSourcePath}:file"; # Backup section with file info
|
2014-12-23 22:03:06 +02:00
|
|
|
my $strDestinationPath = ${$oManifestRef}{'backup:path'}{$strSourcePath}; # Destination path stored in manifest
|
2014-12-23 19:48:25 +02:00
|
|
|
$strSourcePath =~ s/\:/\//g; # Replace : with / in source path
|
|
|
|
my $strName = (split(/\|/, $strMessage))[1]; # Name of file to be restored
|
2014-12-22 18:24:32 +02:00
|
|
|
|
|
|
|
# Generate destination file name
|
|
|
|
my $strDestinationFile = $oFileThread->path_get(PATH_DB_ABSOLUTE, "${strDestinationPath}/${strName}");
|
|
|
|
|
|
|
|
# If checksum is set the destination file already exists, try a checksum before copying
|
2014-12-23 22:03:06 +02:00
|
|
|
my $strChecksum = ${$oManifestRef}{$strSection}{$strName}{checksum};
|
2014-12-22 18:24:32 +02:00
|
|
|
|
|
|
|
if ($oFileThread->exists(PATH_DB_ABSOLUTE, $strDestinationFile))
|
|
|
|
{
|
|
|
|
if (defined($strChecksum) && $oFileThread->hash(PATH_DB_ABSOLUTE, $strDestinationFile) eq $strChecksum)
|
|
|
|
{
|
|
|
|
&log(DEBUG, "${strDestinationFile} exists and matches backup checksum ${strChecksum}");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$oFileThread->remove(PATH_DB_ABSOLUTE, $strDestinationFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy the file from the backup to the database
|
2014-12-23 19:48:25 +02:00
|
|
|
$oFileThread->copy(PATH_BACKUP_CLUSTER, $self->{strBackupPath} . "/${strSourcePath}/${strName}" .
|
2014-12-23 22:03:06 +02:00
|
|
|
($bSourceCompression ? '.' . $oFileThread->{strCompressExtension} : ''),
|
2014-12-22 18:24:32 +02:00
|
|
|
PATH_DB_ABSOLUTE, $strDestinationFile,
|
2014-12-23 22:03:06 +02:00
|
|
|
$bSourceCompression, # Source is compressed based on backup settings
|
2014-12-23 18:48:51 +02:00
|
|
|
undef, undef,
|
2014-12-23 22:03:06 +02:00
|
|
|
${$oManifestRef}{$strSection}{$strName}{modification_time},
|
|
|
|
${$oManifestRef}{$strSection}{$strName}{permission});
|
2014-12-22 18:24:32 +02:00
|
|
|
}
|
|
|
|
|
2014-12-23 18:48:51 +02:00
|
|
|
# Even number threads move up when they have finished a queue, odd numbered threads move down
|
2014-12-22 18:24:32 +02:00
|
|
|
$iQueueIdx += $iDirection;
|
|
|
|
|
2014-12-23 18:48:51 +02:00
|
|
|
# Reset the queue index when it goes over or under the number of queues
|
2014-12-22 18:24:32 +02:00
|
|
|
if ($iQueueIdx < 0)
|
|
|
|
{
|
2014-12-23 22:03:06 +02:00
|
|
|
$iQueueIdx = @{$oyRestoreQueueRef} - 1;
|
2014-12-22 18:24:32 +02:00
|
|
|
}
|
2014-12-23 22:03:06 +02:00
|
|
|
elsif ($iQueueIdx >= @{$oyRestoreQueueRef})
|
2014-12-22 18:24:32 +02:00
|
|
|
{
|
|
|
|
$iQueueIdx = 0;
|
|
|
|
}
|
2014-12-19 19:49:56 +02:00
|
|
|
}
|
2014-12-22 18:24:32 +02:00
|
|
|
while ($iQueueIdx != $iQueueStartIdx);
|
|
|
|
|
|
|
|
&log(DEBUG, "thread ${iThreadIdx} exiting");
|
2014-12-18 18:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|