2014-10-06 02:49:30 +03:00
|
|
|
#!/usr/bin/perl
|
|
|
|
####################################################################################################################################
|
|
|
|
# FileTest.pl - Unit Tests for BackRest::File
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRestTest::FileTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
2015-03-25 21:15:55 +02:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
2014-10-06 02:49:30 +03:00
|
|
|
|
2015-06-21 18:06:13 +02:00
|
|
|
use Cwd qw(abs_path);
|
2015-06-14 00:25:49 +02:00
|
|
|
use Exporter qw(import);
|
2015-06-21 18:06:13 +02:00
|
|
|
use Fcntl qw(:mode);
|
2015-06-14 00:25:49 +02:00
|
|
|
use File::Basename;
|
|
|
|
use File::stat;
|
|
|
|
use POSIX qw(ceil);
|
2015-06-21 18:06:13 +02:00
|
|
|
use Scalar::Util qw(blessed);
|
2015-03-25 21:15:55 +02:00
|
|
|
use Time::HiRes qw(gettimeofday usleep);
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
use lib dirname($0) . '/../lib';
|
2015-03-25 21:15:55 +02:00
|
|
|
use BackRest::Config;
|
2014-10-06 02:49:30 +03:00
|
|
|
use BackRest::File;
|
2015-08-05 14:43:41 +02:00
|
|
|
use BackRest::Protocol::Common;
|
|
|
|
use BackRest::Protocol::RemoteMaster;
|
2015-06-14 00:25:49 +02:00
|
|
|
use BackRest::Utility;
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
use BackRestTest::CommonTest;
|
|
|
|
|
|
|
|
my $strTestPath;
|
|
|
|
my $strHost;
|
|
|
|
my $strUserBackRest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestFile_Setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestFile_Setup
|
|
|
|
{
|
|
|
|
my $bPrivate = shift;
|
|
|
|
my $bDropOnly = shift;
|
|
|
|
|
|
|
|
# Remove the backrest private directory
|
|
|
|
if (-e "${strTestPath}/private")
|
|
|
|
{
|
|
|
|
system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/private'");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remove the test directory
|
|
|
|
system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path';
|
|
|
|
|
|
|
|
if (!defined($bDropOnly) || !$bDropOnly)
|
|
|
|
{
|
|
|
|
# Create the test directory
|
|
|
|
mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory';
|
|
|
|
|
|
|
|
# Create the backrest private directory
|
|
|
|
if (defined($bPrivate) && $bPrivate)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
system("ssh backrest\@${strHost} 'mkdir -m 700 ${strTestPath}/backrest_private'") == 0
|
|
|
|
or die "unable to create ${strTestPath}/backrest_private path";
|
|
|
|
|
|
|
|
system("mkdir -m 700 ${strTestPath}/user_private") == 0
|
|
|
|
or die "unable to create ${strTestPath}/user_private path";
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestFile_Test
|
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
our @EXPORT = qw(BackRestTestFile_Test);
|
|
|
|
|
2014-10-06 02:49:30 +03:00
|
|
|
sub BackRestTestFile_Test
|
|
|
|
{
|
|
|
|
my $strTest = shift;
|
|
|
|
|
|
|
|
# If no test was specified, then run them all
|
|
|
|
if (!defined($strTest))
|
|
|
|
{
|
|
|
|
$strTest = 'all';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Setup test variables
|
|
|
|
my $iRun;
|
|
|
|
$strTestPath = BackRestTestCommon_TestPathGet();
|
|
|
|
my $strStanza = BackRestTestCommon_StanzaGet();
|
|
|
|
my $strUser = BackRestTestCommon_UserGet();
|
|
|
|
my $strGroup = BackRestTestCommon_GroupGet();
|
|
|
|
$strHost = BackRestTestCommon_HostGet();
|
|
|
|
$strUserBackRest = BackRestTestCommon_UserBackRestGet();
|
|
|
|
|
|
|
|
# Print test banner
|
|
|
|
&log(INFO, 'FILE MODULE ********************************************************************');
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-03-25 21:15:55 +02:00
|
|
|
# Create remotes
|
2014-10-06 02:49:30 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-08-05 14:43:41 +02:00
|
|
|
my $oRemote = new BackRest::Protocol::RemoteMaster
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-06-18 21:39:30 +02:00
|
|
|
BackRestTestCommon_CommandRemoteFullGet(), # Command
|
|
|
|
OPTION_DEFAULT_BUFFER_SIZE, # Buffer size
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL, # Compress level
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK, # Compress network level
|
2015-08-05 14:43:41 +02:00
|
|
|
$strHost, # Host
|
|
|
|
$strUserBackRest # User
|
2015-03-25 21:15:55 +02:00
|
|
|
);
|
|
|
|
|
2015-08-05 14:43:41 +02:00
|
|
|
my $oLocal = new BackRest::Protocol::Common
|
2015-03-25 21:15:55 +02:00
|
|
|
(
|
|
|
|
OPTION_DEFAULT_BUFFER_SIZE, # Buffer size
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL, # Compress level
|
2015-08-05 14:43:41 +02:00
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK # Compress network level
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test path_create()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'path_create')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, "Test File->path_create()\n");
|
|
|
|
|
|
|
|
# Loop through local/remote
|
|
|
|
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
|
|
|
{
|
|
|
|
# Create the file object
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
|
|
|
);
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
# Loop through error
|
|
|
|
for (my $bError = 0; $bError <= 1; $bError++)
|
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
# Loop through mode (mode will be set on true)
|
|
|
|
for (my $bMode = 0; $bMode <= 1; $bMode++)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
|
|
|
my $strPathType = PATH_BACKUP_CLUSTER;
|
|
|
|
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-03-25 21:15:55 +02:00
|
|
|
"rmt ${bRemote}, err ${bError}, mode ${bMode}")) {next}
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bError);
|
|
|
|
|
|
|
|
mkdir("${strTestPath}/backup") or confess 'Unable to create test/backup directory';
|
|
|
|
mkdir("${strTestPath}/backup/db") or confess 'Unable to create test/backup/db directory';
|
|
|
|
|
|
|
|
my $strPath = 'path';
|
2015-03-25 21:15:55 +02:00
|
|
|
my $strMode;
|
2014-10-06 02:49:30 +03:00
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
# If mode then set one (other than the default)
|
|
|
|
if ($bMode)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
$strMode = '0700';
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# If not exists then set the path to something bogus
|
|
|
|
if ($bError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strPath = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . "_private/path";
|
|
|
|
|
2014-10-06 02:49:30 +03:00
|
|
|
$strPathType = PATH_BACKUP_ABSOLUTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute in eval to catch errors
|
|
|
|
my $bErrorExpected = $bError;
|
|
|
|
|
|
|
|
eval
|
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
$oFile->path_create($strPathType, $strPath, $strMode);
|
2014-10-06 02:49:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
# Check for errors
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
# Ignore errors if the path did not exist
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess "error raised: " . $@ . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
confess 'error was expected';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure the path was actually created
|
|
|
|
my $strPathCheck = $oFile->path_get($strPathType, $strPath);
|
|
|
|
|
|
|
|
unless (-e $strPathCheck)
|
|
|
|
{
|
|
|
|
confess 'path was not created';
|
|
|
|
}
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
# Check that the mode was set correctly
|
2014-10-06 02:49:30 +03:00
|
|
|
my $oStat = lstat($strPathCheck);
|
|
|
|
|
|
|
|
if (!defined($oStat))
|
|
|
|
{
|
|
|
|
confess "unable to stat ${strPathCheck}";
|
|
|
|
}
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
if ($bMode)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
if ($strMode ne sprintf('%04o', S_IMODE($oStat->mode)))
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
confess "mode were not set to {$strMode}";
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test move()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'move')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "Test File->move()\n");
|
|
|
|
|
|
|
|
for (my $bRemote = 0; $bRemote <= 0; $bRemote++)
|
|
|
|
{
|
|
|
|
# Create the file object
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = (new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
|
|
|
))->clone(1);
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
# Loop through source exists
|
|
|
|
for (my $bSourceExists = 0; $bSourceExists <= 1; $bSourceExists++)
|
|
|
|
{
|
|
|
|
# Loop through source errors
|
|
|
|
for (my $bSourceError = 0; $bSourceError <= 1; $bSourceError++)
|
|
|
|
{
|
|
|
|
# Loop through destination exists
|
|
|
|
for (my $bDestinationExists = 0; $bDestinationExists <= 1; $bDestinationExists++)
|
|
|
|
{
|
|
|
|
# Loop through source errors
|
|
|
|
for (my $bDestinationError = 0; $bDestinationError <= 1; $bDestinationError++)
|
|
|
|
{
|
|
|
|
# Loop through create
|
|
|
|
for (my $bCreate = 0; $bCreate <= $bDestinationExists; $bCreate++)
|
|
|
|
{
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"src_exists ${bSourceExists}, src_error ${bSourceError}, " .
|
|
|
|
", dst_exists ${bDestinationExists}, dst_error ${bDestinationError}, " .
|
|
|
|
"dst_create ${bCreate}")) {next}
|
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bSourceError || $bDestinationError);
|
|
|
|
|
|
|
|
my $strSourceFile = "${strTestPath}/test.txt";
|
|
|
|
my $strDestinationFile = "${strTestPath}/test-dest.txt";
|
|
|
|
|
|
|
|
if ($bSourceError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strSourceFile = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . "_private/test.txt";
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
elsif ($bSourceExists)
|
|
|
|
{
|
|
|
|
system("echo 'TESTDATA' > ${strSourceFile}");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bDestinationError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strDestinationFile = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . "_private/test.txt";
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
elsif (!$bDestinationExists)
|
|
|
|
{
|
|
|
|
$strDestinationFile = "${strTestPath}/sub/test-dest.txt";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute in eval in case of error
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
$oFile->move(PATH_BACKUP_ABSOLUTE, $strSourceFile, PATH_BACKUP_ABSOLUTE, $strDestinationFile, $bCreate);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
if (!$bSourceExists || (!$bDestinationExists && !$bCreate) || $bSourceError || $bDestinationError)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'error raised: ' . $@ . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$bSourceExists || (!$bDestinationExists && !$bCreate) || $bSourceError || $bDestinationError)
|
|
|
|
{
|
|
|
|
confess 'error should have been raised';
|
|
|
|
}
|
|
|
|
|
|
|
|
unless (-e $strDestinationFile)
|
|
|
|
{
|
|
|
|
confess 'file was not moved';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test compress()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'compress')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "Test File->compress()\n");
|
|
|
|
|
|
|
|
for (my $bRemote = 0; $bRemote <= 0; $bRemote++)
|
|
|
|
{
|
|
|
|
# Create the file object
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
# Loop through exists
|
|
|
|
for (my $bExists = 0; $bExists <= 1; $bExists++)
|
|
|
|
{
|
|
|
|
for (my $bError = 0; $bError <= 1; $bError++)
|
|
|
|
{
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rmt ${bRemote}, exists ${bExists}, err ${bError}")) {next}
|
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bError);
|
|
|
|
|
|
|
|
my $strFile = "${strTestPath}/test.txt";
|
|
|
|
my $strSourceHash;
|
2015-03-25 21:15:55 +02:00
|
|
|
my $iSourceSize;
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
if ($bError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strFile = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . "_private/test.txt";
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
elsif ($bExists)
|
|
|
|
{
|
|
|
|
system("echo 'TESTDATA' > ${strFile}");
|
2015-03-25 21:15:55 +02:00
|
|
|
($strSourceHash, $iSourceSize) = $oFile->hash_size(PATH_BACKUP_ABSOLUTE, $strFile);
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Execute in eval in case of error
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
$oFile->compress(PATH_BACKUP_ABSOLUTE, $strFile);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
if (!$bExists || $bError)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'error raised: ' . $@ . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$bExists || $bError)
|
|
|
|
{
|
|
|
|
confess 'expected error';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strDestinationFile = $strFile . '.gz';
|
|
|
|
|
|
|
|
if (-e $strFile)
|
|
|
|
{
|
|
|
|
confess 'source file still exists';
|
|
|
|
}
|
|
|
|
|
|
|
|
unless (-e $strDestinationFile)
|
|
|
|
{
|
|
|
|
confess 'file was not compressed';
|
|
|
|
}
|
|
|
|
|
|
|
|
system("gzip -d ${strDestinationFile}") == 0 or die "could not decompress ${strDestinationFile}";
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
my ($strDestinationHash, $iDestinationSize) = $oFile->hash_size(PATH_BACKUP_ABSOLUTE, $strFile);
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
if ($strSourceHash ne $strDestinationHash)
|
|
|
|
{
|
|
|
|
confess "source ${strSourceHash} and destination ${strDestinationHash} file hashes do not match";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test wait()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'wait')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "Test File->wait()\n");
|
|
|
|
|
|
|
|
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
|
|
|
{
|
|
|
|
# Create the file object
|
|
|
|
my $oFile = new BackRest::File
|
|
|
|
(
|
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'db' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
|
|
|
);
|
|
|
|
|
|
|
|
my $lTimeBegin = gettimeofday();
|
|
|
|
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rmt ${bRemote}, begin ${lTimeBegin}")) {next}
|
|
|
|
|
|
|
|
# If there is not enough time to complete the test then sleep
|
|
|
|
if (ceil($lTimeBegin) - $lTimeBegin < .250)
|
|
|
|
{
|
|
|
|
my $lSleepMs = ceil(((int($lTimeBegin) + 1) - $lTimeBegin) * 1000);
|
|
|
|
|
|
|
|
usleep($lSleepMs * 1000);
|
|
|
|
|
|
|
|
&log(DEBUG, "slept ${lSleepMs}ms: begin ${lTimeBegin}, end " . gettimeofday());
|
|
|
|
|
|
|
|
$lTimeBegin = gettimeofday();
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run the test
|
|
|
|
my $lTimeBeginCheck = $oFile->wait(PATH_DB_ABSOLUTE);
|
|
|
|
|
|
|
|
&log(DEBUG, "begin ${lTimeBegin}, check ${lTimeBeginCheck}, end " . time());
|
|
|
|
|
|
|
|
# Current time should have advanced by 1 second
|
2015-04-19 23:53:29 +02:00
|
|
|
if (int(time()) == int($lTimeBegin))
|
2015-03-25 21:15:55 +02:00
|
|
|
{
|
|
|
|
confess "time was not advanced by 1 second";
|
|
|
|
}
|
|
|
|
|
|
|
|
# lTimeBegin and lTimeBeginCheck should be equal
|
|
|
|
if (int($lTimeBegin) != $lTimeBeginCheck)
|
|
|
|
{
|
|
|
|
confess 'time begin ' || int($lTimeBegin) || "and check ${lTimeBeginCheck} should be equal";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 02:49:30 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test manifest()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'manifest')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "Test File->manifest()\n");
|
|
|
|
|
|
|
|
my $strManifestCompare =
|
|
|
|
".,d,${strUser},${strGroup},0770,,,,\n" .
|
|
|
|
"sub1,d,${strUser},${strGroup},0750,,,,\n" .
|
|
|
|
"sub1/sub2,d,${strUser},${strGroup},0750,,,,\n" .
|
|
|
|
"sub1/sub2/test,l,${strUser},${strGroup},,,,,../..\n" .
|
|
|
|
"sub1/sub2/test-hardlink.txt,f,${strUser},${strGroup},1640,1111111111,0,9,\n" .
|
|
|
|
"sub1/sub2/test-sub2.txt,f,${strUser},${strGroup},0666,1111111113,0,11,\n" .
|
|
|
|
"sub1/test,l,${strUser},${strGroup},,,,,..\n" .
|
|
|
|
"sub1/test-hardlink.txt,f,${strUser},${strGroup},1640,1111111111,0,9,\n" .
|
|
|
|
"sub1/test-sub1.txt,f,${strUser},${strGroup},0646,1111111112,0,10,\n" .
|
|
|
|
"test.txt,f,${strUser},${strGroup},1640,1111111111,0,9,";
|
|
|
|
|
|
|
|
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
|
|
|
{
|
|
|
|
# Create the file object
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
for (my $bError = 0; $bError <= 1; $bError++)
|
|
|
|
{
|
|
|
|
for (my $bExists = 0; $bExists <= 1; $bExists++)
|
|
|
|
{
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rmt ${bRemote}, exists ${bExists}, err ${bError}")) {next}
|
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bError);
|
|
|
|
|
|
|
|
# Setup test data
|
|
|
|
system("mkdir -m 750 ${strTestPath}/sub1") == 0 or confess 'Unable to create test directory';
|
|
|
|
system("mkdir -m 750 ${strTestPath}/sub1/sub2") == 0 or confess 'Unable to create test directory';
|
|
|
|
|
|
|
|
system("echo 'TESTDATA' > ${strTestPath}/test.txt");
|
|
|
|
utime(1111111111, 1111111111, "${strTestPath}/test.txt");
|
|
|
|
system("chmod 1640 ${strTestPath}/test.txt");
|
|
|
|
|
|
|
|
system("echo 'TESTDATA_' > ${strTestPath}/sub1/test-sub1.txt");
|
|
|
|
utime(1111111112, 1111111112, "${strTestPath}/sub1/test-sub1.txt");
|
|
|
|
system("chmod 0640 ${strTestPath}/sub1/test-sub1.txt");
|
|
|
|
|
|
|
|
system("echo 'TESTDATA__' > ${strTestPath}/sub1/sub2/test-sub2.txt");
|
|
|
|
utime(1111111113, 1111111113, "${strTestPath}/sub1/sub2/test-sub2.txt");
|
|
|
|
system("chmod 0646 ${strTestPath}/sub1/test-sub1.txt");
|
|
|
|
|
|
|
|
system("ln ${strTestPath}/test.txt ${strTestPath}/sub1/test-hardlink.txt");
|
|
|
|
system("ln ${strTestPath}/test.txt ${strTestPath}/sub1/sub2/test-hardlink.txt");
|
|
|
|
|
|
|
|
system("ln -s .. ${strTestPath}/sub1/test");
|
|
|
|
system("chmod 0700 ${strTestPath}/sub1/test");
|
|
|
|
system("ln -s ../.. ${strTestPath}/sub1/sub2/test");
|
|
|
|
system("chmod 0750 ${strTestPath}/sub1/sub2/test");
|
|
|
|
|
|
|
|
system("chmod 0770 ${strTestPath}");
|
|
|
|
|
|
|
|
# Create path
|
|
|
|
my $strPath = $strTestPath;
|
|
|
|
|
|
|
|
if ($bError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strPath = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . '_private';
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
elsif (!$bExists)
|
|
|
|
{
|
|
|
|
$strPath = $strTestPath . '/error';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute in eval in case of error
|
|
|
|
my %oManifestHash;
|
|
|
|
my $bErrorExpected = !$bExists || $bError;
|
|
|
|
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
$oFile->manifest(PATH_BACKUP_ABSOLUTE, $strPath, \%oManifestHash);
|
|
|
|
};
|
|
|
|
|
|
|
|
# Check for an error
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'error raised: ' . $@ . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check for an expected error
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
confess 'error was expected';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strManifest;
|
|
|
|
|
|
|
|
# Validate the manifest
|
2015-06-21 18:06:13 +02:00
|
|
|
foreach my $strName (sort(keys(%{$oManifestHash{name}})))
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
|
|
|
if (!defined($strManifest))
|
|
|
|
{
|
|
|
|
$strManifest = '';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strManifest .= "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($oManifestHash{name}{"${strName}"}{inode}))
|
|
|
|
{
|
|
|
|
$oManifestHash{name}{"${strName}"}{inode} = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$strManifest .=
|
|
|
|
"${strName}," .
|
|
|
|
$oManifestHash{name}{"${strName}"}{type} . ',' .
|
|
|
|
(defined($oManifestHash{name}{"${strName}"}{user}) ?
|
|
|
|
$oManifestHash{name}{"${strName}"}{user} : '') . ',' .
|
|
|
|
(defined($oManifestHash{name}{"${strName}"}{group}) ?
|
|
|
|
$oManifestHash{name}{"${strName}"}{group} : '') . ',' .
|
2015-03-25 21:15:55 +02:00
|
|
|
(defined($oManifestHash{name}{"${strName}"}{mode}) ?
|
|
|
|
$oManifestHash{name}{"${strName}"}{mode} : '') . ',' .
|
2014-10-06 02:49:30 +03:00
|
|
|
(defined($oManifestHash{name}{"${strName}"}{modification_time}) ?
|
|
|
|
$oManifestHash{name}{"${strName}"}{modification_time} : '') . ',' .
|
|
|
|
(defined($oManifestHash{name}{"${strName}"}{inode}) ?
|
|
|
|
$oManifestHash{name}{"${strName}"}{inode} : '') . ',' .
|
|
|
|
(defined($oManifestHash{name}{"${strName}"}{size}) ?
|
|
|
|
$oManifestHash{name}{"${strName}"}{size} : '') . ',' .
|
|
|
|
(defined($oManifestHash{name}{"${strName}"}{link_destination}) ?
|
|
|
|
$oManifestHash{name}{"${strName}"}{link_destination} : '');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($strManifest ne $strManifestCompare)
|
|
|
|
{
|
|
|
|
confess "manifest is not equal:\n\n${strManifest}\n\ncompare:\n\n${strManifestCompare}\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test list()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'list')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "Test File->list()\n");
|
|
|
|
|
|
|
|
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
|
|
|
{
|
|
|
|
# Create the file object
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
for (my $bSort = false; $bSort <= true; $bSort++)
|
|
|
|
{
|
|
|
|
my $strSort = $bSort ? undef : 'reverse';
|
|
|
|
|
|
|
|
# Loop through expression
|
|
|
|
for (my $iExpression = 0; $iExpression <= 2; $iExpression++)
|
|
|
|
{
|
|
|
|
my $strExpression;
|
|
|
|
|
|
|
|
# Expression tha returns results
|
|
|
|
if ($iExpression == 1)
|
|
|
|
{
|
|
|
|
$strExpression = "^test2\\..*\$";
|
|
|
|
}
|
|
|
|
# Expression that does not return results
|
|
|
|
elsif ($iExpression == 2)
|
|
|
|
{
|
|
|
|
$strExpression = "^du\$";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Loop through exists
|
|
|
|
for (my $bExists = false; $bExists <= true; $bExists++)
|
|
|
|
{
|
|
|
|
# Loop through ignore missing
|
|
|
|
for (my $bIgnoreMissing = false; $bIgnoreMissing <= $bExists; $bIgnoreMissing++)
|
|
|
|
{
|
|
|
|
# Loop through error
|
|
|
|
for (my $bError = false; $bError <= true; $bError++)
|
|
|
|
{
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rmt ${bRemote}, err ${bError}, exists ${bExists}, ignmis ${bIgnoreMissing}, " .
|
|
|
|
'expression ' . (defined($strExpression) ? $strExpression : '[undef]') . ', ' .
|
|
|
|
'sort ' . (defined($strSort) ? $strSort : '[undef]'))) {next}
|
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bError);
|
|
|
|
|
|
|
|
my $strPath = $strTestPath;
|
|
|
|
|
|
|
|
if ($bError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strPath = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . '_private';
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
elsif (!$bExists)
|
|
|
|
{
|
|
|
|
$strPath = "${strTestPath}/error";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
system("echo 'TESTDATA' > ${strPath}/test.txt");
|
|
|
|
system("echo 'TESTDATA2' > ${strPath}/test2.txt");
|
|
|
|
}
|
|
|
|
|
|
|
|
my @stryFileCompare = split(/\n/, "test.txt\ntest2.txt");
|
|
|
|
|
|
|
|
# Execute in eval in case of error
|
|
|
|
my @stryFileList;
|
|
|
|
my $bErrorExpected = (!$bExists && !$bIgnoreMissing) || $bError;
|
|
|
|
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
@stryFileList = $oFile->list(PATH_BACKUP_ABSOLUTE, $strPath, $strExpression, $strSort, $bIgnoreMissing);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'error raised: ' . $@ . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
confess 'error was expected';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Validate the list
|
|
|
|
if (defined($strExpression))
|
|
|
|
{
|
|
|
|
@stryFileCompare = grep(/$strExpression/i, @stryFileCompare);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($strSort))
|
|
|
|
{
|
|
|
|
@stryFileCompare = sort {$b cmp $a} @stryFileCompare;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strFileList = sprintf("@stryFileList");
|
|
|
|
my $strFileCompare = sprintf("@stryFileCompare");
|
|
|
|
|
|
|
|
if ($strFileList ne $strFileCompare)
|
|
|
|
{
|
|
|
|
confess "list (${strFileList})[" . @stryFileList .
|
|
|
|
"] does not match compare (${strFileCompare})[" . @stryFileCompare . ']';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test remove()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'remove')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "Test File->remove()\n");
|
|
|
|
|
|
|
|
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
# Loop through exists
|
|
|
|
for (my $bError = 0; $bError <= 1; $bError++)
|
|
|
|
{
|
|
|
|
# Loop through exists
|
|
|
|
for (my $bExists = 0; $bExists <= 1; $bExists++)
|
|
|
|
{
|
|
|
|
# Loop through temp
|
|
|
|
for (my $bTemp = 0; $bTemp <= 1; $bTemp++)
|
|
|
|
{
|
|
|
|
# Loop through ignore missing
|
|
|
|
for (my $bIgnoreMissing = 0; $bIgnoreMissing <= 1; $bIgnoreMissing++)
|
|
|
|
{
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rmt ${bRemote}, err = ${bError}, exists ${bExists}, tmp ${bTemp}, " .
|
|
|
|
"ignore missing ${bIgnoreMissing}")) {next}
|
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bError);
|
|
|
|
|
|
|
|
my $strFile = "${strTestPath}/test.txt";
|
|
|
|
|
|
|
|
if ($bError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strFile = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . '_private/test.txt';
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
elsif (!$bExists)
|
|
|
|
{
|
|
|
|
$strFile = "${strTestPath}/private/error.txt"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
system("echo 'TESTDATA' > ${strFile}" . ($bTemp ? '.backrest.tmp' : ''));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute in eval in case of error
|
|
|
|
my $bRemoved;
|
|
|
|
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
$bRemoved = $oFile->remove(PATH_BACKUP_ABSOLUTE, $strFile, $bTemp, $bIgnoreMissing);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
if ($bError || $bRemote)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$bExists && !$bIgnoreMissing)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'unexpected error raised: ' . $@;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bError || $bRemote)
|
|
|
|
{
|
|
|
|
confess 'error should have been returned';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$bRemoved)
|
|
|
|
{
|
|
|
|
if (!$bExists && $bIgnoreMissing)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'remove returned false, but something should have been removed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-e ($strFile . ($bTemp ? '.backrest.tmp' : '')))
|
|
|
|
{
|
|
|
|
confess 'file still exists';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test hash()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'hash')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "test File->hash()\n");
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
# Loop through error
|
2015-03-25 21:15:55 +02:00
|
|
|
for (my $bError = false; $bError <= true; $bError++)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
|
|
|
# Loop through exists
|
2015-03-25 21:15:55 +02:00
|
|
|
for (my $bExists = false; $bExists <= true; $bExists++)
|
|
|
|
{
|
|
|
|
# Loop through exists
|
|
|
|
for (my $bCompressed = false; $bCompressed <= true; $bCompressed++)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-03-25 21:15:55 +02:00
|
|
|
"rmt ${bRemote}, err ${bError}, exists ${bExists}, cmp ${bCompressed}")) {next}
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bError);
|
|
|
|
|
|
|
|
my $strFile = "${strTestPath}/test.txt";
|
|
|
|
|
|
|
|
if ($bError)
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
$strFile = "${strTestPath}/" . ($bRemote ? 'user' : 'backrest') . '_private/test.txt';
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
elsif (!$bExists)
|
|
|
|
{
|
|
|
|
$strFile = "${strTestPath}/error.txt";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
system("echo 'TESTDATA' > ${strFile}");
|
2015-03-25 21:15:55 +02:00
|
|
|
|
|
|
|
if ($bCompressed && !$bRemote)
|
|
|
|
{
|
|
|
|
$oFile->compress(PATH_BACKUP_ABSOLUTE, $strFile);
|
|
|
|
$strFile = $strFile . '.gz';
|
|
|
|
}
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Execute in eval in case of error
|
|
|
|
my $strHash;
|
2015-03-25 21:15:55 +02:00
|
|
|
my $iSize;
|
2014-10-06 02:49:30 +03:00
|
|
|
my $bErrorExpected = !$bExists || $bError || $bRemote;
|
|
|
|
|
|
|
|
eval
|
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
($strHash, $iSize) = $oFile->hash_size(PATH_BACKUP_ABSOLUTE, $strFile, $bCompressed)
|
2014-10-06 02:49:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'unexpected error raised: ' . $@;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bErrorExpected)
|
|
|
|
{
|
|
|
|
confess 'error was expected';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($strHash ne '06364afe79d801433188262478a76d19777ef351')
|
|
|
|
{
|
|
|
|
confess 'hashes do not match';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-25 21:15:55 +02:00
|
|
|
}
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test exists()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'exists')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
|
|
|
&log(INFO, '--------------------------------------------------------------------------------');
|
|
|
|
&log(INFO, "test File->exists()\n");
|
|
|
|
|
|
|
|
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
# Loop through exists
|
|
|
|
for (my $bExists = 0; $bExists <= 1; $bExists++)
|
|
|
|
{
|
|
|
|
# Loop through exists
|
|
|
|
for (my $bError = 0; $bError <= $bExists; $bError++)
|
|
|
|
{
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rmt ${bRemote}, err ${bError}, exists ${bExists}")) {next}
|
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup($bError);
|
|
|
|
|
|
|
|
my $strFile = "${strTestPath}/test.txt";
|
|
|
|
|
|
|
|
if ($bError)
|
|
|
|
{
|
|
|
|
$strFile = "${strTestPath}/private/test.txt";
|
|
|
|
}
|
|
|
|
elsif ($bExists)
|
|
|
|
{
|
|
|
|
system("echo 'TESTDATA' > ${strFile}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute in eval in case of error
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
if ($oFile->exists(PATH_BACKUP_ABSOLUTE, $strFile) != $bExists)
|
|
|
|
{
|
|
|
|
confess "bExists is set to ${bExists}, but exists() returned " . !$bExists;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
my $oMessage = $@;
|
|
|
|
my $iCode;
|
|
|
|
my $strMessage;
|
|
|
|
|
|
|
|
if (blessed($oMessage))
|
|
|
|
{
|
|
|
|
if ($oMessage->isa('BackRest::Exception'))
|
|
|
|
{
|
|
|
|
$iCode = $oMessage->code();
|
|
|
|
$strMessage = $oMessage->message();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess 'unknown error object';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strMessage = $oMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bError)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'error raised: ' . $strMessage . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test copy()
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'copy')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
# Loop through small/large
|
2015-04-21 15:45:03 +02:00
|
|
|
for (my $iLarge = 0; $iLarge <= 3; $iLarge++)
|
2015-03-25 21:15:55 +02:00
|
|
|
{
|
2014-10-06 02:49:30 +03:00
|
|
|
# Loop through backup local vs remote
|
|
|
|
for (my $bBackupRemote = 0; $bBackupRemote <= 1; $bBackupRemote++)
|
|
|
|
{
|
|
|
|
# Loop through db local vs remote
|
|
|
|
for (my $bDbRemote = 0; $bDbRemote <= 1; $bDbRemote++)
|
|
|
|
{
|
|
|
|
# Backup and db cannot both be remote
|
|
|
|
if ($bBackupRemote && $bDbRemote)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Determine side is remote
|
|
|
|
my $strRemote = $bBackupRemote ? 'backup' : $bDbRemote ? 'db' : undef;
|
|
|
|
|
|
|
|
# Create the file object
|
2015-03-25 21:15:55 +02:00
|
|
|
my $oFile = new BackRest::File
|
2014-10-06 02:49:30 +03:00
|
|
|
(
|
2015-03-25 21:15:55 +02:00
|
|
|
$strStanza,
|
|
|
|
$strTestPath,
|
|
|
|
$strRemote,
|
|
|
|
defined($strRemote) ? $oRemote : $oLocal
|
2014-10-06 02:49:30 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
# Loop through source path types
|
|
|
|
for (my $bSourcePathType = 0; $bSourcePathType <= 1; $bSourcePathType++)
|
|
|
|
{
|
|
|
|
# Loop through destination path types
|
|
|
|
for (my $bDestinationPathType = 0; $bDestinationPathType <= 1; $bDestinationPathType++)
|
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
# Loop through source missing/present
|
2015-04-21 15:45:03 +02:00
|
|
|
for (my $bSourceMissing = 0; $bSourceMissing <= !$iLarge; $bSourceMissing++)
|
2015-03-25 21:15:55 +02:00
|
|
|
{
|
2014-10-06 02:49:30 +03:00
|
|
|
# Loop through source ignore/require
|
2015-04-21 15:45:03 +02:00
|
|
|
for (my $bSourceIgnoreMissing = 0; $bSourceIgnoreMissing <= !$iLarge; $bSourceIgnoreMissing++)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
# Loop through checksum append
|
2015-04-21 15:45:03 +02:00
|
|
|
for (my $bChecksumAppend = 0; $bChecksumAppend <= !$iLarge; $bChecksumAppend++)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
# Loop through source compression
|
|
|
|
for (my $bSourceCompressed = 0; $bSourceCompressed <= !$bSourceMissing; $bSourceCompressed++)
|
|
|
|
{
|
|
|
|
# Loop through destination compression
|
|
|
|
for (my $bDestinationCompress = 0; $bDestinationCompress <= !$bSourceMissing; $bDestinationCompress++)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
|
|
|
my $strSourcePathType = $bSourcePathType ? PATH_DB_ABSOLUTE : PATH_BACKUP_ABSOLUTE;
|
|
|
|
my $strSourcePath = $bSourcePathType ? 'db' : 'backup';
|
|
|
|
|
|
|
|
my $strDestinationPathType = $bDestinationPathType ? PATH_DB_ABSOLUTE : PATH_BACKUP_ABSOLUTE;
|
|
|
|
my $strDestinationPath = $bDestinationPathType ? 'db' : 'backup';
|
|
|
|
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-04-21 15:45:03 +02:00
|
|
|
"lrg ${iLarge}, rmt " .
|
2014-10-06 02:49:30 +03:00
|
|
|
(defined($strRemote) && ($strRemote eq $strSourcePath ||
|
|
|
|
$strRemote eq $strDestinationPath) ? 1 : 0) .
|
2015-03-25 21:15:55 +02:00
|
|
|
', srcpth ' . (defined($strRemote) && $strRemote eq $strSourcePath ? 'rmt' : 'lcl') .
|
|
|
|
":${strSourcePath}, srcmiss ${bSourceMissing}, " .
|
|
|
|
"srcignmiss ${bSourceIgnoreMissing}, srccmp $bSourceCompressed, " .
|
2014-10-06 02:49:30 +03:00
|
|
|
'dstpth ' .
|
|
|
|
(defined($strRemote) && $strRemote eq $strDestinationPath ? 'rmt' : 'lcl') .
|
2015-03-25 21:15:55 +02:00
|
|
|
":${strDestinationPath}, chkapp ${bChecksumAppend}, " .
|
|
|
|
"dstcmp $bDestinationCompress")) {next}
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
# Setup test directory
|
|
|
|
BackRestTestFile_Setup(false);
|
|
|
|
system("mkdir ${strTestPath}/backup") == 0 or confess 'Unable to create test/backup directory';
|
|
|
|
system("mkdir ${strTestPath}/db") == 0 or confess 'Unable to create test/db directory';
|
|
|
|
|
|
|
|
my $strSourceFile = "${strTestPath}/${strSourcePath}/test-source";
|
|
|
|
my $strDestinationFile = "${strTestPath}/${strDestinationPath}/test-destination";
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
my $strCopyHash;
|
|
|
|
my $iCopySize;
|
|
|
|
|
2014-10-06 02:49:30 +03:00
|
|
|
# Create the compressed or uncompressed test file
|
|
|
|
my $strSourceHash;
|
2015-03-25 21:15:55 +02:00
|
|
|
my $iSourceSize;
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
if (!$bSourceMissing)
|
|
|
|
{
|
2015-04-21 15:45:03 +02:00
|
|
|
if ($iLarge)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
|
|
|
$strSourceFile .= '.bin';
|
|
|
|
$strDestinationFile .= '.bin';
|
|
|
|
|
2015-04-21 15:45:03 +02:00
|
|
|
if ($iLarge < 3)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute('cp ' . BackRestTestCommon_DataPathGet() .
|
|
|
|
"/test.archive${iLarge}.bin ${strSourceFile}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (my $iTableSizeIdx = 0; $iTableSizeIdx < 100; $iTableSizeIdx++)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute('cat ' . BackRestTestCommon_DataPathGet() .
|
|
|
|
"/test.table.bin >> ${strSourceFile}");
|
|
|
|
}
|
|
|
|
}
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strSourceFile .= '.txt';
|
|
|
|
$strDestinationFile .= '.txt';
|
|
|
|
|
|
|
|
system("echo 'TESTDATA' > ${strSourceFile}");
|
|
|
|
}
|
|
|
|
|
2015-04-21 15:45:03 +02:00
|
|
|
if ($iLarge == 1)
|
2015-03-25 21:15:55 +02:00
|
|
|
{
|
2015-05-29 14:12:39 +02:00
|
|
|
$strSourceHash = '4518a0fdf41d796760b384a358270d4682589820';
|
2015-03-25 21:15:55 +02:00
|
|
|
$iSourceSize = 16777216;
|
|
|
|
}
|
2015-04-21 15:45:03 +02:00
|
|
|
elsif ($iLarge == 2)
|
2015-03-25 21:15:55 +02:00
|
|
|
{
|
|
|
|
$strSourceHash = '1c7e00fd09b9dd11fc2966590b3e3274645dd031';
|
|
|
|
$iSourceSize = 16777216;
|
|
|
|
}
|
2015-04-21 15:45:03 +02:00
|
|
|
elsif ($iLarge == 3)
|
|
|
|
{
|
|
|
|
$strSourceHash = 'c23a89d47c7a006fcda51da0cc95993dc9aad995';
|
|
|
|
$iSourceSize = 104857600;
|
|
|
|
}
|
2015-03-25 21:15:55 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$strSourceHash = '06364afe79d801433188262478a76d19777ef351';
|
|
|
|
$iSourceSize = 9;
|
|
|
|
}
|
2014-10-06 02:49:30 +03:00
|
|
|
|
|
|
|
if ($bSourceCompressed)
|
|
|
|
{
|
|
|
|
system("gzip ${strSourceFile}");
|
|
|
|
$strSourceFile .= '.gz';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bDestinationCompress)
|
|
|
|
{
|
|
|
|
$strDestinationFile .= '.gz';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run file copy in an eval block because some errors are expected
|
|
|
|
my $bReturn;
|
|
|
|
|
|
|
|
eval
|
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
($bReturn, $strCopyHash, $iCopySize) =
|
|
|
|
$oFile->copy($strSourcePathType, $strSourceFile,
|
|
|
|
$strDestinationPathType, $strDestinationFile,
|
|
|
|
$bSourceCompressed, $bDestinationCompress,
|
2015-08-05 14:43:41 +02:00
|
|
|
$bSourceIgnoreMissing, undef, '0770', false, undef, undef,
|
2015-03-25 21:15:55 +02:00
|
|
|
$bChecksumAppend);
|
2014-10-06 02:49:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
# Check for errors after copy
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
my $oMessage = $@;
|
|
|
|
|
|
|
|
if (blessed($oMessage))
|
|
|
|
{
|
|
|
|
if ($oMessage->isa('BackRest::Exception'))
|
|
|
|
{
|
|
|
|
if ($bSourceMissing && !$bSourceIgnoreMissing)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess $oMessage->message();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess 'unknown error object: ' . $oMessage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
confess $oMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bSourceMissing)
|
|
|
|
{
|
|
|
|
if ($bSourceIgnoreMissing)
|
|
|
|
{
|
|
|
|
if ($bReturn)
|
|
|
|
{
|
|
|
|
confess 'copy() returned ' . $bReturn . ' when ignore missing set';
|
|
|
|
}
|
|
|
|
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
confess 'expected source file missing error';
|
|
|
|
}
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
if (!defined($strCopyHash))
|
|
|
|
{
|
|
|
|
confess 'copy hash must be defined';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bChecksumAppend)
|
|
|
|
{
|
|
|
|
if ($bDestinationCompress)
|
|
|
|
{
|
|
|
|
$strDestinationFile =
|
|
|
|
substr($strDestinationFile, 0, length($strDestinationFile) -3) . "-${strSourceHash}.gz";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strDestinationFile .= '-' . $strSourceHash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 02:49:30 +03:00
|
|
|
unless (-e $strDestinationFile)
|
|
|
|
{
|
|
|
|
confess "could not find destination file ${strDestinationFile}";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strDestinationTest = $strDestinationFile;
|
|
|
|
|
|
|
|
if ($bDestinationCompress)
|
|
|
|
{
|
|
|
|
$strDestinationTest = substr($strDestinationFile, 0, length($strDestinationFile) - 3) . '.test';
|
|
|
|
|
|
|
|
system("gzip -dc ${strDestinationFile} > ${strDestinationTest}") == 0
|
|
|
|
or die "could not decompress ${strDestinationFile}";
|
|
|
|
}
|
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
my ($strDestinationHash, $iDestinationSize) = $oFile->hash_size(PATH_ABSOLUTE, $strDestinationTest);
|
2014-10-06 02:49:30 +03:00
|
|
|
|
2015-03-25 21:15:55 +02:00
|
|
|
if ($strSourceHash ne $strDestinationHash || $strSourceHash ne $strCopyHash)
|
2014-10-06 02:49:30 +03:00
|
|
|
{
|
2015-03-25 21:15:55 +02:00
|
|
|
confess "source ${strSourceHash}, copy ${strCopyHash} and destination ${strDestinationHash} file hashes do not match";
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
2015-03-25 21:15:55 +02:00
|
|
|
|
|
|
|
if ($iSourceSize != $iDestinationSize || $iSourceSize != $iCopySize)
|
|
|
|
{
|
|
|
|
confess "source ${iSourceSize}, copy ${iCopySize} and destination ${iDestinationSize} sizes do not match";
|
|
|
|
}
|
|
|
|
}
|
2014-10-06 02:49:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
BackRestTestFile_Setup(undef, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|