diff --git a/bin/pg_backrest_remote.pl b/bin/pg_backrest_remote.pl index bc1b1ad22..94d1ccced 100755 --- a/bin/pg_backrest_remote.pl +++ b/bin/pg_backrest_remote.pl @@ -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) diff --git a/lib/BackRest/Backup.pm b/lib/BackRest/Backup.pm index d9fd5cd74..6c17ef07c 100644 --- a/lib/BackRest/Backup.pm +++ b/lib/BackRest/Backup.pm @@ -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 { @@ -1205,9 +1205,11 @@ sub backup_file_thread # Copy the file from the database to the backup (will return false if the source file is missing) unless($oFileThread->copy(PATH_DB_ABSOLUTE, $oFileCopyMap{$strFile}{db_file}, 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 + false, # Source is not compressed since it is the db directory + $bCompress, # Destination should be compressed based on backup settings + 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}); diff --git a/lib/BackRest/File.pm b/lib/BackRest/File.pm index f9caddff8..00562af1c 100644 --- a/lib/BackRest/File.pm +++ b/lib/BackRest/File.pm @@ -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; diff --git a/lib/BackRest/Remote.pm b/lib/BackRest/Remote.pm index d312d5c1e..7fcd8d84a 100644 --- a/lib/BackRest/Remote.pm +++ b/lib/BackRest/Remote.pm @@ -420,7 +420,7 @@ sub binary_xfer $self->wait_pid(); confess "unable to read block header ${strBlockHeader}"; } - + $iBlockInTotal = 0; $iBlockTotal += 1; } @@ -432,7 +432,7 @@ sub binary_xfer # print "looking for a block of size" $iBlockIn = sysread($hIn, $strBlock, $iBlockSize - $iBlockInTotal); - + # while (defined($iBlockIn) && $iBlockIn != $iBlockSize) # { # $iBlockInMore = sysread($hIn, $strBlockMore, $iBlockSize - $iBlockIn); diff --git a/test/lib/BackRestTest/BackupTest.pm b/test/lib/BackRestTest/BackupTest.pm index 6bfe675fd..570c99ab9 100755 --- a/test/lib/BackRestTest/BackupTest.pm +++ b/test/lib/BackRestTest/BackupTest.pm @@ -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 ******************************************************************"); - BackRestTestBackup_Setup(); + if ($strTest eq 'all' || $strTest eq 'full') + { + $iRun = 0; - BackRestTestCommon_ConfigCreate(BackRestTestCommon_DbPathGet() . '/pg_backrest.conf', REMOTE_DB, REMOTE_BACKUP); - BackRestTestCommon_ConfigCreate(BackRestTestCommon_BackupPathGet() . '/pg_backrest.conf', REMOTE_BACKUP, REMOTE_DB); + &log(INFO, "Test Full Backup\n"); - BackRestTestCommon_Execute(BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_BackupPathGet() . - "/pg_backrest.conf --type=incr --stanza=${strStanza} backup"); + for (my $bRemote = 0; $bRemote <= 1; $bRemote++) + { + BackRestTestBackup_Setup(); + + 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() diff --git a/test/lib/BackRestTest/CommonTest.pm b/test/lib/BackRestTest/CommonTest.pm index ff3bb577e..048851644 100755 --- a/test/lib/BackRestTest/CommonTest.pm +++ b/test/lib/BackRestTest/CommonTest.pm @@ -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}"; diff --git a/test/lib/BackRestTest/FileTest.pm b/test/lib/BackRestTest/FileTest.pm index d52a892c3..c7e762193 100755 --- a/test/lib/BackRestTest/FileTest.pm +++ b/test/lib/BackRestTest/FileTest.pm @@ -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,10 +1129,8 @@ sub BackRestTestFile_Test confess 'unknown error object: ' . $oMessage; } } - else - { - confess $oMessage; - } + + confess $oMessage; } if ($bSourceMissing)