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

Working on unit tests.

This commit is contained in:
David Steele
2014-06-28 14:32:34 -04:00
parent 97b9560e5c
commit f9ec149ffe
7 changed files with 154 additions and 34 deletions

View File

@@ -114,7 +114,8 @@ while ($strCommand ne OP_EXIT)
$oFile->copy(PIPE_STDIN, undef,
PATH_ABSOLUTE, param_get(\%oParamHash, 'destination_file'),
undef, param_get(\%oParamHash, 'destination_compress'),
undef, undef, undef,
undef, undef,
param_get(\%oParamHash, 'permission', false),
param_get(\%oParamHash, 'destination_path_create'));
$oRemote->output_write();
@@ -154,7 +155,8 @@ while ($strCommand ne OP_EXIT)
param_get(\%oParamHash, 'source_compressed'),
param_get(\%oParamHash, 'destination_compress'),
param_get(\%oParamHash, 'ignore_missing_source', false).
undef, undef,
undef,
param_get(\%oParamHash, 'permission', false),
param_get(\%oParamHash, 'destination_path_create')) ? 'Y' : 'N');
}
elsif ($strCommand eq OP_FILE_MANIFEST)

View File

@@ -190,7 +190,7 @@ sub backup_thread_complete
if ($bConfessOnError)
{
confess &log(ERROR, "error in thread ${iThreadIdx}: check log for details");
confess &log(ERROR, 'error in thread ' . (${iThreadIdx} + 1) . ': check log for details');
}
else
{
@@ -1207,7 +1207,9 @@ sub backup_file_thread
PATH_BACKUP_TMP, $oFileCopyMap{$strFile}{backup_file},
false, # Source is not compressed since it is the db directory
$bCompress, # Destination should be compressed based on backup settings
true)) # Ignore missing files
true, # Ignore missing files
undef, undef, # Do not set permissions or modification time
true)) # Create the destiation directory if it does not exist
{
# If file is missing assume the database removed it (else corruption and nothing we can do!)
&log(INFO, "thread ${iThreadIdx} skipped file removed by database: " . $oFileCopyMap{$strFile}{db_file});

View File

@@ -750,7 +750,7 @@ sub hash
if (!open($hFile, "<", $strFileOp))
{
my $strError = "${strFileOp} could not be read" . $!;
my $strError = "${strFileOp} could not be read: " . $!;
my $iErrorCode = 2;
if (!$self->exists($strPathType, $strFile))
@@ -1174,9 +1174,9 @@ sub copy
my $strError = "${strDestinationTmpOp} could not be opened: " . $!;
my $iErrorCode = COMMAND_ERR_FILE_READ;
if (!$self->exists(PATH_ABSOLUTE, dirname($strDestinationOp)))
if (!$self->exists(PATH_ABSOLUTE, dirname($strDestinationTmpOp)))
{
$strError = "${strDestinationOp} does not exist";
$strError = dirname($strDestinationTmpOp) . " does not exist";
$iErrorCode = COMMAND_ERR_FILE_MISSING;
}
@@ -1190,7 +1190,7 @@ sub copy
confess &log(ERROR, "${strDebug}: " . $strError);
}
$self->path_create(PATH_ABSOLUTE, dirname($strDestinationOp));
$self->path_create(PATH_ABSOLUTE, dirname($strDestinationTmpOp));
if (!open($hDestinationFile, ">", $strDestinationTmpOp))
{
@@ -1246,6 +1246,11 @@ sub copy
$oParamHash{destination_compress} = $bDestinationCompress;
$oParamHash{destination_path_create} = $bDestinationPathCreate;
if (defined($strPermission))
{
$oParamHash{permission} = $strPermission;
}
$hOut = $self->{oRemote}->{hIn};
}
}
@@ -1260,6 +1265,11 @@ sub copy
$oParamHash{destination_compress} = $bDestinationCompress;
$oParamHash{destination_path_create} = $bDestinationPathCreate;
if (defined($strPermission))
{
$oParamHash{permission} = $strPermission;
}
if ($bIgnoreMissingSource)
{
$oParamHash{ignore_missing_source} = $bIgnoreMissingSource;
@@ -1363,21 +1373,21 @@ sub copy
if (!$bDestinationRemote)
{
# Set the file permission if required
if (defined($strPermission))
{
system("chmod ${strPermission} ${strDestinationTmpOp}") == 0
or confess &log(ERROR, "unable to set permissions for local ${strDestinationTmpOp}");
}
# if (defined($strPermission))
# {
# system("chmod ${strPermission} ${strDestinationTmpOp}") == 0
# or confess &log(ERROR, "unable to set permissions for local ${strDestinationTmpOp}");
# }
# Set the file modification time if required
if (defined($lModificationTime))
{
utime($lModificationTime, $lModificationTime, $strDestinationTmpOp)
or confess &log(ERROR, "unable to set time for local ${strDestinationTmpOp}");
}
# if (defined($lModificationTime))
# {
# utime($lModificationTime, $lModificationTime, $strDestinationTmpOp)
# or confess &log(ERROR, "unable to set time for local ${strDestinationTmpOp}");
# }
# Move the file from tmp to final destination
$self->move(PATH_ABSOLUTE, $strDestinationTmpOp, PATH_ABSOLUTE, $strDestinationOp, false);
$self->move(PATH_ABSOLUTE, $strDestinationTmpOp, PATH_ABSOLUTE, $strDestinationOp, true);
}
return true;

View File

@@ -46,6 +46,20 @@ sub BackRestTestBackup_ClusterDrop
}
}
####################################################################################################################################
# BackRestTestBackup_ClusterRestart
####################################################################################################################################
sub BackRestTestBackup_ClusterRestart
{
my $strPath = BackRestTestCommon_DbCommonPathGet();
# If the db directory already exists, stop the cluster and remove the directory
if (-e $strPath . "/postmaster.pid")
{
BackRestTestCommon_Execute("pg_ctl restart -D $strPath -w -s");
}
}
####################################################################################################################################
# BackRestTestBackup_ClusterCreate
####################################################################################################################################
@@ -127,13 +141,58 @@ sub BackRestTestBackup_Test
# Print test banner
&log(INFO, "BACKUP MODULE ******************************************************************");
if ($strTest eq 'all' || $strTest eq 'full')
{
$iRun = 0;
&log(INFO, "Test Full Backup\n");
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
{
BackRestTestBackup_Setup();
BackRestTestCommon_ConfigCreate(BackRestTestCommon_DbPathGet() . '/pg_backrest.conf', REMOTE_DB, REMOTE_BACKUP);
BackRestTestCommon_ConfigCreate(BackRestTestCommon_BackupPathGet() . '/pg_backrest.conf', REMOTE_BACKUP, REMOTE_DB);
for (my $bHardlink = 0; $bHardlink <= 1; $bHardlink++)
{
# BackRestTestBackup_ClusterRestart();
my %oDbConfigHash;
my %oBackupConfigHash;
# Confgure hard-linking
if ($bHardlink)
{
$oBackupConfigHash{'global:backup'}{hardlink} = 'y';
}
BackRestTestCommon_ConfigCreate(BackRestTestCommon_DbPathGet() . '/pg_backrest.conf', 'db',
($bRemote ? REMOTE_BACKUP : undef), \%oDbConfigHash);
BackRestTestCommon_ConfigCreate(BackRestTestCommon_BackupPathGet() . '/pg_backrest.conf', 'backup',
($bRemote ? REMOTE_DB : undef), \%oBackupConfigHash);
for (my $iFull = 1; $iFull <= 1; $iFull++)
{
$iRun++;
&log(INFO, "run ${iRun} - " .
"remote ${bRemote}, full ${iFull}");
BackRestTestCommon_Execute(BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_BackupPathGet() .
"/pg_backrest.conf --type=full --stanza=${strStanza} backup");
for (my $iIncr = 1; $iIncr <= 1; $iIncr++)
{
$iRun++;
&log(INFO, "run ${iRun} - " .
"remote ${bRemote}, full ${iFull}, hardlink ${bHardlink}, incr ${iIncr}");
BackRestTestCommon_Execute(BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_BackupPathGet() .
"/pg_backrest.conf --type=incr --stanza=${strStanza} backup");
}
}
}
}
}
#-------------------------------------------------------------------------------------------------------------------------------
# Test path_create()

