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

More work on backup unit tests - added tablespace tests.

This commit is contained in:
David Steele
2014-10-19 16:30:16 -04:00
parent 4de1d9aa5a
commit 66a5da6fd1
3 changed files with 137 additions and 38 deletions

View File

@@ -705,7 +705,7 @@ sub backup_file_not_in_manifest
if ($strBasePath eq $strName)
{
my $strSection = $strBasePath eq 'tablespace' ? 'base:tablespace' : "${strBasePath}:path";
my $strSection = $strBasePath eq 'tablespace' ? 'backup:tablespace' : "${strBasePath}:path";
if (defined(${$oManifestRef}{"${strSection}"}))
{
@@ -861,16 +861,15 @@ sub backup_manifest_build
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{user} = $oManifestHash{name}{"${strName}"}{user};
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{group} = $oManifestHash{name}{"${strName}"}{group};
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{permission} = $oManifestHash{name}{"${strName}"}{permission};
if ($cType eq 'f')
if ($cType eq 'f' || $cType eq 'd')
{
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{size} = $oManifestHash{name}{"${strName}"}{size} + 0;
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{modification_time} = $oManifestHash{name}{"${strName}"}{modification_time} + 0;
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{permission} = $oManifestHash{name}{"${strName}"}{permission};
}
if ($cType eq 'f')
{
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{modification_time} = $oManifestHash{name}{"${strName}"}{modification_time} + 0;
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{inode} = $oManifestHash{name}{"${strName}"}{inode} + 0;
${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{size} = $oManifestHash{name}{"${strName}"}{size} + 0;
@@ -929,8 +928,8 @@ sub backup_manifest_build
my $strTablespaceOid = basename($strName);
my $strTablespaceName = ${$oTablespaceMapRef}{oid}{"${strTablespaceOid}"}{name};
${$oBackupManifestRef}{"${strLevel}:tablespace"}{"${strTablespaceName}"}{oid} = $strTablespaceOid + 0;
${$oBackupManifestRef}{"${strLevel}:tablespace"}{"${strTablespaceName}"}{path} = $strLinkDestination;
${$oBackupManifestRef}{"backup:tablespace"}{"${strTablespaceName}"}{link} = $strTablespaceOid;
${$oBackupManifestRef}{"backup:tablespace"}{"${strTablespaceName}"}{path} = $strLinkDestination;
backup_manifest_build($strLinkDestination, $oBackupManifestRef, $oLastManifestRef,
$oTablespaceMapRef, "tablespace:${strTablespaceName}");
@@ -995,10 +994,12 @@ sub backup_file
{
$lTablespaceIdx++;
my $strTablespaceName = (split(':', $strSectionPath))[1];
$strBackupSourcePath = ${$oBackupManifestRef}{'base:tablespace'}{"${strTablespaceName}"}{path};
$strBackupSourcePath = ${$oBackupManifestRef}{'backup:tablespace'}{"${strTablespaceName}"}{path};
$strBackupDestinationPath = "tablespace/${strTablespaceName}";
$strSectionFile = "tablespace:${strTablespaceName}:file";
${$oBackupManifestRef}{'backup:path'}{"tablespace:${strTablespaceName}"} = $strBackupSourcePath;
# Create the tablespace directory and link
if ($bPathCreate)
{
@@ -1006,7 +1007,7 @@ sub backup_file
$oFile->link_create(PATH_BACKUP_TMP, ${strBackupDestinationPath},
PATH_BACKUP_TMP,
'base/pg_tblspc/' . ${$oBackupManifestRef}{'base:tablespace'}{"${strTablespaceName}"}{oid},
'base/pg_tblspc/' . ${$oBackupManifestRef}{'backup:tablespace'}{"${strTablespaceName}"}{link},
false, true);
}
}
@@ -1386,6 +1387,11 @@ sub backup
${oBackupManifest}{backup}{type} = $strType;
if ($strType ne BACKUP_TYPE_FULL)
{
${oBackupManifest}{'backup:option'}{'hardlink'} = $bHardLink ? 'y' : 'n';
}
# Build backup tmp and config
my $strBackupTmpPath = $oFile->path_get(PATH_BACKUP_TMP);
my $strBackupConfFile = $oFile->path_get(PATH_BACKUP_TMP, 'backup.manifest');

View File

@@ -210,6 +210,105 @@ sub BackRestTestBackup_Create
}
}
####################################################################################################################################
# BackRestTestBackup_ManifestPathCreate
#
# Create a path specifying mode and add it to the manifest.
####################################################################################################################################
sub BackRestTestBackup_ManifestPathCreate
{
my $oManifestRef = shift;
my $strPath = shift;
my $strSubPath = shift;
my $strMode = shift;
# Create final file location
my $strFinalPath = ${$oManifestRef}{'backup:path'}{$strPath} . (defined($strSubPath) ? "/${strSubPath}" : '');
# Create the path
if (!(-e $strFinalPath))
{
BackRestTestCommon_PathCreate($strFinalPath, $strMode);
}
# Stat the file
my $oStat = lstat($strFinalPath);
# Check for errors in stat
if (!defined($oStat))
{
confess 'unable to stat ${strSubPath}';
}
my $strManifestPath = defined($strSubPath) ? $strSubPath : '.';
# Load file into manifest
${$oManifestRef}{"${strPath}:path"}{$strManifestPath}{group} = getgrgid($oStat->gid);
${$oManifestRef}{"${strPath}:path"}{$strManifestPath}{user} = getpwuid($oStat->uid);
${$oManifestRef}{"${strPath}:path"}{$strManifestPath}{permission} = sprintf('%04o', S_IMODE($oStat->mode));
}
####################################################################################################################################
# BackRestTestBackup_ManifestTablespaceCreate
#
# Create a tablespace specifying mode and add it to the manifest.
####################################################################################################################################
sub BackRestTestBackup_ManifestTablespaceCreate
{
my $oManifestRef = shift;
my $iOid = shift;
my $strMode = shift;
# Create final file location
my $strPath = BackRestTestCommon_DbPathGet() . "/ts${iOid}";
# Create the path
if (!(-e $strPath))
{
BackRestTestCommon_PathCreate($strPath, $strMode);
}
# Stat the path
my $oStat = lstat($strPath);
# Check for errors in stat
if (!defined($oStat))
{
confess 'unable to stat path ${strPath}';
}
# Load path into manifest
${$oManifestRef}{"tablespace:${iOid}:path"}{'.'}{group} = getgrgid($oStat->gid);
${$oManifestRef}{"tablespace:${iOid}:path"}{'.'}{user} = getpwuid($oStat->uid);
${$oManifestRef}{"tablespace:${iOid}:path"}{'.'}{permission} = sprintf('%04o', S_IMODE($oStat->mode));
# Create the link in pg_tblspc
my $strLink = BackRestTestCommon_DbCommonPathGet() . "/pg_tblspc/${iOid}";
symlink($strPath, $strLink)
or confess "unable to link ${strLink} to ${strPath}";
# Stat the link
$oStat = lstat($strLink);
# Check for errors in stat
if (!defined($oStat))
{
confess 'unable to stat link ${strLink}';
}
# Load link into the manifest
${$oManifestRef}{"base:link"}{"pg_tblspc/${iOid}"}{group} = getgrgid($oStat->gid);
${$oManifestRef}{"base:link"}{"pg_tblspc/${iOid}"}{user} = getpwuid($oStat->uid);
${$oManifestRef}{"base:link"}{"pg_tblspc/${iOid}"}{link_destination} = $strPath;
# Load tablespace into the manifest
${$oManifestRef}{"backup:tablespace"}{$iOid}{link} = $iOid;
${$oManifestRef}{"backup:tablespace"}{$iOid}{path} = $strPath;
${$oManifestRef}{"backup:path"}{"tablespace:${iOid}"} = $strPath;
}
####################################################################################################################################
# BackRestTestBackup_ManifestFileCreate
#
@@ -253,10 +352,6 @@ sub BackRestTestBackup_ManifestFileCreate
{
${$oManifestRef}{"${strPath}:file"}{$strFile}{checksum} = $strChecksum;
}
else
{
delete(${$oManifestRef}{"${strPath}:file"}{$strFile}{checksum});
}
}
####################################################################################################################################
@@ -692,13 +787,12 @@ sub BackRestTestBackup_Test
{
for (my $bHardlink = false; $bHardlink <= true; $bHardlink++)
{
for (my $bTablespace = false; $bTablespace <= true; $bTablespace++)
for (my $iTablespaceTotal = false; $iTablespaceTotal <= 2; $iTablespaceTotal++)
{
# Increment the run, log, and decide whether this unit test should be run
if (!BackRestTestCommon_Run(++$iRun,
"rmt ${bRemote}, cmp ${bCompress}, chk ${bChecksum}, " .
"hardlink ${bHardlink}, tblspc ${bTablespace}")) {next}
# Initialize the manifest
"hardlink ${bHardlink}, tblspc ${iTablespaceTotal}")) {next}
# Get base time
my $lTime = time() - 100000;
@@ -715,9 +809,7 @@ sub BackRestTestBackup_Test
$oManifest{'backup:path'}{base} = BackRestTestCommon_DbCommonPathGet();
$oManifest{'base:path'}{'.'}{group} = $strGroup;
$oManifest{'base:path'}{'.'}{user} = $strUser;
$oManifest{'base:path'}{'.'}{permission} = '0700';
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base');
# Create the file object
my $oFile = new BackRest::File
@@ -728,24 +820,23 @@ sub BackRestTestBackup_Test
$bRemote ? $oRemote : undef
);
# Create the db/common/pg_tblspc directory
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet() . '/pg_tblspc');
# Create base path
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base', 'base');
$oManifest{'base:path'}{'pg_tblspc'}{group} = $strGroup;
$oManifest{'base:path'}{'pg_tblspc'}{user} = $strUser;
$oManifest{'base:path'}{'pg_tblspc'}{permission} = '0700';
# Create the db/common/base directory
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet() . '/base');
$oManifest{'base:path'}{'base'}{group} = $strGroup;
$oManifest{'base:path'}{'base'}{user} = $strUser;
$oManifest{'base:path'}{'base'}{permission} = '0700';
# Create the db/common/base/base.txt file
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base.txt', 'BASE',
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base1.txt', 'BASE',
$bChecksum ? 'a3b357a3e395e43fcfb19bb13f3c1b5179279593' : undef, $lTime);
# Create tablespace path
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base', 'pg_tblspc');
for (my $iTablespaceIdx = 1; $iTablespaceIdx <= $iTablespaceTotal; $iTablespaceIdx++)
{
BackRestTestBackup_ManifestTablespaceCreate(\%oManifest, $iTablespaceIdx);
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace:${iTablespaceIdx}", 'tablespace.txt', 'TBLSPC',
$bChecksum ? '44ad0bf042936c576c75891d0e5ded8e2b60fb54' : undef, $lTime);
}
# Create db config
BackRestTestCommon_ConfigCreate('db', # local
$bRemote ? REMOTE_BACKUP : undef, # remote
@@ -787,6 +878,7 @@ sub BackRestTestBackup_Test
# Perform first incr backup
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
$oManifest{'backup:option'}{hardlink} = $bHardlink ? 'y' : 'n';
$strType = 'incr';
&log(INFO, " ${strType} backup (no file changes, only references)");

View File

@@ -372,12 +372,13 @@ sub BackRestTestCommon_ConfigCreate
$oParamHash{'global:log'}{'level-console'} = 'error';
$oParamHash{'global:log'}{'level-file'} = 'trace';
if (defined($bHardlink) && !$bHardlink)
{
$oParamHash{'global:backup'}{'hardlink'} = 'n';
}
if ($strLocal eq REMOTE_BACKUP)
{
if (defined($bHardlink) && $bHardlink)
{
$oParamHash{'global:backup'}{'hardlink'} = 'y';
}
}
elsif ($strLocal eq REMOTE_DB)
{