1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Restore with base path remap working.

This commit is contained in:
David Steele 2015-01-22 19:04:55 -05:00
parent 82969eb497
commit df4b50b977
4 changed files with 119 additions and 48 deletions

View File

@ -20,7 +20,7 @@ use Exporter qw(import);
our @EXPORT = qw(MANIFEST_SECTION_BACKUP MANIFEST_SECTION_BACKUP_OPTION MANIFEST_SECTION_BACKUP_PATH
MANIFEST_SECTION_BACKUP_TABLESPACE
MANIFEST_KEY_ARCHIVE_START MANIFEST_KEY_ARCHIVE_STOP MANIFEST_KEY_CHECKSUM MANIFEST_KEY_COMPRESS
MANIFEST_KEY_ARCHIVE_START MANIFEST_KEY_ARCHIVE_STOP MANIFEST_KEY_BASE MANIFEST_KEY_CHECKSUM MANIFEST_KEY_COMPRESS
MANIFEST_KEY_HARDLINK MANIFEST_KEY_LABEL MANIFEST_KEY_PRIOR MANIFEST_KEY_REFERENCE MANIFEST_KEY_TIMESTAMP_DB_START
MANIFEST_KEY_TIMESTAMP_DB_STOP MANIFEST_KEY_TIMESTAMP_COPY_START MANIFEST_KEY_TIMESTAMP_START
MANIFEST_KEY_TIMESTAMP_STOP MANIFEST_KEY_TYPE MANIFEST_KEY_VERSION
@ -41,6 +41,7 @@ use constant
MANIFEST_KEY_ARCHIVE_START => 'archive-start',
MANIFEST_KEY_ARCHIVE_STOP => 'archive-stop',
MANIFEST_KEY_BASE => 'base',
MANIFEST_KEY_CHECKSUM => 'checksum',
MANIFEST_KEY_COMPRESS => 'compress',
MANIFEST_KEY_HARDLINK => 'hardlink',

View File

@ -187,45 +187,51 @@ sub manifest_load
' - this indicates some sort of corruption (at the very least paths have been renamed.');
}
# If tablespaces have been remapped, update the manifest
if (defined($self->{oRemapRef}))
if ($self->{strDbClusterPath} ne $oManifest->set(MANIFEST_SECTION_BACKUP_PATH, MANIFEST_KEY_BASE))
{
foreach my $strPathKey (sort(keys $self->{oRemapRef}))
{
my $strRemapPath = ${$self->{oRemapRef}}{$strPathKey};
if ($strPathKey eq 'base')
{
&log(INFO, "remapping base to ${strRemapPath}");
$oManifest->set(MANIFEST_SECTION_BACKUP_PATH, $strPathKey, undef, $strRemapPath);
}
else
{
# If the tablespace begins 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 (!$oManifest->test(MANIFEST_SECTION_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 = $oManifest->get(MANIFEST_SECTION_BACKUP_TABLESPACE, $strPathKey, MANIFEST_SUBKEY_LINK);
$oManifest->set(MANIFEST_SECTION_BACKUP_PATH, "tablespace:${strPathKey}", undef, $strRemapPath);
$oManifest->set(MANIFEST_SECTION_BACKUP_TABLESPACE, $strPathKey, MANIFEST_SUBKEY_PATH, $strRemapPath);
$oManifest->set('base:link', "pg_tblspc/${strTablespaceLink}", MANIFEST_SUBKEY_DESTINATION, $strRemapPath);
}
}
&log(INFO, 'base path remapped to ' . $self->{strDbClusterPath});
$oManifest->set(MANIFEST_SECTION_BACKUP_PATH, MANIFEST_KEY_BASE, undef, $self->{strDbClusterPath});
}
# # If tablespaces have been remapped, update the manifest
# if (defined($self->{oRemapRef}))
# {
# foreach my $strPathKey (sort(keys $self->{oRemapRef}))
# {
# my $strRemapPath = ${$self->{oRemapRef}}{$strPathKey};
#
# if ($strPathKey eq 'base')
# {
# &log(INFO, "remapping base to ${strRemapPath}");
# $oManifest->set(MANIFEST_SECTION_BACKUP_PATH, $strPathKey, undef, $strRemapPath);
# }
# else
# {
# # If the tablespace begins 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 (!$oManifest->test(MANIFEST_SECTION_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 = $oManifest->get(MANIFEST_SECTION_BACKUP_TABLESPACE, $strPathKey, MANIFEST_SUBKEY_LINK);
#
# $oManifest->set(MANIFEST_SECTION_BACKUP_PATH, "tablespace:${strPathKey}", undef, $strRemapPath);
# $oManifest->set(MANIFEST_SECTION_BACKUP_TABLESPACE, $strPathKey, MANIFEST_SUBKEY_PATH, $strRemapPath);
# $oManifest->set('base:link', "pg_tblspc/${strTablespaceLink}", MANIFEST_SUBKEY_DESTINATION, $strRemapPath);
# }
# }
# }
$self->manifest_ownership_check($oManifest);
return $oManifest;
@ -276,7 +282,7 @@ sub clean
# If force was not specified then error if any file is found
if (!$self->{bForce} && !$self->{bDelta})
{
confess &log(ERROR, "db path '${strPath}' contains files");
die &log(ERROR, "db path '${strPath}' contains files");
}
my $strFile = "${strPath}/${strName}";

View File