View File

@@ -135,9 +135,17 @@ sub BackRestTestCommon_ConfigCreate
$oParamHash{'global:backup'}{'path'} = $strCommonBackupPath;
$oParamHash{'global:backup'}{'thread-max'} = '8';
$oParamHash{'global:log'}{'level-console'} = 'debug';
$oParamHash{'global:log'}{'level-console'} = 'error';
$oParamHash{'global:log'}{'level-file'} = 'trace';
foreach my $strSection (keys $oParamHashRef)
{
foreach my $strKey (keys ${$oParamHashRef}{$strSection})
{
$oParamHash{$strSection}{$strKey} = ${$oParamHashRef}{$strSection}{$strKey};
}
}
tied(%oParamHash)->WriteConfig($strFile) or die "could not write config file ${strFile}";
chmod(0770, $strFile) or die "unable to set permissions for ${strFile}";

View File

@@ -250,6 +250,11 @@ sub BackRestTestFile_Test
{
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"remote $bRemote" .
", src_exists $bSourceExists, src_error $bSourceError" .
@@ -340,6 +345,11 @@ sub BackRestTestFile_Test
{
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"remote $bRemote, exists $bExists, error $bError");
@@ -444,6 +454,11 @@ sub BackRestTestFile_Test
{
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"remote $bRemote, error $bError, exists $bExists");
@@ -612,6 +627,11 @@ sub BackRestTestFile_Test
{
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"remote $bRemote, error $bError, exists $bExists, " .
"expression " . (defined($strExpression) ? $strExpression : "[undef]") . ", " .
@@ -722,6 +742,11 @@ sub BackRestTestFile_Test
{
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"remote ${bRemote}, error = $bError, exists ${bExists}, temp ${bTemp} " .
", ignore missing ${bIgnoreMissing}");
@@ -821,6 +846,11 @@ sub BackRestTestFile_Test
{
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"remote $bRemote, error $bError, exists $bExists");
@@ -903,6 +933,11 @@ sub BackRestTestFile_Test
{
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"remote $bRemote, exists $bExists, error ${bError}");
@@ -1021,6 +1056,11 @@ sub BackRestTestFile_Test
$iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " .
"srcpth " . (defined($strRemote) && $strRemote eq $strSourcePath ? "remote" : "local") .
":${strSourcePath}, srccmp $bSourceCompressed, srcmiss ${bSourceMissing}, " .
@@ -1064,7 +1104,8 @@ sub BackRestTestFile_Test
$bReturn = $oFile->copy($strSourcePathType, $strSourceFile,
$strDestinationPathType, $strDestinationFile,
$bSourceCompressed, $bDestinationCompress,
$bSourceIgnoreMissing);
$bSourceIgnoreMissing, undef,
'0700');
};
# Check for errors after copy
@@ -1088,11 +1129,9 @@ sub BackRestTestFile_Test
confess 'unknown error object: ' . $oMessage;
}
}
else
{
confess $oMessage;
}
}
if ($bSourceMissing)
{