@ -184,6 +184,7 @@ sub BackRestTestBackup_Create
# Create the db paths
BackRestTestCommon_PathCreate(BackRestTestCommon_DbPathGet());
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet());
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet() . '2');
# Create tablespace paths
BackRestTestCommon_PathCreate(BackRestTestCommon_DbTablespacePathGet());
@ -779,21 +780,37 @@ sub BackRestTestBackup_BackupCompare
$oFile->remove(PATH_ABSOLUTE, "${strTestPath}/actual.manifest");
}
####################################################################################################################################
# BackRestTestBackup_CompareRestore
# BackRestTestBackup_Restore
####################################################################################################################################
sub BackRestTestBackup_CompareRestore
sub BackRestTestBackup_Restore
{
my $oFile = shift;
my $strBackup = shift;
my $strStanza = shift;
my $oExpectedManifestRef = shift;
my $oRemapHashRef = shift;
my $bDelta = shift;
my $bForce = shift;
my $strComment = shift;
# Set defaults
$bDelta = defined($bDelta) ? $bDelta : false;
$bForce = defined($bForce) ? $bForce : false;
if (defined($oRemapHashRef))
{
BackRestTestCommon_ConfigRemap($oRemapHashRef, $oExpectedManifestRef);
}
&log(INFO, ' ' . ($bDelta ? 'delta ' : '') . ($bForce ? 'force ' : '') .
(defined($oRemapHashRef) ? 'remap ' : '') . 'restore' .
(defined($strComment) ? " (${strComment})" : ''));
# Create the backup command
BackRestTestCommon_Execute(BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() .
'/pg_backrest.conf ' . (defined($bDelta)? '--delta ' : '') . "--stanza=${strStanza} restore");
'/pg_backrest.conf' . (defined($bDelta) && $bDelta ? ' --delta' : '') .
(defined($bForce) && $bForce ? ' --force' : '') . " --stanza=${strStanza} restore");
}
####################################################################################################################################
@ -1219,8 +1236,8 @@ sub BackRestTestBackup_Test
# Restore - tests various permissions, extra files/paths, missing files/paths
#-----------------------------------------------------------------------------------------------------------------------
my $bForce = true;
&log(INFO, ' ' . ($bForce ? 'force ' : '') . 'restore');
my $bDelta = true;
my $bForce = false;
# Create a path and file that are not in the manifest
BackRestTestBackup_PathCreate(\%oManifest, 'base', 'deleteme');
@ -1238,8 +1255,8 @@ sub BackRestTestBackup_Test
# Remove a file
BackRestTestBackup_FileRemove(\%oManifest, 'base', 'PG_VERSION');
BackRestTestBackup_CompareRestore($oFile, $strFullBackup, $strStanza, \%oManifest, $bForce);
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, \%oManifest, undef, $bDelta, $bForce,
'add and delete files');
# Incr backup - add a tablespace
#-----------------------------------------------------------------------------------------------------------------------
@ -1250,6 +1267,17 @@ sub BackRestTestBackup_Test
my $strBackup = BackRestTestBackup_Backup($strType, $strStanza, $bRemote, $oFile, \%oManifest, 'add tablespace 1');
# Restore -
#-----------------------------------------------------------------------------------------------------------------------
$bDelta = false;
# Remap the base path
my %oRemapHash;
$oRemapHash{base} = BackRestTestCommon_DbCommonPathGet . '2';
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, \%oManifest, \%oRemapHash, $bDelta, $bForce,
'remap base path');
# Resume Incr Backup
#-----------------------------------------------------------------------------------------------------------------------
$strType = 'incr';
@ -1274,7 +1302,7 @@ sub BackRestTestBackup_Test
$strTmpPath, $bRemote);
$strBackup = BackRestTestBackup_Backup($strType, $strStanza, $bRemote, $oFile, \%oManifest,
'resume', TEST_BACKUP_NORESUME);
'resume - fail', TEST_BACKUP_NORESUME);
# Incr Backup
#-----------------------------------------------------------------------------------------------------------------------

View File

@ -29,7 +29,7 @@ our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin BackRe
BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest
BackRestTestCommon_PathCreate BackRestTestCommon_PathMode BackRestTestCommon_PathRemove
BackRestTestCommon_FileCreate BackRestTestCommon_FileRemove BackRestTestCommon_PathCopy BackRestTestCommon_PathMove
BackRestTestCommon_ConfigCreate BackRestTestCommon_Run BackRestTestCommon_Cleanup
BackRestTestCommon_ConfigCreate BackRestTestCommon_ConfigRemap BackRestTestCommon_Run BackRestTestCommon_Cleanup
BackRestTestCommon_PgSqlBinPathGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet
BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet
BackRestTestCommon_GroupGet BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet
@ -410,6 +410,42 @@ sub BackRestTestCommon_Setup
$bNoCleanup = $bNoCleanupParam;
}
####################################################################################################################################
# BackRestTestCommon_ConfigRemap
####################################################################################################################################
sub BackRestTestCommon_ConfigRemap
{
my $oRemapHashRef = shift;
my $oManifestRef = shift;
# Create config filename
my $strConfigFile = BackRestTestCommon_DbPathGet() . '/pg_backrest.conf';
my $strStanza = BackRestTestCommon_StanzaGet();
# Load Config file
my %oConfig;
ini_load($strConfigFile, \%oConfig);
# Rewrite remap section
delete($oConfig{"${strStanza}:tablespace:map"});
foreach my $strRemap (sort(keys $oRemapHashRef))
{
if ($strRemap eq 'base')
{
$oConfig{$strStanza}{path} = ${$oRemapHashRef}{$strRemap};
${$oManifestRef}{'backup:path'}{base} = ${$oRemapHashRef}{$strRemap};
}
else
{
confess " not coded yet";
}
}
# Resave the config file
ini_save($strConfigFile, \%oConfig);
}
####################################################################################################################################
# BackRestTestCommon_ConfigCreate
####################################################################################################################################