2014-06-22 17:30:17 +03:00
|
|
|
#!/usr/bin/perl
|
|
|
|
####################################################################################################################################
|
2015-03-08 19:26:09 +02:00
|
|
|
# BackupTest.pl - Unit Tests for BackRest::Backup and BackRest::Restore
|
2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
2014-06-22 18:56:01 +03:00
|
|
|
package BackRestTest::BackupTest;
|
2014-06-22 17:30:17 +03:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
2015-03-03 07:57:20 +02:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
use DBI;
|
|
|
|
use Exporter qw(import);
|
|
|
|
use Fcntl ':mode';
|
2014-06-22 17:30:17 +03:00
|
|
|
use File::Basename;
|
2014-09-16 18:22:55 +03:00
|
|
|
use File::Copy 'cp';
|
2014-10-18 20:25:20 +03:00
|
|
|
use File::stat;
|
2015-01-25 19:20:12 +02:00
|
|
|
use Time::HiRes qw(gettimeofday);
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
use lib dirname($0) . '/../lib';
|
2015-06-14 00:25:49 +02:00
|
|
|
use BackRest::Archive;
|
|
|
|
use BackRest::ArchiveInfo;
|
2015-08-08 23:11:20 +02:00
|
|
|
use BackRest::Db;
|
2015-01-27 18:44:23 +02:00
|
|
|
use BackRest::Config;
|
2015-06-14 00:25:49 +02:00
|
|
|
use BackRest::Exception;
|
2014-06-22 17:30:17 +03:00
|
|
|
use BackRest::File;
|
2015-06-14 00:25:49 +02:00
|
|
|
use BackRest::Ini;
|
|
|
|
use BackRest::Manifest;
|
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-06-22 17:30:17 +03:00
|
|
|
|
2015-08-06 06:00:30 +02:00
|
|
|
use BackRestTest::BackupCommonTest;
|
2014-06-22 18:56:01 +03:00
|
|
|
use BackRestTest::CommonTest;
|
|
|
|
|
2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
2014-06-22 18:56:01 +03:00
|
|
|
# BackRestTestBackup_Test
|
2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
2015-08-06 06:00:30 +02:00
|
|
|
our @EXPORT = qw(BackRestTestBackup_Test);
|
|
|
|
|
2014-06-22 18:56:01 +03:00
|
|
|
sub BackRestTestBackup_Test
|
2014-06-22 17:30:17 +03:00
|
|
|
{
|
|
|
|
my $strTest = shift;
|
2015-02-28 17:21:36 +02:00
|
|
|
my $iThreadMax = shift;
|
2014-06-22 17:30:17 +03:00
|
|
|
|
|
|
|
# If no test was specified, then run them all
|
|
|
|
if (!defined($strTest))
|
|
|
|
{
|
|
|
|
$strTest = 'all';
|
|
|
|
}
|
|
|
|
|
2014-08-10 22:02:14 +03:00
|
|
|
# Setup global variables
|
2015-08-06 06:00:30 +02:00
|
|
|
my $strTestPath = BackRestTestCommon_TestPathGet();
|
|
|
|
my $strHost = BackRestTestCommon_HostGet();
|
|
|
|
my $strUser = BackRestTestCommon_UserGet();
|
|
|
|
my $strUserBackRest = BackRestTestCommon_UserBackRestGet();
|
|
|
|
my $strGroup = BackRestTestCommon_GroupGet();
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2014-06-22 17:30:17 +03:00
|
|
|
# Setup test variables
|
|
|
|
my $iRun;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strModule = 'backup';
|
|
|
|
my $strThisTest;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bCreate;
|
2014-06-22 18:56:01 +03:00
|
|
|
my $strStanza = BackRestTestCommon_StanzaGet();
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2014-07-17 02:15:56 +03:00
|
|
|
my $strArchiveChecksum = '1c7e00fd09b9dd11fc2966590b3e3274645dd031';
|
|
|
|
my $iArchiveMax = 3;
|
|
|
|
my $strXlogPath = BackRestTestCommon_DbCommonPathGet() . '/pg_xlog';
|
2015-03-03 03:36:12 +02:00
|
|
|
my $strArchiveTestFile = BackRestTestCommon_DataPathGet() . '/test.archive2.bin';
|
2015-05-29 14:12:39 +02:00
|
|
|
my $strArchiveTestFile2 = BackRestTestCommon_DataPathGet() . '/test.archive1.bin';
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2014-06-22 18:56:01 +03:00
|
|
|
# Print test banner
|
2014-09-16 18:22:55 +03:00
|
|
|
&log(INFO, 'BACKUP MODULE ******************************************************************');
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2015-05-29 23:58:13 +02:00
|
|
|
# Drop any existing cluster
|
|
|
|
BackRestTestBackup_Drop(true, true);
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-03-12 18:15:19 +02:00
|
|
|
# Create remotes
|
2014-07-16 05:32:41 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-08-05 14:43:41 +02:00
|
|
|
my $oRemote = new BackRest::Protocol::RemoteMaster
|
2014-07-16 05:32:41 +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-03 03:36:12 +02:00
|
|
|
);
|
|
|
|
|
2015-08-05 14:43:41 +02:00
|
|
|
my $oLocal = new BackRest::Protocol::Common
|
2015-03-03 03:36:12 +02:00
|
|
|
(
|
2015-03-12 18:15:19 +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-07-16 05:32:41 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2014-07-17 02:15:56 +03:00
|
|
|
# Test archive-push
|
2014-07-16 05:32:41 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-05-28 19:17:34 +02:00
|
|
|
$strThisTest = 'archive-push';
|
|
|
|
|
|
|
|
if ($strTest eq 'all' || $strTest eq $strThisTest)
|
2014-07-13 17:37:16 +03:00
|
|
|
{
|
|
|
|
$iRun = 0;
|
2014-07-16 05:32:41 +03:00
|
|
|
$bCreate = true;
|
|
|
|
my $oFile;
|
2014-07-13 17:37:16 +03:00
|
|
|
|
2015-05-28 19:17:34 +02:00
|
|
|
&log(INFO, "Test ${strThisTest}\n");
|
2014-07-13 17:37:16 +03:00
|
|
|
|
|
|
|
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
|
|
|
{
|
2014-07-16 05:32:41 +03:00
|
|
|
for (my $bCompress = false; $bCompress <= true; $bCompress++)
|
2014-07-13 17:37:16 +03:00
|
|
|
{
|
2015-01-28 17:29:29 +02:00
|
|
|
for (my $bArchiveAsync = false; $bArchiveAsync <= true; $bArchiveAsync++)
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-03-01 03:31:56 +02:00
|
|
|
"rmt ${bRemote}, cmp ${bCompress}, " .
|
2015-05-28 19:17:34 +02:00
|
|
|
"arc_async ${bArchiveAsync}",
|
|
|
|
$iThreadMax == 1 ? $strModule : undef,
|
|
|
|
$iThreadMax == 1 ? $strThisTest: undef)) {next}
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
# Create the file object
|
2014-07-16 05:32:41 +03:00
|
|
|
if ($bCreate)
|
|
|
|
{
|
2014-10-10 22:13:28 +03:00
|
|
|
$oFile = (new BackRest::File
|
2014-07-16 05:32:41 +03:00
|
|
|
(
|
2014-10-10 22:13:28 +03:00
|
|
|
$strStanza,
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_RepoPathGet(),
|
2014-10-10 22:13:28 +03:00
|
|
|
$bRemote ? 'backup' : undef,
|
2015-03-03 03:36:12 +02:00
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-07-16 05:32:41 +03:00
|
|
|
))->clone();
|
|
|
|
|
|
|
|
$bCreate = false;
|
|
|
|
}
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
# Create the test directory
|
|
|
|
BackRestTestBackup_Create($bRemote, false);
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
BackRestTestCommon_ConfigCreate('db',
|
2014-12-24 01:52:38 +02:00
|
|
|
($bRemote ? BACKUP : undef),
|
2014-07-16 05:32:41 +03:00
|
|
|
$bCompress,
|
2015-03-01 03:31:56 +02:00
|
|
|
undef, # checksum
|
2014-07-16 05:32:41 +03:00
|
|
|
undef, # hardlink
|
|
|
|
undef, # thread-max
|
|
|
|
$bArchiveAsync,
|
2015-03-25 00:50:14 +02:00
|
|
|
undef);
|
2014-07-16 05:32:41 +03:00
|
|
|
|
|
|
|
my $strCommand = BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() .
|
2015-04-01 21:58:33 +02:00
|
|
|
'/pg_backrest.conf --no-fork --stanza=db archive-push';
|
2014-07-16 05:32:41 +03:00
|
|
|
|
|
|
|
# Loop through backups
|
|
|
|
for (my $iBackup = 1; $iBackup <= 3; $iBackup++)
|
|
|
|
{
|
|
|
|
my $strArchiveFile;
|
|
|
|
|
|
|
|
# Loop through archive files
|
|
|
|
for (my $iArchive = 1; $iArchive <= $iArchiveMax; $iArchive++)
|
|
|
|
{
|
|
|
|
# Construct the archive filename
|
|
|
|
my $iArchiveNo = (($iBackup - 1) * $iArchiveMax + ($iArchive - 1)) + 1;
|
|
|
|
|
|
|
|
if ($iArchiveNo > 255)
|
|
|
|
{
|
2014-09-16 18:22:55 +03:00
|
|
|
confess 'backup total * archive total cannot be greater than 255';
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
$strArchiveFile = uc(sprintf('0000000100000001%08x', $iArchiveNo));
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
&log(INFO, ' backup ' . sprintf('%02d', $iBackup) .
|
|
|
|
', archive ' .sprintf('%02x', $iArchive) .
|
2014-07-16 05:32:41 +03:00
|
|
|
" - ${strArchiveFile}");
|
|
|
|
|
2014-07-17 02:15:56 +03:00
|
|
|
my $strSourceFile = "${strXlogPath}/${strArchiveFile}";
|
|
|
|
|
|
|
|
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile, # Source file
|
|
|
|
PATH_DB_ABSOLUTE, $strSourceFile, # Destination file
|
|
|
|
false, # Source is not compressed
|
|
|
|
false, # Destination is not compressed
|
|
|
|
undef, undef, undef, # Unused params
|
|
|
|
true); # Create path if it does not exist
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2014-07-17 02:15:56 +03:00
|
|
|
BackRestTestCommon_Execute($strCommand . " ${strSourceFile}");
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
if ($iArchive == $iBackup)
|
|
|
|
{
|
|
|
|
# load the archive info file so it can be munged for testing
|
|
|
|
my $strInfoFile = $oFile->path_get(PATH_BACKUP_ARCHIVE, ARCHIVE_INFO_FILE);
|
|
|
|
my %oInfo;
|
|
|
|
BackRestTestCommon_iniLoad($strInfoFile, \%oInfo, $bRemote);
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strDbVersion = $oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_VERSION};
|
|
|
|
my $ullDbSysId = $oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_SYSTEM_ID};
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
# Break the database version
|
2015-06-14 00:25:49 +02:00
|
|
|
$oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_VERSION} = '8.0';
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
&log(INFO, ' test db version mismatch error');
|
|
|
|
|
|
|
|
BackRestTestCommon_Execute($strCommand . " ${strSourceFile}", undef, undef, undef,
|
|
|
|
ERROR_ARCHIVE_MISMATCH);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Break the system id
|
|
|
|
$oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_VERSION} = $strDbVersion;
|
|
|
|
$oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_SYSTEM_ID} = '5000900090001855000';
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
&log(INFO, ' test db system-id mismatch error');
|
|
|
|
|
|
|
|
BackRestTestCommon_Execute($strCommand . " ${strSourceFile}", undef, undef, undef,
|
|
|
|
ERROR_ARCHIVE_MISMATCH);
|
|
|
|
|
|
|
|
# Move settings back to original
|
2015-06-14 00:25:49 +02:00
|
|
|
$oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_SYSTEM_ID} = $ullDbSysId;
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2015-05-29 14:12:39 +02:00
|
|
|
# Should succeed because checksum is the same
|
|
|
|
&log(INFO, ' test archive duplicate ok');
|
|
|
|
|
|
|
|
BackRestTestCommon_Execute($strCommand . " ${strSourceFile}");
|
|
|
|
|
|
|
|
# Now it should break on archive duplication (because checksum is different
|
2015-04-01 21:58:33 +02:00
|
|
|
&log(INFO, ' test archive duplicate error');
|
|
|
|
|
2015-05-29 14:12:39 +02:00
|
|
|
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile2, # Source file
|
|
|
|
PATH_DB_ABSOLUTE, $strSourceFile, # Destination file
|
|
|
|
false, # Source is not compressed
|
|
|
|
false, # Destination is not compressed
|
|
|
|
undef, undef, undef, # Unused params
|
|
|
|
true); # Create path if it does not exist
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
BackRestTestCommon_Execute($strCommand . " ${strSourceFile}", undef, undef, undef,
|
|
|
|
ERROR_ARCHIVE_DUPLICATE);
|
|
|
|
|
2015-05-28 19:17:34 +02:00
|
|
|
if ($bArchiveAsync)
|
2015-04-01 21:58:33 +02:00
|
|
|
{
|
2015-05-28 19:17:34 +02:00
|
|
|
my $strDuplicateWal =
|
|
|
|
($bRemote ? BackRestTestCommon_LocalPathGet() : BackRestTestCommon_RepoPathGet()) .
|
2015-05-29 14:12:39 +02:00
|
|
|
"/archive/${strStanza}/out/${strArchiveFile}-4518a0fdf41d796760b384a358270d4682589820";
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
unlink ($strDuplicateWal)
|
|
|
|
or confess "unable to remove duplicate WAL segment created for testing: ${strDuplicateWal}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
# Build the archive name to check for at the destination
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strArchiveCheck = "9.3-1/${strArchiveFile}-${strArchiveChecksum}";
|
2014-07-16 05:32:41 +03:00
|
|
|
|
|
|
|
if ($bCompress)
|
|
|
|
{
|
2014-09-16 18:22:55 +03:00
|
|
|
$strArchiveCheck .= '.gz';
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:13:07 +02:00
|
|
|
my $oWait = waitInit(5);
|
|
|
|
my $bFound = false;
|
|
|
|
|
|
|
|
do
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
2015-07-13 18:13:07 +02:00
|
|
|
$bFound = $oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck);
|
|
|
|
}
|
|
|
|
while (!$bFound && waitMore($oWait));
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-07-13 18:13:07 +02:00
|
|
|
if (!$bFound)
|
|
|
|
{
|
|
|
|
confess 'unable to find ' . $strArchiveCheck;
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# !!! Need to put in tests for .backup files here
|
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
BackRestTestCommon_TestLogAppendFile($oFile->path_get(PATH_BACKUP_ARCHIVE) . '/archive.info', $bRemote);
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
2014-07-13 17:37:16 +03:00
|
|
|
}
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
$bCreate = true;
|
|
|
|
}
|
2014-07-13 17:37:16 +03:00
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
2015-01-30 21:54:08 +02:00
|
|
|
BackRestTestBackup_Drop(true);
|
2014-07-13 17:37:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-28 19:17:34 +02:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test archive-stop
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strThisTest = 'archive-stop';
|
|
|
|
|
|
|
|
if ($strTest eq 'all' || $strTest eq $strThisTest)
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
$bCreate = true;
|
|
|
|
my $oFile;
|
|
|
|
|
|
|
|
&log(INFO, "Test ${strThisTest}\n");
|
|
|
|
|
|
|
|
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
|
|
|
{
|
|
|
|
for (my $bCompress = false; $bCompress <= true; $bCompress++)
|
|
|
|
{
|
|
|
|
for (my $iError = 0; $iError <= $bRemote; $iError++)
|
|
|
|
{
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rmt ${bRemote}, cmp ${bCompress}" .
|
|
|
|
', error ' . ($iError ? 'connect' : 'version'),
|
|
|
|
$iThreadMax == 1 ? $strModule : undef,
|
|
|
|
$iThreadMax == 1 ? $strThisTest: undef)) {next}
|
|
|
|
|
|
|
|
# Create the file object
|
|
|
|
if ($bCreate)
|
|
|
|
{
|
|
|
|
$oFile = (new BackRest::File
|
|
|
|
(
|
|
|
|
$strStanza,
|
|
|
|
BackRestTestCommon_RepoPathGet(),
|
|
|
|
$bRemote ? 'backup' : undef,
|
|
|
|
$bRemote ? $oRemote : $oLocal
|
|
|
|
))->clone();
|
|
|
|
|
|
|
|
$bCreate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create the test directory
|
|
|
|
BackRestTestBackup_Create($bRemote, false);
|
|
|
|
|
|
|
|
BackRestTestCommon_ConfigCreate('db',
|
|
|
|
($bRemote ? BACKUP : undef),
|
|
|
|
$bCompress,
|
|
|
|
undef, # checksum
|
|
|
|
undef, # hardlink
|
|
|
|
undef, # thread-max
|
|
|
|
true, # archive-async
|
|
|
|
undef);
|
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
# Helper function to push archive logs
|
|
|
|
sub archivePush
|
|
|
|
{
|
|
|
|
my $oFile = shift;
|
|
|
|
my $strXlogPath = shift;
|
|
|
|
my $strArchiveTestFile = shift;
|
|
|
|
my $iArchiveNo = shift;
|
|
|
|
my $iExpectedError = shift;
|
|
|
|
|
|
|
|
my $strSourceFile = "${strXlogPath}/" . uc(sprintf('0000000100000001%08x', $iArchiveNo));
|
|
|
|
|
|
|
|
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile, # Source file
|
|
|
|
PATH_DB_ABSOLUTE, $strSourceFile, # Destination file
|
|
|
|
false, # Source is not compressed
|
|
|
|
false, # Destination is not compressed
|
|
|
|
undef, undef, undef, # Unused params
|
|
|
|
true); # Create path if it does not exist
|
|
|
|
|
|
|
|
my $strCommand = BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() .
|
|
|
|
'/pg_backrest.conf --archive-max-mb=24 --no-fork --stanza=db archive-push' .
|
|
|
|
(defined($iExpectedError) && $iExpectedError == ERROR_HOST_CONNECT ?
|
|
|
|
" --backup-host=bogus" : '');
|
|
|
|
|
|
|
|
BackRestTestCommon_Execute($strCommand . " ${strSourceFile}", undef, undef, undef,
|
|
|
|
$iExpectedError);
|
|
|
|
}
|
2015-05-28 19:17:34 +02:00
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
# Push a WAL segment
|
|
|
|
archivePush($oFile, $strXlogPath, $strArchiveTestFile, 1);
|
2015-05-28 19:17:34 +02:00
|
|
|
|
|
|
|
# load the archive info file so it can be munged for testing
|
|
|
|
my $strInfoFile = $oFile->path_get(PATH_BACKUP_ARCHIVE, ARCHIVE_INFO_FILE);
|
|
|
|
my %oInfo;
|
|
|
|
BackRestTestCommon_iniLoad($strInfoFile, \%oInfo, $bRemote);
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strDbVersion = $oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_VERSION};
|
|
|
|
my $ullDbSysId = $oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_SYSTEM_ID};
|
2015-05-28 19:17:34 +02:00
|
|
|
|
|
|
|
# Break the database version
|
|
|
|
if ($iError == 0)
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
$oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_VERSION} = '8.0';
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
2015-05-28 19:17:34 +02:00
|
|
|
}
|
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
# Push two more segments with errors to exceed archive-max-mb
|
|
|
|
archivePush($oFile, $strXlogPath, $strArchiveTestFile, 2,
|
|
|
|
$iError ? ERROR_HOST_CONNECT : ERROR_ARCHIVE_MISMATCH);
|
2015-05-28 19:17:34 +02:00
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
archivePush($oFile, $strXlogPath, $strArchiveTestFile, 3,
|
|
|
|
$iError ? ERROR_HOST_CONNECT : ERROR_ARCHIVE_MISMATCH);
|
2015-05-28 19:17:34 +02:00
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
# Now this segment will get dropped
|
|
|
|
archivePush($oFile, $strXlogPath, $strArchiveTestFile, 4);
|
2015-05-28 19:17:34 +02:00
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
# Fix the database version
|
2015-05-28 19:17:34 +02:00
|
|
|
if ($iError == 0)
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
$oInfo{&INFO_ARCHIVE_SECTION_DB}{&INFO_ARCHIVE_KEY_DB_VERSION} = '9.3';
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
2015-05-28 19:17:34 +02:00
|
|
|
}
|
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
# Remove the stop file
|
2015-05-28 19:17:34 +02:00
|
|
|
my $strStopFile = ($bRemote ? BackRestTestCommon_LocalPathGet() : BackRestTestCommon_RepoPathGet()) .
|
|
|
|
'/lock/db-archive.stop';
|
|
|
|
|
|
|
|
unlink($strStopFile)
|
|
|
|
or die "unable to remove stop file ${strStopFile}";
|
|
|
|
|
2015-05-29 17:41:19 +02:00
|
|
|
# Push two more segments - only #4 should be missing from the archive at the end
|
|
|
|
archivePush($oFile, $strXlogPath, $strArchiveTestFile, 5);
|
|
|
|
archivePush($oFile, $strXlogPath, $strArchiveTestFile, 6);
|
2015-05-28 19:17:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$bCreate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
|
|
|
BackRestTestBackup_Drop(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 02:15:56 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test archive-get
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-05-28 19:17:34 +02:00
|
|
|
$strThisTest = 'archive-get';
|
|
|
|
|
|
|
|
if ($strTest eq 'all' || $strTest eq $strThisTest)
|
2014-07-17 02:15:56 +03:00
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
$bCreate = true;
|
|
|
|
my $oFile;
|
|
|
|
|
2015-05-28 19:17:34 +02:00
|
|
|
&log(INFO, "Test ${strThisTest}\n");
|
2014-07-17 02:15:56 +03:00
|
|
|
|
|
|
|
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
|
|
|
{
|
|
|
|
for (my $bCompress = false; $bCompress <= true; $bCompress++)
|
|
|
|
{
|
2014-10-02 17:55:38 +03:00
|
|
|
for (my $bExists = false; $bExists <= true; $bExists++)
|
2014-07-17 02:15:56 +03:00
|
|
|
{
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-05-28 19:17:34 +02:00
|
|
|
"rmt ${bRemote}, cmp ${bCompress}, exists ${bExists}",
|
|
|
|
$iThreadMax == 1 ? $strModule : undef,
|
|
|
|
$iThreadMax == 1 ? $strThisTest: undef)) {next}
|
2014-07-17 02:15:56 +03:00
|
|
|
|
|
|
|
# Create the test directory
|
|
|
|
if ($bCreate)
|
|
|
|
{
|
|
|
|
# Create the file object
|
|
|
|
$oFile = (BackRest::File->new
|
|
|
|
(
|
2014-10-10 22:13:28 +03:00
|
|
|
$strStanza,
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_RepoPathGet(),
|
2014-10-10 22:13:28 +03:00
|
|
|
$bRemote ? 'backup' : undef,
|
2015-03-03 03:36:12 +02:00
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-07-17 02:15:56 +03:00
|
|
|
))->clone();
|
|
|
|
|
|
|
|
BackRestTestBackup_Create($bRemote, false);
|
|
|
|
|
|
|
|
# Create the db/common/pg_xlog directory
|
2014-10-16 20:22:34 +03:00
|
|
|
BackRestTestCommon_PathCreate($strXlogPath);
|
2014-07-17 02:15:56 +03:00
|
|
|
|
|
|
|
$bCreate = false;
|
|
|
|
}
|
|
|
|
|
2014-12-24 01:52:38 +02:00
|
|
|
BackRestTestCommon_ConfigCreate('db', # local
|
|
|
|
($bRemote ? BACKUP : undef), # remote
|
|
|
|
$bCompress, # compress
|
2015-03-01 03:31:56 +02:00
|
|
|
undef, # checksum
|
2014-12-24 01:52:38 +02:00
|
|
|
undef, # hardlink
|
|
|
|
undef, # thread-max
|
|
|
|
undef, # archive-async
|
|
|
|
undef); # compress-async
|
2014-07-17 02:15:56 +03:00
|
|
|
|
|
|
|
my $strCommand = BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() .
|
2014-09-16 18:22:55 +03:00
|
|
|
'/pg_backrest.conf --stanza=db archive-get';
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2015-06-22 15:51:16 +02:00
|
|
|
BackRestTestCommon_Execute($strCommand . " 000000010000000100000001 ${strXlogPath}/000000010000000100000001",
|
|
|
|
undef, undef, undef, ERROR_FILE_MISSING);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Create the archive info file
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g+r,g+x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackRestTestCommon_Execute('mkdir -p -m 770 ' . $oFile->path_get(PATH_BACKUP_ARCHIVE), $bRemote);
|
2015-07-07 03:00:48 +02:00
|
|
|
(new BackRest::ArchiveInfo($oFile->path_get(PATH_BACKUP_ARCHIVE)))->check('9.3', 1234567890123456789);
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestCommon_TestLogAppendFile($oFile->path_get(PATH_BACKUP_ARCHIVE) . '/archive.info', $bRemote);
|
|
|
|
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute("chmod g-r,g-x " . BackRestTestCommon_RepoPathGet(), $bRemote);
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
if ($bExists)
|
2014-07-17 02:15:56 +03:00
|
|
|
{
|
2014-10-02 17:55:38 +03:00
|
|
|
# Loop through archive files
|
|
|
|
my $strArchiveFile;
|
|
|
|
|
|
|
|
for (my $iArchiveNo = 1; $iArchiveNo <= $iArchiveMax; $iArchiveNo++)
|
2014-07-17 02:15:56 +03:00
|
|
|
{
|
2014-10-02 17:55:38 +03:00
|
|
|
# Construct the archive filename
|
|
|
|
if ($iArchiveNo > 255)
|
|
|
|
{
|
|
|
|
confess 'backup total * archive total cannot be greater than 255';
|
|
|
|
}
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
$strArchiveFile = uc(sprintf('0000000100000001%08x', $iArchiveNo));
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
&log(INFO, ' archive ' .sprintf('%02x', $iArchiveNo) .
|
|
|
|
" - ${strArchiveFile}");
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2015-03-01 03:31:56 +02:00
|
|
|
my $strSourceFile = "${strArchiveFile}-${strArchiveChecksum}";
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
if ($bCompress)
|
|
|
|
{
|
|
|
|
$strSourceFile .= '.gz';
|
|
|
|
}
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveTestFile, # Source file
|
|
|
|
PATH_BACKUP_ARCHIVE, "9.3-1/${strSourceFile}", # Destination file
|
|
|
|
false, # Source is not compressed
|
|
|
|
$bCompress, # Destination compress based on test
|
|
|
|
undef, undef, undef, # Unused params
|
|
|
|
true); # Create path if it does not exist
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
my $strDestinationFile = "${strXlogPath}/${strArchiveFile}";
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
BackRestTestCommon_Execute($strCommand . " ${strArchiveFile} ${strDestinationFile}");
|
2014-07-17 02:15:56 +03:00
|
|
|
|
2014-10-02 17:55:38 +03:00
|
|
|
# Check that the destination file exists
|
|
|
|
if ($oFile->exists(PATH_DB_ABSOLUTE, $strDestinationFile))
|
|
|
|
{
|
|
|
|
if ($oFile->hash(PATH_DB_ABSOLUTE, $strDestinationFile) ne $strArchiveChecksum)
|
|
|
|
{
|
|
|
|
confess "archive file hash does not match ${strArchiveChecksum}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-07-17 02:15:56 +03:00
|
|
|
{
|
2014-10-02 17:55:38 +03:00
|
|
|
confess 'archive file is not in destination';
|
2014-07-17 02:15:56 +03:00
|
|
|
}
|
|
|
|
}
|
2014-10-02 17:55:38 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
BackRestTestCommon_Execute($strCommand . " 000000090000000900000009 ${strXlogPath}/RECOVERYXLOG",
|
|
|
|
undef, undef, undef, 1);
|
2014-07-17 02:15:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$bCreate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
2015-01-30 21:54:08 +02:00
|
|
|
BackRestTestBackup_Drop(true);
|
2014-07-17 02:15:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 00:31:05 +02:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test expire
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-06-14 00:25:49 +02:00
|
|
|
$strThisTest = 'expire';
|
|
|
|
|
|
|
|
if ($strTest eq 'all' || $strTest eq $strThisTest)
|
2015-03-18 00:31:05 +02:00
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
my $oFile;
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
&log(INFO, "Test ${strThisTest}\n");
|
2015-03-18 00:31:05 +02:00
|
|
|
|
2015-08-08 06:51:58 +02:00
|
|
|
if (BackRestTestCommon_DbVersion() >= 9.5)
|
|
|
|
{
|
|
|
|
&log(WARN, 'currently unable to run expire test on version 9.5');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-18 00:31:05 +02:00
|
|
|
# Create the file object
|
|
|
|
$oFile = (BackRest::File->new
|
|
|
|
(
|
|
|
|
$strStanza,
|
|
|
|
BackRestTestCommon_RepoPathGet(),
|
|
|
|
'db',
|
|
|
|
$oLocal
|
|
|
|
))->clone();
|
|
|
|
|
|
|
|
# Create the database
|
|
|
|
BackRestTestBackup_Create(false);
|
|
|
|
|
|
|
|
# Create db config
|
|
|
|
BackRestTestCommon_ConfigCreate('db', # local
|
|
|
|
undef, # remote
|
|
|
|
false, # compress
|
|
|
|
undef, # checksum
|
|
|
|
undef, # hardlink
|
|
|
|
$iThreadMax, # thread-max
|
|
|
|
undef, # archive-async
|
|
|
|
undef); # compress-async
|
|
|
|
|
|
|
|
# Create backup config
|
|
|
|
BackRestTestCommon_ConfigCreate('backup', # local
|
|
|
|
undef, # remote
|
|
|
|
false, # compress
|
|
|
|
undef, # checksum
|
|
|
|
undef, # hardlink
|
|
|
|
$iThreadMax, # thread-max
|
|
|
|
undef, # archive-async
|
|
|
|
undef); # compress-async
|
|
|
|
|
|
|
|
# Backups
|
|
|
|
my @stryBackupExpected;
|
|
|
|
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_FULL, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_DIFF, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_INCR, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_FULL, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_DIFF, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_INCR, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_DIFF, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_DIFF, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_FULL, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_DIFF, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_INCR, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_INCR, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_INCR, $strStanza, false, $oFile);
|
|
|
|
push @stryBackupExpected, BackRestTestBackup_Backup(BACKUP_TYPE_DIFF, $strStanza, false, $oFile);
|
2015-06-14 00:25:49 +02:00
|
|
|
push @stryBackupExpected, 'backup.info';
|
2015-03-18 00:31:05 +02:00
|
|
|
push @stryBackupExpected, 'latest';
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-07-07 03:00:48 +02:00
|
|
|
"local")) {next}
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
# Append backup.info to create a baseline
|
|
|
|
BackRestTestCommon_TestLogAppendFile(BackRestTestCommon_RepoPathGet() .
|
|
|
|
"/backup/${strStanza}/backup.info", false);
|
|
|
|
|
2015-03-18 00:31:05 +02:00
|
|
|
# Create an archive log path that will be removed as old on the first archive expire call
|
2015-06-14 00:25:49 +02:00
|
|
|
$oFile->path_create(PATH_BACKUP_ARCHIVE, BackRestTestCommon_DbVersion() . '-1/0000000000000000');
|
2015-03-18 00:31:05 +02:00
|
|
|
|
|
|
|
# Get the expected archive list
|
2015-06-14 00:25:49 +02:00
|
|
|
my @stryArchiveExpected = $oFile->list(PATH_BACKUP_ARCHIVE, BackRestTestCommon_DbVersion() . '-1/0000000100000000');
|
2015-03-18 00:31:05 +02:00
|
|
|
|
|
|
|
# Expire all but the last two fulls
|
|
|
|
splice(@stryBackupExpected, 0, 3);
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 2);
|
|
|
|
|
|
|
|
# Expire all but the last three diffs
|
|
|
|
splice(@stryBackupExpected, 1, 3);
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, undef, 3);
|
|
|
|
|
|
|
|
# Expire all but the last three diffs and last two fulls (should be no change)
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 2, 3);
|
|
|
|
|
|
|
|
# Expire archive based on the last two fulls
|
|
|
|
splice(@stryArchiveExpected, 0, 10);
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 2, 3, 'full', 2);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($oFile->exists(PATH_BACKUP_ARCHIVE, BackRestTestCommon_DbVersion() . '-1/0000000000000000'))
|
2015-03-18 00:31:05 +02:00
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
confess 'archive log path ' . BackRestTestCommon_DbVersion() . '-1/0000000000000000 should have been removed';
|
2015-03-18 00:31:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Expire archive based on the last two diffs
|
|
|
|
splice(@stryArchiveExpected, 0, 18);
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 2, 3, 'diff', 2);
|
|
|
|
|
|
|
|
# Expire archive based on the last two incrs
|
|
|
|
splice(@stryBackupExpected, 0, 2);
|
|
|
|
splice(@stryArchiveExpected, 0, 9);
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 1, 2, 'incr', 2);
|
|
|
|
|
|
|
|
# Expire archive based on the last two incrs (no change in archive)
|
|
|
|
splice(@stryBackupExpected, 1, 4);
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 1, 1, 'incr', 2);
|
|
|
|
|
|
|
|
# Expire archive based on the last two diffs (no change in archive)
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 1, 1, 'diff', 2);
|
|
|
|
|
|
|
|
# Expire archive based on the last diff
|
|
|
|
splice(@stryArchiveExpected, 0, 3);
|
|
|
|
BackRestTestBackup_Expire($strStanza, $oFile, \@stryBackupExpected, \@stryArchiveExpected, 1, 1, 'diff', 1);
|
2015-08-08 06:51:58 +02:00
|
|
|
}
|
2015-03-18 00:31:05 +02:00
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
|
|
|
BackRestTestBackup_Drop(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 22:44:50 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-05-05 19:08:48 +02:00
|
|
|
# Test synthetic
|
2014-10-14 22:44:50 +03:00
|
|
|
#
|
|
|
|
# Check the backup and restore functionality using synthetic data.
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2015-05-05 19:08:48 +02:00
|
|
|
$strThisTest = 'synthetic';
|
|
|
|
|
|
|
|
if ($strTest eq 'all' || $strTest eq $strThisTest)
|
2014-10-16 02:11:09 +03:00
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
&log(INFO, "Test ${strModule} - ${strThisTest}\n");
|
2014-10-16 02:11:09 +03:00
|
|
|
|
|
|
|
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
|
|
|
{
|
|
|
|
for (my $bCompress = false; $bCompress <= true; $bCompress++)
|
|
|
|
{
|
|
|
|
for (my $bHardlink = false; $bHardlink <= true; $bHardlink++)
|
|
|
|
{
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-05-05 19:08:48 +02:00
|
|
|
"rmt ${bRemote}, cmp ${bCompress}, hardlink ${bHardlink}",
|
2015-05-07 02:24:34 +02:00
|
|
|
$iThreadMax == 1 ? $strModule : undef,
|
|
|
|
$iThreadMax == 1 ? $strThisTest: undef)) {next}
|
2014-10-16 02:11:09 +03:00
|
|
|
|
2014-10-18 20:25:20 +03:00
|
|
|
# Get base time
|
|
|
|
my $lTime = time() - 100000;
|
|
|
|
|
2014-10-16 02:11:09 +03:00
|
|
|
# Build the manifest
|
|
|
|
my %oManifest;
|
|
|
|
|
2015-06-22 19:11:07 +02:00
|
|
|
$oManifest{&INI_SECTION_BACKREST}{&INI_KEY_VERSION} = BACKREST_VERSION;
|
2015-06-14 00:25:49 +02:00
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_ARCHIVE_CHECK} = JSON::PP::true;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_ARCHIVE_COPY} = JSON::PP::true;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS} = $bCompress ? JSON::PP::true : JSON::PP::false;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_HARDLINK} = $bHardlink ? JSON::PP::true : JSON::PP::false;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_START_STOP} = JSON::PP::false;
|
|
|
|
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_CATALOG} = 201306121;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_CONTROL} = 937;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_SYSTEM_ID} = 6156904820763115222;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_DB_VERSION} = '9.3';
|
2014-10-16 02:11:09 +03:00
|
|
|
|
|
|
|
# Create the test directory
|
|
|
|
BackRestTestBackup_Create($bRemote, false);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$oManifest{'backup:path'}{base}{&MANIFEST_SUBKEY_PATH} = BackRestTestCommon_DbCommonPathGet();
|
2014-10-18 20:25:20 +03:00
|
|
|
|
2014-10-19 23:30:16 +03:00
|
|
|
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base');
|
2014-10-16 02:11:09 +03:00
|
|
|
|
|
|
|
# Create the file object
|
|
|
|
my $oFile = new BackRest::File
|
|
|
|
(
|
|
|
|
$strStanza,
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_RepoPathGet(),
|
2014-10-16 02:11:09 +03:00
|
|
|
$bRemote ? 'backup' : undef,
|
2015-03-03 03:36:12 +02:00
|
|
|
$bRemote ? $oRemote : $oLocal
|
2014-10-16 02:11:09 +03:00
|
|
|
);
|
|
|
|
|
2014-10-20 00:41:11 +03:00
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'PG_VERSION', '9.3',
|
2015-03-01 03:31:56 +02:00
|
|
|
'e1f7a3a299f62225cba076fc6d3d6e677f303482', $lTime);
|
2014-10-20 00:41:11 +03:00
|
|
|
|
2014-10-19 23:30:16 +03:00
|
|
|
# Create base path
|
|
|
|
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base', 'base');
|
2014-10-16 02:11:09 +03:00
|
|
|
|
2014-10-19 23:30:16 +03:00
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base1.txt', 'BASE',
|
2015-03-01 03:31:56 +02:00
|
|
|
'a3b357a3e395e43fcfb19bb13f3c1b5179279593', $lTime);
|
2014-10-16 02:11:09 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Create global path
|
|
|
|
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base', 'global');
|
|
|
|
|
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'global/pg_control', '[replaceme]',
|
|
|
|
'56fe5780b8dca9705e0c22032a83828860a21235', $lTime - 100);
|
|
|
|
BackRestTestCommon_Execute('cp ' . BackRestTestCommon_DataPathGet() . '/pg_control ' .
|
|
|
|
BackRestTestCommon_DbCommonPathGet() . '/global/pg_control');
|
|
|
|
utime($lTime - 100, $lTime - 100, BackRestTestCommon_DbCommonPathGet() . '/global/pg_control')
|
|
|
|
or confess &log(ERROR, "unable to set time");
|
|
|
|
$oManifest{'base:file'}{'global/pg_control'}{'size'} = 8192;
|
|
|
|
|
2014-10-19 23:30:16 +03:00
|
|
|
# Create tablespace path
|
|
|
|
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base', 'pg_tblspc');
|
2014-10-18 20:25:20 +03:00
|
|
|
|
2014-10-16 02:11:09 +03:00
|
|
|
# Create db config
|
2014-12-24 01:52:38 +02:00
|
|
|
BackRestTestCommon_ConfigCreate('db', # local
|
|
|
|
$bRemote ? BACKUP : undef, # remote
|
|
|
|
$bCompress, # compress
|
2015-03-01 03:31:56 +02:00
|
|
|
true, # checksum
|
2014-12-24 01:52:38 +02:00
|
|
|
$bRemote ? undef : $bHardlink, # hardlink
|
2014-12-31 21:59:33 +02:00
|
|
|
$iThreadMax); # thread-max
|
2014-10-16 02:11:09 +03:00
|
|
|
|
|
|
|
# Create backup config
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
2014-12-24 01:52:38 +02:00
|
|
|
BackRestTestCommon_ConfigCreate('backup', # local
|
2014-12-31 21:59:33 +02:00
|
|
|
DB, # remote
|
2014-12-24 01:52:38 +02:00
|
|
|
$bCompress, # compress
|
2015-03-01 03:31:56 +02:00
|
|
|
true, # checksum
|
2014-12-24 01:52:38 +02:00
|
|
|
$bHardlink, # hardlink
|
2014-12-31 21:59:33 +02:00
|
|
|
$iThreadMax); # thread-max
|
2014-10-16 02:11:09 +03:00
|
|
|
}
|
|
|
|
|
2014-12-31 21:59:33 +02:00
|
|
|
# Full backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-18 20:25:20 +03:00
|
|
|
my $strType = 'full';
|
|
|
|
|
2014-12-21 17:11:17 +02:00
|
|
|
BackRestTestBackup_ManifestLinkCreate(\%oManifest, 'base', 'link-test', '/test');
|
|
|
|
BackRestTestBackup_ManifestPathCreate(\%oManifest, 'base', 'path-test');
|
|
|
|
|
2015-05-07 02:24:34 +02:00
|
|
|
my $strFullBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
undef, undef, undef, undef, '--manifest-save-threshold=3');
|
2014-12-19 19:49:56 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Backup Info
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
BackRestTestBackup_Info($strStanza, undef, false);
|
|
|
|
BackRestTestBackup_Info($strStanza, INFO_OUTPUT_JSON, false);
|
|
|
|
|
2015-01-22 01:37:49 +02:00
|
|
|
# Resume Full Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = 'full';
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
my $strTmpPath = BackRestTestCommon_RepoPathGet() . "/temp/${strStanza}.tmp";
|
2015-01-22 01:37:49 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_PathMove(BackRestTestCommon_RepoPathGet() . "/backup/${strStanza}/${strFullBackup}",
|
2015-01-22 01:37:49 +02:00
|
|
|
$strTmpPath, $bRemote);
|
|
|
|
|
2015-05-07 02:24:34 +02:00
|
|
|
my $oMungeManifest = BackRestTestCommon_manifestLoad("$strTmpPath/backup.manifest", $bRemote);
|
|
|
|
$oMungeManifest->remove('base:file', 'PG_VERSION', 'checksum');
|
|
|
|
BackRestTestCommon_manifestSave("$strTmpPath/backup.manifest", $oMungeManifest, $bRemote);
|
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strFullBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'resume', TEST_BACKUP_RESUME);
|
2015-01-22 01:37:49 +02:00
|
|
|
|
2015-03-23 23:17:43 +02:00
|
|
|
# Restore - tests various mode, extra files/paths, missing files/paths
|
2014-12-31 21:59:33 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2015-01-23 02:04:55 +02:00
|
|
|
my $bDelta = true;
|
|
|
|
my $bForce = false;
|
2014-12-21 17:11:17 +02:00
|
|
|
|
2014-12-31 21:59:33 +02:00
|
|
|
# Create a path and file that are not in the manifest
|
2014-12-19 19:49:56 +02:00
|
|
|
BackRestTestBackup_PathCreate(\%oManifest, 'base', 'deleteme');
|
|
|
|
BackRestTestBackup_FileCreate(\%oManifest, 'base', 'deleteme/deleteme.txt', 'DELETEME');
|
2014-12-31 21:59:33 +02:00
|
|
|
|
|
|
|
# Change path mode
|
2014-12-21 17:11:17 +02:00
|
|
|
BackRestTestBackup_PathMode(\%oManifest, 'base', 'base', '0777');
|
|
|
|
|
2014-12-31 21:59:33 +02:00
|
|
|
# Change an existing link to the wrong directory
|
2014-12-21 17:11:17 +02:00
|
|
|
BackRestTestBackup_FileRemove(\%oManifest, 'base', 'link-test');
|
|
|
|
BackRestTestBackup_LinkCreate(\%oManifest, 'base', 'link-test', '/wrong');
|
|
|
|
|
2014-12-31 21:59:33 +02:00
|
|
|
# Remove an path
|
2014-12-21 17:11:17 +02:00
|
|
|
BackRestTestBackup_PathRemove(\%oManifest, 'base', 'path-test');
|
2014-12-19 19:49:56 +02:00
|
|
|
|
2014-12-31 21:59:33 +02:00
|
|
|
# Remove a file
|
2014-12-22 18:24:32 +02:00
|
|
|
BackRestTestBackup_FileRemove(\%oManifest, 'base', 'PG_VERSION');
|
2015-01-23 03:55:16 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, \%oManifest, undef, $bDelta, $bForce,
|
2015-01-26 21:59:58 +02:00
|
|
|
undef, undef, undef, undef, undef, undef,
|
2015-01-23 02:04:55 +02:00
|
|
|
'add and delete files');
|
2014-10-18 20:25:20 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Various broken info tests
|
2014-12-31 21:59:33 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-18 20:25:20 +03:00
|
|
|
$strType = 'incr';
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup);
|
2014-10-18 20:25:20 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strInfoFile = BackRestTestCommon_RepoPathGet . "/backup/${strStanza}/backup.info";
|
|
|
|
my %oInfo;
|
|
|
|
BackRestTestCommon_iniLoad($strInfoFile, \%oInfo, $bRemote);
|
|
|
|
|
|
|
|
# Break the database version
|
|
|
|
my $strDbVersion = $oInfo{'db'}{&MANIFEST_KEY_DB_VERSION};
|
|
|
|
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_DB_VERSION} = '8.0';
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
|
|
|
|
|
|
|
my $strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'invalid database version', undef, undef, ERROR_BACKUP_MISMATCH);
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_DB_VERSION} = $strDbVersion;
|
|
|
|
|
|
|
|
# Break the database system id
|
|
|
|
my $ullDbSysId = $oInfo{'db'}{&MANIFEST_KEY_SYSTEM_ID};
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_SYSTEM_ID} = 6999999999999999999;
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
|
|
|
|
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'invalid system id', undef, undef, ERROR_BACKUP_MISMATCH);
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_SYSTEM_ID} = $ullDbSysId;
|
|
|
|
|
|
|
|
# Break the control version
|
|
|
|
my $iControlVersion = $oInfo{'db'}{&MANIFEST_KEY_CONTROL};
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_CONTROL} = 842;
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
|
|
|
|
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'invalid control version', undef, undef, ERROR_BACKUP_MISMATCH);
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_CONTROL} = $iControlVersion;
|
|
|
|
|
|
|
|
# Break the catalog version
|
|
|
|
my $iCatalogVersion = $oInfo{'db'}{&MANIFEST_KEY_CATALOG};
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_CATALOG} = 197208141;
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
|
|
|
|
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'invalid catalog version', undef, undef, ERROR_BACKUP_MISMATCH);
|
|
|
|
|
|
|
|
# Fix up info file for next test
|
|
|
|
$oInfo{db}{&MANIFEST_KEY_CATALOG} = $iCatalogVersion;
|
|
|
|
BackRestTestCommon_iniSave($strInfoFile, \%oInfo, $bRemote, true);
|
|
|
|
|
|
|
|
# Incr backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = 'incr';
|
|
|
|
|
2015-01-23 03:11:33 +02:00
|
|
|
# Add tablespace 1
|
|
|
|
BackRestTestBackup_ManifestTablespaceCreate(\%oManifest, 1);
|
2014-10-19 18:46:01 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace/1", 'tablespace1.txt', 'TBLSPC1',
|
2015-03-01 03:31:56 +02:00
|
|
|
'd85de07d6421d90aa9191c11c889bfde43680f0f', $lTime);
|
2015-05-07 02:24:34 +02:00
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, "base", 'badchecksum.txt', 'BADCHECKSUM',
|
|
|
|
'f927212cd08d11a42a666b2f04235398e9ceeb51', $lTime);
|
2015-01-23 02:04:55 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'add tablespace 1');
|
2015-01-23 02:04:55 +02:00
|
|
|
|
2015-01-22 17:54:02 +02:00
|
|
|
# Resume Incr Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = 'incr';
|
|
|
|
|
2015-01-24 01:28:39 +02:00
|
|
|
# Move database from backup to temp
|
2015-03-12 18:15:19 +02:00
|
|
|
$strTmpPath = BackRestTestCommon_RepoPathGet() . "/temp/${strStanza}.tmp";
|
2015-01-22 17:54:02 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_PathMove(BackRestTestCommon_RepoPathGet() . "/backup/${strStanza}/${strBackup}",
|
2015-01-22 17:54:02 +02:00
|
|
|
$strTmpPath, $bRemote);
|
|
|
|
|
2015-05-07 02:24:34 +02:00
|
|
|
$oMungeManifest = BackRestTestCommon_manifestLoad("$strTmpPath/backup.manifest", $bRemote);
|
|
|
|
$oMungeManifest->set('base:file', 'badchecksum.txt', 'checksum', 'bogus');
|
|
|
|
BackRestTestCommon_manifestSave("$strTmpPath/backup.manifest", $oMungeManifest, $bRemote);
|
|
|
|
|
2015-01-24 01:28:39 +02:00
|
|
|
# Add tablespace 2
|
|
|
|
BackRestTestBackup_ManifestTablespaceCreate(\%oManifest, 2);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace/2", 'tablespace2.txt', 'TBLSPC2',
|
2015-03-01 03:31:56 +02:00
|
|
|
'dc7f76e43c46101b47acc55ae4d593a9e6983578', $lTime);
|
2015-01-24 01:28:39 +02:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'resume and add tablespace 2', TEST_BACKUP_RESUME);
|
2015-01-22 17:54:02 +02:00
|
|
|
|
|
|
|
# Resume Diff Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = 'diff';
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
$strTmpPath = BackRestTestCommon_RepoPathGet() . "/temp/${strStanza}.tmp";
|
2015-01-22 17:54:02 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_PathMove(BackRestTestCommon_RepoPathGet() . "/backup/${strStanza}/${strBackup}",
|
2015-01-22 17:54:02 +02:00
|
|
|
$strTmpPath, $bRemote);
|
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
2015-03-04 04:21:07 +02:00
|
|
|
'cannot resume - new diff', TEST_BACKUP_NORESUME);
|
2015-01-22 17:54:02 +02:00
|
|
|
|
2015-05-07 18:29:30 +02:00
|
|
|
# Resume Diff Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = 'diff';
|
|
|
|
|
|
|
|
$strTmpPath = BackRestTestCommon_RepoPathGet() . "/temp/${strStanza}.tmp";
|
|
|
|
|
|
|
|
BackRestTestCommon_PathMove(BackRestTestCommon_RepoPathGet() . "/backup/${strStanza}/${strBackup}",
|
|
|
|
$strTmpPath, $bRemote);
|
|
|
|
|
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'cannot resume - disabled', TEST_BACKUP_NORESUME, undef, undef,
|
|
|
|
'--no-resume');
|
|
|
|
|
2015-05-09 00:34:27 +02:00
|
|
|
# Restore
|
2015-01-23 03:11:33 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$bDelta = false;
|
|
|
|
|
2015-03-04 04:21:07 +02:00
|
|
|
# Fail on used path
|
2015-01-28 23:25:38 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, $strBackup, $strStanza, $bRemote, \%oManifest, undef, $bDelta, $bForce,
|
2015-01-26 21:59:58 +02:00
|
|
|
undef, undef, undef, undef, undef, undef,
|
2015-01-24 01:28:39 +02:00
|
|
|
'fail on used path', ERROR_RESTORE_PATH_NOT_EMPTY);
|
2015-03-04 04:21:07 +02:00
|
|
|
# Fail on undef format
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestBackup_ManifestMunge($oFile, $bRemote, $strBackup, INI_SECTION_BACKREST, INI_KEY_FORMAT, undef, undef);
|
2015-03-04 04:21:07 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_Restore($oFile, $strBackup, $strStanza, $bRemote, \%oManifest, undef, $bDelta, $bForce,
|
|
|
|
undef, undef, undef, undef, undef, undef,
|
|
|
|
'fail on undef format', ERROR_FORMAT);
|
|
|
|
|
|
|
|
# Fail on mismatch format
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestBackup_ManifestMunge($oFile, $bRemote, $strBackup, INI_SECTION_BACKREST, INI_KEY_FORMAT, undef, 0);
|
2015-03-04 04:21:07 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_Restore($oFile, $strBackup, $strStanza, $bRemote, \%oManifest, undef, $bDelta, $bForce,
|
|
|
|
undef, undef, undef, undef, undef, undef,
|
|
|
|
'fail on mismatch format', ERROR_FORMAT);
|
|
|
|
|
2015-06-22 19:11:07 +02:00
|
|
|
BackRestTestBackup_ManifestMunge($oFile, $bRemote, $strBackup, INI_SECTION_BACKREST, INI_KEY_FORMAT, undef,
|
|
|
|
BACKREST_FORMAT);
|
2015-01-24 01:28:39 +02:00
|
|
|
|
2015-01-23 03:11:33 +02:00
|
|
|
# Remap the base path
|
|
|
|
my %oRemapHash;
|
|
|
|
$oRemapHash{base} = BackRestTestCommon_DbCommonPathGet(2);
|
2015-01-23 03:55:16 +02:00
|
|
|
$oRemapHash{1} = BackRestTestCommon_DbTablespacePathGet(1, 2);
|
2015-01-24 01:28:39 +02:00
|
|
|
$oRemapHash{2} = BackRestTestCommon_DbTablespacePathGet(2, 2);
|
2015-01-23 03:11:33 +02:00
|
|
|
|
2015-01-28 23:25:38 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, $strBackup, $strStanza, $bRemote, \%oManifest, \%oRemapHash, $bDelta, $bForce,
|
2015-01-26 21:59:58 +02:00
|
|
|
undef, undef, undef, undef, undef, undef,
|
2015-01-24 01:28:39 +02:00
|
|
|
'remap all paths');
|
2015-01-23 03:11:33 +02:00
|
|
|
|
2015-01-22 17:54:02 +02:00
|
|
|
# Incr Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-19 18:46:01 +03:00
|
|
|
$strType = 'incr';
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
2014-10-19 18:46:01 +03:00
|
|
|
|
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base2.txt', 'BASE2',
|
2015-03-01 03:31:56 +02:00
|
|
|
'09b5e31766be1dba1ec27de82f975c1b6eea2a92', $lTime);
|
2014-10-19 18:46:01 +03:00
|
|
|
|
2015-01-24 18:05:26 +02:00
|
|
|
BackRestTestBackup_ManifestTablespaceDrop(\%oManifest, 1, 2);
|
2014-10-20 00:41:11 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace/2", 'tablespace2b.txt', 'TBLSPC2B',
|
2015-03-01 03:31:56 +02:00
|
|
|
'e324463005236d83e6e54795dbddd20a74533bf3', $lTime);
|
2015-01-24 18:05:26 +02:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest,
|
|
|
|
'add files and remove tablespace 2');
|
2014-10-20 00:41:11 +03:00
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
# Incr Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-20 00:41:11 +03:00
|
|
|
$strType = 'incr';
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
2014-10-20 00:41:11 +03:00
|
|
|
|
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base1.txt', 'BASEUPDT',
|
2015-03-01 03:31:56 +02:00
|
|
|
'9a53d532e27785e681766c98516a5e93f096a501', $lTime);
|
2014-10-20 00:41:11 +03:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest, 'update files');
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
# Diff Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-20 18:44:36 +03:00
|
|
|
$strType = 'diff';
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup, true);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest, 'no updates');
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
# Incr Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-20 18:44:36 +03:00
|
|
|
$strType = 'incr';
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest, $strBackup);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "remove files - but won't affect manifest",
|
|
|
|
true, true, 1);
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_FileRemove(\%oManifest, 'base', 'base/base1.txt');
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupEnd($strType, $strStanza, $oFile, $bRemote, undef, \%oManifest, true);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
# Diff Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-20 18:44:36 +03:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup, true);
|
|
|
|
|
|
|
|
$strType = 'diff';
|
|
|
|
|
2014-12-21 17:11:17 +02:00
|
|
|
BackRestTestBackup_ManifestFileRemove(\%oManifest, 'base', 'base/base1.txt');
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestBackup_ManifestFileRemove(\%oManifest, "tablespace/2", 'tablespace2b.txt', true);
|
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace/2", 'tablespace2c.txt', 'TBLSPC2C',
|
2015-03-01 03:31:56 +02:00
|
|
|
'ad7df329ab97a1e7d35f1ff0351c079319121836', $lTime);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "remove files during backup", true, true, 1);
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, "tablespace/2", 'tablespace2c.txt', 'TBLSPCBIGGER',
|
2015-03-02 05:43:32 +02:00
|
|
|
'dfcb8679956b734706cf87259d50c88f83e80e66', $lTime);
|
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_ManifestFileRemove(\%oManifest, 'base', 'base/base2.txt', true);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupEnd($strType, $strStanza, $oFile, $bRemote, undef, \%oManifest, true);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
# Full Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = 'full';
|
2014-10-20 18:44:36 +03:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest);
|
|
|
|
|
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base1.txt', 'BASEUPDT2',
|
2015-03-01 03:31:56 +02:00
|
|
|
'7579ada0808d7f98087a0a586d0df9de009cdc33', $lTime);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strFullBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-23 00:43:19 +02:00
|
|
|
# Diff Backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2014-10-20 18:44:36 +03:00
|
|
|
$strType = 'diff';
|
2015-01-23 00:43:19 +02:00
|
|
|
BackRestTestBackup_ManifestReference(\%oManifest, $strFullBackup);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
|
|
|
BackRestTestBackup_ManifestFileCreate(\%oManifest, 'base', 'base/base2.txt', 'BASE2UPDT',
|
2015-03-01 03:31:56 +02:00
|
|
|
'cafac3c59553f2cfde41ce2e62e7662295f108c0', $lTime);
|
2014-10-20 18:44:36 +03:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
$strBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, $bRemote, $oFile, \%oManifest, 'add files');
|
2015-05-09 00:34:27 +02:00
|
|
|
|
|
|
|
# Restore
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$bDelta = true;
|
|
|
|
|
|
|
|
BackRestTestBackup_Restore($oFile, $strBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
|
|
|
undef, undef, undef, undef, undef, undef,
|
|
|
|
'no tablespace remap', undef, '--no-tablespace', false);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Backup Info
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
BackRestTestCommon_Execute('mkdir ' . BackRestTestCommon_RepoPathGet . '/backup/db_empty', $bRemote);
|
|
|
|
|
|
|
|
BackRestTestBackup_Info(undef, undef, false);
|
|
|
|
BackRestTestBackup_Info(undef, INFO_OUTPUT_JSON, false);
|
|
|
|
BackRestTestBackup_Info('bogus', undef, false);
|
|
|
|
BackRestTestBackup_Info('bogus', INFO_OUTPUT_JSON, false);
|
2014-10-16 02:11:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
2015-01-30 21:54:08 +02:00
|
|
|
BackRestTestBackup_Drop(true);
|
2014-10-16 02:11:09 +03:00
|
|
|
}
|
|
|
|
}
|
2014-10-14 22:44:50 +03:00
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test full
|
2014-10-14 22:44:50 +03:00
|
|
|
#
|
2014-12-18 16:58:07 +02:00
|
|
|
# Check the entire backup mechanism using actual clusters. Only the archive and start/stop mechanisms need to be tested since
|
|
|
|
# everything else was tested in the backup test.
|
2014-07-16 05:32:41 +03:00
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
2014-06-28 21:32:34 +03:00
|
|
|
if ($strTest eq 'all' || $strTest eq 'full')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
2014-07-16 05:32:41 +03:00
|
|
|
$bCreate = true;
|
2014-06-28 21:32:34 +03:00
|
|
|
|
|
|
|
&log(INFO, "Test Full Backup\n");
|
|
|
|
|
2014-06-29 17:53:39 +03:00
|
|
|
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
2014-07-13 02:03:39 +03:00
|
|
|
{
|
2014-12-18 16:58:07 +02:00
|
|
|
for (my $bArchiveAsync = false; $bArchiveAsync <= true; $bArchiveAsync++)
|
2015-03-01 23:42:27 +02:00
|
|
|
{
|
|
|
|
for (my $bCompress = false; $bCompress <= true; $bCompress++)
|
2014-06-28 21:32:34 +03:00
|
|
|
{
|
2014-12-18 16:58:07 +02:00
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
2015-03-01 23:42:27 +02:00
|
|
|
"rmt ${bRemote}, arc_async ${bArchiveAsync}, cmp ${bCompress}")) {next}
|
2014-12-18 16:58:07 +02:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
# Create the file object
|
|
|
|
my $oFile = new BackRest::File
|
|
|
|
(
|
|
|
|
$strStanza,
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_RepoPathGet(),
|
2015-01-27 18:44:23 +02:00
|
|
|
$bRemote ? 'backup' : undef,
|
2015-03-03 03:36:12 +02:00
|
|
|
$bRemote ? $oRemote : $oLocal
|
2015-01-27 18:44:23 +02:00
|
|
|
);
|
|
|
|
|
2014-12-18 16:58:07 +02:00
|
|
|
# Create the test directory
|
|
|
|
if ($bCreate)
|
2014-06-28 21:32:34 +03:00
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
BackRestTestBackup_Create($bRemote, false);
|
2014-12-18 16:58:07 +02:00
|
|
|
}
|
2014-06-28 21:32:34 +03:00
|
|
|
|
2014-12-18 16:58:07 +02:00
|
|
|
# Create db config
|
|
|
|
BackRestTestCommon_ConfigCreate('db', # local
|
2014-12-24 01:52:38 +02:00
|
|
|
$bRemote ? BACKUP : undef, # remote
|
2015-01-28 23:25:38 +02:00
|
|
|
$bCompress, # compress
|
2015-03-01 03:31:56 +02:00
|
|
|
undef, # checksum
|
2015-05-22 20:49:14 +02:00
|
|
|
$bRemote ? undef : false, # hardlink
|
2014-12-24 01:52:38 +02:00
|
|
|
$iThreadMax, # thread-max
|
2014-12-18 16:58:07 +02:00
|
|
|
$bArchiveAsync, # archive-async
|
|
|
|
undef); # compress-async
|
2014-06-28 21:32:34 +03:00
|
|
|
|
2014-12-18 16:58:07 +02:00
|
|
|
# Create backup config
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
BackRestTestCommon_ConfigCreate('backup', # local
|
2014-12-24 01:52:38 +02:00
|
|
|
$bRemote ? DB : undef, # remote
|
2015-01-28 23:25:38 +02:00
|
|
|
$bCompress, # compress
|
2015-03-01 03:31:56 +02:00
|
|
|
undef, # checksum
|
2015-05-22 20:49:14 +02:00
|
|
|
false, # hardlink
|
2014-12-18 16:58:07 +02:00
|
|
|
$iThreadMax, # thread-max
|
|
|
|
undef, # archive-async
|
|
|
|
undef); # compress-async
|
|
|
|
}
|
2014-06-28 21:32:34 +03:00
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
# Create the cluster
|
|
|
|
if ($bCreate)
|
|
|
|
{
|
|
|
|
BackRestTestBackup_ClusterCreate();
|
|
|
|
$bCreate = false;
|
|
|
|
}
|
|
|
|
|
2015-01-31 20:48:09 +02:00
|
|
|
# Static backup parameters
|
2015-01-28 18:12:21 +02:00
|
|
|
my $bSynthetic = false;
|
2015-03-08 20:05:41 +02:00
|
|
|
my $fTestDelay = .1;
|
2015-01-31 20:48:09 +02:00
|
|
|
|
|
|
|
# Variable backup parameters
|
2015-01-27 18:44:23 +02:00
|
|
|
my $bDelta = true;
|
|
|
|
my $bForce = false;
|
2015-01-31 20:48:09 +02:00
|
|
|
my $strType = undef;
|
|
|
|
my $strTarget = undef;
|
|
|
|
my $bTargetExclusive = false;
|
|
|
|
my $bTargetResume = false;
|
|
|
|
my $strTargetTimeline = undef;
|
|
|
|
my $oRecoveryHashRef = undef;
|
|
|
|
my $strTestPoint = undef;
|
|
|
|
my $strComment = undef;
|
|
|
|
my $iExpectedExitStatus = undef;
|
2014-09-20 00:51:51 +03:00
|
|
|
|
2015-01-28 18:12:21 +02:00
|
|
|
# Restore test string
|
|
|
|
my $strDefaultMessage = 'default';
|
2015-01-28 05:59:59 +02:00
|
|
|
my $strFullMessage = 'full';
|
2015-01-28 18:12:21 +02:00
|
|
|
my $strIncrMessage = 'incr';
|
2015-01-28 05:59:59 +02:00
|
|
|
my $strTimeMessage = 'time';
|
|
|
|
my $strXidMessage = 'xid';
|
|
|
|
my $strNameMessage = 'name';
|
2015-01-31 20:48:09 +02:00
|
|
|
my $strTimelineMessage = 'timeline3';
|
2014-08-14 16:40:20 +03:00
|
|
|
|
2015-01-27 18:44:23 +02:00
|
|
|
# Full backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2015-01-28 18:12:21 +02:00
|
|
|
$strType = BACKUP_TYPE_FULL;
|
2015-01-31 20:48:09 +02:00
|
|
|
$strTestPoint = TEST_MANIFEST_BUILD;
|
2015-01-28 18:12:21 +02:00
|
|
|
|
2015-08-08 23:11:20 +02:00
|
|
|
# Create the table where test messages will be stored
|
2015-01-27 18:44:23 +02:00
|
|
|
BackRestTestBackup_PgExecute("create table test (message text not null)");
|
2015-01-28 05:59:59 +02:00
|
|
|
BackRestTestBackup_PgSwitchXlog();
|
2015-01-28 18:12:21 +02:00
|
|
|
BackRestTestBackup_PgExecute("insert into test values ('$strDefaultMessage')");
|
2014-06-29 17:53:39 +03:00
|
|
|
|
2015-08-08 23:11:20 +02:00
|
|
|
# Acquire the backup advisory lock so it looks like a backup is running
|
|
|
|
if (!BackRestTestBackup_PgSelectOne('select pg_try_advisory_lock(' . DB_BACKUP_ADVISORY_LOCK . ')'))
|
|
|
|
{
|
|
|
|
confess 'unable to acquire advisory lock for testing';
|
|
|
|
}
|
|
|
|
|
|
|
|
$strComment = 'fail on backup lock exists';
|
|
|
|
BackRestTestBackup_Backup($strType, $strStanza, $bRemote, $oFile, $strComment, undef, undef, ERROR_LOCK_ACQUIRE);
|
|
|
|
|
|
|
|
# Release the backup advisory lock so the next backup will succeed
|
|
|
|
if (!BackRestTestBackup_PgSelectOne('select pg_advisory_unlock(' . DB_BACKUP_ADVISORY_LOCK . ')'))
|
|
|
|
{
|
|
|
|
confess 'unable to acquire advisory lock for testing';
|
|
|
|
}
|
|
|
|
|
|
|
|
$strComment = 'update during backup';
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, $bSynthetic,
|
|
|
|
defined($strTestPoint), $fTestDelay);
|
2015-08-08 23:11:20 +02:00
|
|
|
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestCommon_ExecuteEnd($strTestPoint);
|
2015-01-28 18:12:21 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strFullMessage'", false);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strFullBackup = BackRestTestBackup_BackupEnd($strType, $strStanza, $oFile, $bRemote, undef, undef, $bSynthetic);
|
2014-08-10 22:02:14 +03:00
|
|
|
|
2015-01-31 03:16:21 +02:00
|
|
|
# Setup the time target
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strTimeMessage'", false);
|
|
|
|
BackRestTestBackup_PgSwitchXlog();
|
|
|
|
my $strTimeTarget = BackRestTestBackup_PgSelectOne("select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS.US TZ')");
|
|
|
|
&log(INFO, " time target is ${strTimeTarget}");
|
|
|
|
|
|
|
|
# Incr backup
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = BACKUP_TYPE_INCR;
|
2015-01-31 20:48:09 +02:00
|
|
|
$strTestPoint = TEST_MANIFEST_BUILD;
|
2015-01-31 03:16:21 +02:00
|
|
|
|
2015-05-09 00:34:27 +02:00
|
|
|
BackRestTestBackup_PgExecuteNoTrans("create tablespace ts1 location '" .
|
|
|
|
BackRestTestCommon_DbTablespacePathGet(1) . "'");
|
|
|
|
BackRestTestBackup_PgExecute("alter table test set tablespace ts1", true);
|
|
|
|
|
2015-01-31 03:16:21 +02:00
|
|
|
BackRestTestBackup_PgExecute("create table test_remove (id int)", false);
|
|
|
|
BackRestTestBackup_PgSwitchXlog();
|
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false);
|
|
|
|
BackRestTestBackup_PgSwitchXlog();
|
|
|
|
|
2015-08-08 23:11:20 +02:00
|
|
|
# Start a backup so the next backup has to restart it
|
|
|
|
if (BackRestTestCommon_DbVersion() >= 9.3)
|
|
|
|
{
|
|
|
|
BackRestTestBackup_PgSelectOne("select pg_start_backup('test backup that will be cancelled', true)");
|
|
|
|
}
|
|
|
|
|
|
|
|
# # Can't do this test yet because it puts errors in the Postgres log
|
|
|
|
# $strComment = 'fail on backup already running';
|
|
|
|
# BackRestTestBackup_Backup($strType, $strStanza, $bRemote, $oFile, $strComment, undef, undef, ERROR_DB_QUERY);
|
|
|
|
|
|
|
|
$strComment = 'update during backup';
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, $bSynthetic,
|
2015-08-08 23:11:20 +02:00
|
|
|
defined($strTestPoint), $fTestDelay, '--' . OPTION_STOP_AUTO);
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestCommon_ExecuteEnd($strTestPoint);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_PgExecute("drop table test_remove", false);
|
|
|
|
BackRestTestBackup_PgSwitchXlog();
|
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strIncrMessage'", false);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strIncrBackup = BackRestTestBackup_BackupEnd($strType, $strStanza, $oFile, $bRemote, undef, undef, $bSynthetic);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
# Setup the xid target
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strXidMessage'", false, false);
|
|
|
|
BackRestTestBackup_PgSwitchXlog();
|
|
|
|
my $strXidTarget = BackRestTestBackup_PgSelectOne("select txid_current()");
|
|
|
|
BackRestTestBackup_PgCommit();
|
|
|
|
&log(INFO, " xid target is ${strXidTarget}");
|
|
|
|
|
|
|
|
# Setup the name target
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strNameTarget = 'backrest';
|
|
|
|
|
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strNameMessage'", false, true);
|
|
|
|
BackRestTestBackup_PgSwitchXlog();
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
if (BackRestTestCommon_DbVersion() >= 9.1)
|
|
|
|
{
|
|
|
|
BackRestTestBackup_PgExecute("select pg_create_restore_point('${strNameTarget}')", false, false);
|
|
|
|
}
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
&log(INFO, " name target is ${strNameTarget}");
|
|
|
|
|
|
|
|
# Restore (type = default)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$bDelta = false;
|
|
|
|
$bForce = false;
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType = RECOVERY_TYPE_DEFAULT;
|
|
|
|
$strTarget = undef;
|
|
|
|
$bTargetExclusive = undef;
|
|
|
|
$bTargetResume = undef;
|
|
|
|
$strTargetTimeline = undef;
|
|
|
|
$oRecoveryHashRef = undef;
|
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
&log(INFO, " testing recovery type = ${strType}");
|
|
|
|
|
|
|
|
# Expect failure because postmaster.pid exists
|
2015-01-31 20:48:09 +02:00
|
|
|
$strComment = 'postmaster running';
|
|
|
|
$iExpectedExitStatus = ERROR_POSTMASTER_RUNNING;
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStop();
|
|
|
|
|
|
|
|
# Expect failure because db path is not empty
|
2015-01-31 20:48:09 +02:00
|
|
|
$strComment = 'path not empty';
|
|
|
|
$iExpectedExitStatus = ERROR_RESTORE_PATH_NOT_EMPTY;
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
# Drop and recreate db path
|
|
|
|
BackRestTestCommon_PathRemove(BackRestTestCommon_DbCommonPathGet());
|
|
|
|
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet());
|
2015-05-09 00:34:27 +02:00
|
|
|
BackRestTestCommon_PathRemove(BackRestTestCommon_DbTablespacePathGet(1));
|
|
|
|
BackRestTestCommon_PathCreate(BackRestTestCommon_DbTablespacePathGet(1));
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
# Now the restore should work
|
2015-01-31 20:48:09 +02:00
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStart();
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestBackup_PgSelectOneTest('select message from test', $strNameMessage);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
# Restore (restore type = xid, inclusive)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$bDelta = false;
|
|
|
|
$bForce = true;
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType = RECOVERY_TYPE_XID;
|
|
|
|
$strTarget = $strXidTarget;
|
|
|
|
$bTargetExclusive = undef;
|
2015-08-06 22:36:55 +02:00
|
|
|
$bTargetResume = BackRestTestCommon_DbVersion() >= 9.1 && BackRestTestCommon_DbVersion() < 9.5 ? true : undef;
|
2015-01-31 20:48:09 +02:00
|
|
|
$strTargetTimeline = undef;
|
|
|
|
$oRecoveryHashRef = undef;
|
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
&log(INFO, " testing recovery type = ${strType}");
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStop();
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, $strIncrBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-03-04 06:15:40 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
2015-05-09 00:34:27 +02:00
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus, '--no-tablespace', false);
|
2015-03-04 06:15:40 +02:00
|
|
|
|
|
|
|
# Save recovery file to test so we can use it in the next test
|
|
|
|
$oFile->copy(PATH_ABSOLUTE, BackRestTestCommon_DbCommonPathGet() . '/recovery.conf',
|
|
|
|
PATH_ABSOLUTE, BackRestTestCommon_TestPathGet() . '/recovery.conf');
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStart();
|
|
|
|
BackRestTestBackup_PgSelectOneTest('select message from test', $strXidMessage);
|
|
|
|
|
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strTimelineMessage'", false);
|
|
|
|
|
|
|
|
# Restore (restore type = preserve, inclusive)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$bDelta = true;
|
|
|
|
$bForce = false;
|
|
|
|
$strType = RECOVERY_TYPE_PRESERVE;
|
|
|
|
$strTarget = undef;
|
|
|
|
$bTargetExclusive = undef;
|
|
|
|
$bTargetResume = undef;
|
|
|
|
$strTargetTimeline = undef;
|
|
|
|
$oRecoveryHashRef = undef;
|
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
|
|
|
|
|
|
|
&log(INFO, " testing recovery type = ${strType}");
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStop();
|
|
|
|
|
|
|
|
# Restore recovery file that was save in last test
|
|
|
|
$oFile->move(PATH_ABSOLUTE, BackRestTestCommon_TestPathGet() . '/recovery.conf',
|
|
|
|
PATH_ABSOLUTE, BackRestTestCommon_DbCommonPathGet() . '/recovery.conf');
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStart();
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestBackup_PgSelectOneTest('select message from test', $strXidMessage);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestBackup_PgExecute("update test set message = '$strTimelineMessage'", false);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
# Restore (restore type = time, inclusive) - there is no exclusive time test because I can't find a way to find the
|
|
|
|
# exact commit time of a transaction.
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$bDelta = true;
|
|
|
|
$bForce = false;
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType = RECOVERY_TYPE_TIME;
|
|
|
|
$strTarget = $strTimeTarget;
|
|
|
|
$bTargetExclusive = undef;
|
|
|
|
$bTargetResume = undef;
|
|
|
|
$strTargetTimeline = undef;
|
|
|
|
$oRecoveryHashRef = undef;
|
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
&log(INFO, " testing recovery type = ${strType}");
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStop();
|
|
|
|
|
|
|
|
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStart();
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestBackup_PgSelectOneTest('select message from test', $strTimeMessage);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
# Restore (restore type = xid, exclusive)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$bDelta = true;
|
|
|
|
$bForce = false;
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType = RECOVERY_TYPE_XID;
|
|
|
|
$strTarget = $strXidTarget;
|
|
|
|
$bTargetExclusive = true;
|
|
|
|
$bTargetResume = undef;
|
|
|
|
$strTargetTimeline = undef;
|
|
|
|
$oRecoveryHashRef = undef;
|
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
&log(INFO, " testing recovery type = ${strType}");
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStop();
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, $strIncrBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-01-31 20:48:09 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStart();
|
2015-01-31 20:48:09 +02:00
|
|
|
BackRestTestBackup_PgSelectOneTest('select message from test', $strIncrMessage);
|
2015-01-31 03:16:21 +02:00
|
|
|
|
|
|
|
# Restore (restore type = name)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2015-04-01 21:58:33 +02:00
|
|
|
if (BackRestTestCommon_DbVersion() >= 9.1)
|
|
|
|
{
|
|
|
|
$bDelta = true;
|
|
|
|
$bForce = true;
|
|
|
|
$strType = RECOVERY_TYPE_NAME;
|
|
|
|
$strTarget = $strNameTarget;
|
|
|
|
$bTargetExclusive = undef;
|
|
|
|
$bTargetResume = undef;
|
|
|
|
$strTargetTimeline = undef;
|
|
|
|
$oRecoveryHashRef = undef;
|
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
|
|
|
|
|
|
|
&log(INFO, " testing recovery type = ${strType}");
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStop();
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-04-01 21:58:33 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStart();
|
|
|
|
BackRestTestBackup_PgSelectOneTest('select message from test', $strNameMessage);
|
|
|
|
}
|
2015-01-31 03:16:21 +02:00
|
|
|
|
2015-01-31 20:48:09 +02:00
|
|
|
# Restore (restore type = default, timeline = 3)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2015-04-03 15:56:03 +02:00
|
|
|
if (BackRestTestCommon_DbVersion() >= 8.4)
|
2015-04-01 21:58:33 +02:00
|
|
|
{
|
|
|
|
$bDelta = true;
|
|
|
|
$bForce = false;
|
|
|
|
$strType = RECOVERY_TYPE_DEFAULT;
|
|
|
|
$strTarget = undef;
|
|
|
|
$bTargetExclusive = undef;
|
|
|
|
$bTargetResume = undef;
|
|
|
|
$strTargetTimeline = 3;
|
|
|
|
$oRecoveryHashRef = BackRestTestCommon_DbVersion() >= 9.0 ? {'standby-mode' => 'on'} : undef;
|
|
|
|
$strComment = undef;
|
|
|
|
$iExpectedExitStatus = undef;
|
|
|
|
|
|
|
|
&log(INFO, " testing recovery type = ${strType}");
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStop();
|
|
|
|
|
2015-04-19 23:28:19 +02:00
|
|
|
BackRestTestBackup_Restore($oFile, $strIncrBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
|
2015-04-01 21:58:33 +02:00
|
|
|
$strType, $strTarget, $bTargetExclusive, $bTargetResume, $strTargetTimeline,
|
|
|
|
$oRecoveryHashRef, $strComment, $iExpectedExitStatus);
|
|
|
|
|
|
|
|
BackRestTestBackup_ClusterStart(undef, undef, true);
|
|
|
|
BackRestTestBackup_PgSelectOneTest('select message from test', $strTimelineMessage, 120);
|
|
|
|
}
|
2015-01-27 18:44:23 +02:00
|
|
|
|
2014-12-18 16:58:07 +02:00
|
|
|
$bCreate = true;
|
2014-06-28 21:32:34 +03:00
|
|
|
}
|
2014-07-13 02:03:39 +03:00
|
|
|
}
|
2015-01-28 23:25:38 +02:00
|
|
|
}
|
2014-06-22 18:56:01 +03:00
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
2015-01-30 21:54:08 +02:00
|
|
|
BackRestTestBackup_Drop(true);
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
|
|
|
}
|
2015-01-01 02:03:03 +02:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test collision
|
|
|
|
#
|
|
|
|
# See if it is possible for a table to be written to, have stop backup run, and be written to again all in the same second.
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'collision')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
my $iRunMax = 1000;
|
|
|
|
|
|
|
|
&log(INFO, "Test Backup Collision\n");
|
|
|
|
|
|
|
|
# Create the file object
|
|
|
|
my $oFile = (BackRest::File->new
|
|
|
|
(
|
|
|
|
$strStanza,
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_RepoPathGet(),
|
2015-03-26 23:42:45 +02:00
|
|
|
NONE,
|
|
|
|
$oLocal
|
2015-01-01 02:03:03 +02:00
|
|
|
))->clone();
|
|
|
|
|
|
|
|
# Create the test database
|
|
|
|
BackRestTestBackup_Create(false);
|
|
|
|
|
|
|
|
# Create the config file
|
|
|
|
BackRestTestCommon_ConfigCreate('db', # local
|
|
|
|
undef, # remote
|
|
|
|
false, # compress
|
|
|
|
false, # checksum
|
|
|
|
false, # hardlink
|
|
|
|
$iThreadMax, # thread-max
|
|
|
|
false, # archive-async
|
|
|
|
undef); # compress-async
|
|
|
|
|
|
|
|
# Create the test table
|
|
|
|
BackRestTestBackup_PgExecute("create table test_collision (id int)");
|
|
|
|
|
|
|
|
# Construct filename to test
|
|
|
|
my $strFile = BackRestTestCommon_DbCommonPathGet() . "/base";
|
|
|
|
|
2015-01-02 21:18:07 +02:00
|
|
|
# Get the oid of the postgres db
|
2015-01-01 02:03:03 +02:00
|
|
|
my $strSql = "select oid from pg_database where datname = 'postgres'";
|
2015-08-06 06:00:30 +02:00
|
|
|
my $hStatement = BackRestTestBackup_PgHandleGet()->prepare($strSql);
|
2015-01-01 02:03:03 +02:00
|
|
|
|
|
|
|
$hStatement->execute() or
|
|
|
|
confess &log(ERROR, "Unable to execute: ${strSql}");
|
|
|
|
|
|
|
|
my @oyRow = $hStatement->fetchrow_array();
|
|
|
|
$strFile .= '/' . $oyRow[0];
|
|
|
|
|
|
|
|
$hStatement->finish();
|
|
|
|
|
|
|
|
# Get the oid of the new table so we can check the file on disk
|
|
|
|
$strSql = "select oid from pg_class where relname = 'test_collision'";
|
2015-08-06 06:00:30 +02:00
|
|
|
$hStatement = BackRestTestBackup_PgHandleGet()->prepare($strSql);
|
2015-01-01 02:03:03 +02:00
|
|
|
|
|
|
|
$hStatement->execute() or
|
|
|
|
confess &log(ERROR, "Unable to execute: ${strSql}");
|
|
|
|
|
2015-01-02 21:18:07 +02:00
|
|
|
@oyRow = $hStatement->fetchrow_array();
|
2015-01-01 02:03:03 +02:00
|
|
|
$strFile .= '/' . $oyRow[0];
|
|
|
|
|
|
|
|
&log(INFO, 'table filename = ' . $strFile);
|
|
|
|
|
|
|
|
$hStatement->finish();
|
|
|
|
|
|
|
|
BackRestTestBackup_PgExecute("select pg_start_backup('test');");
|
|
|
|
|
2015-01-02 21:18:07 +02:00
|
|
|
# File modified in the same second after the manifest is taken and file is copied
|
2015-01-01 02:03:03 +02:00
|
|
|
while ($iRun < $iRunMax)
|
|
|
|
{
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"mod after manifest")) {next}
|
|
|
|
|
|
|
|
my $strTestChecksum = $oFile->hash(PATH_DB_ABSOLUTE, $strFile);
|
|
|
|
|
|
|
|
# Insert a row and do a checkpoint
|
|
|
|
BackRestTestBackup_PgExecute("insert into test_collision values (1)", true);
|
|
|
|
|
|
|
|
# Stat the file to get size/modtime after the backup has started
|
|
|
|
my $strBeginChecksum = $oFile->hash(PATH_DB_ABSOLUTE, $strFile);
|
|
|
|
my $oStat = lstat($strFile);
|
|
|
|
my $lBeginSize = $oStat->size;
|
|
|
|
my $lBeginTime = $oStat->mtime;
|
|
|
|
|
|
|
|
# Sleep .5 seconds to give a reasonable amount of time for the file to be copied after the manifest was generated
|
2015-01-23 21:12:53 +02:00
|
|
|
# Sleep for a while to show there is a large window where this can happen
|
|
|
|
&log(INFO, 'time ' . gettimeofday());
|
2015-01-25 19:20:12 +02:00
|
|
|
hsleep(.5);
|
2015-01-23 21:12:53 +02:00
|
|
|
&log(INFO, 'time ' . gettimeofday());
|
2015-01-01 02:03:03 +02:00
|
|
|
|
|
|
|
# Insert another row
|
|
|
|
BackRestTestBackup_PgExecute("insert into test_collision values (1)");
|
|
|
|
|
|
|
|
# Stop backup, start a new backup
|
|
|
|
BackRestTestBackup_PgExecute("select pg_stop_backup();");
|
|
|
|
BackRestTestBackup_PgExecute("select pg_start_backup('test');");
|
|
|
|
|
|
|
|
# Stat the file to get size/modtime after the backup has restarted
|
|
|
|
my $strEndChecksum = $oFile->hash(PATH_DB_ABSOLUTE, $strFile);
|
|
|
|
$oStat = lstat($strFile);
|
|
|
|
my $lEndSize = $oStat->size;
|
|
|
|
my $lEndTime = $oStat->mtime;
|
|
|
|
|
|
|
|
# Error if the size/modtime are the same between the backups
|
|
|
|
&log(INFO, " begin size = ${lBeginSize}, time = ${lBeginTime}, hash ${strBeginChecksum} - " .
|
|
|
|
"end size = ${lEndSize}, time = ${lEndTime}, hash ${strEndChecksum} - test hash ${strTestChecksum}");
|
|
|
|
|
|
|
|
if ($lBeginSize == $lEndSize && $lBeginTime == $lEndTime &&
|
|
|
|
$strTestChecksum ne $strBeginChecksum && $strBeginChecksum ne $strEndChecksum)
|
|
|
|
{
|
|
|
|
&log(ERROR, "size and mod time are the same between backups");
|
|
|
|
$iRun = $iRunMax;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BackRestTestBackup_PgExecute("select pg_stop_backup();");
|
|
|
|
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
2015-01-30 21:54:08 +02:00
|
|
|
BackRestTestBackup_Drop(true);
|
2015-01-01 02:03:03 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 19:56:44 +02:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# rsync-collision
|
|
|
|
#
|
|
|
|
# See if it is possible for a table to be written to, have stop backup run, and be written to again all in the same second.
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'rsync-collision')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
my $iRunMax = 1000;
|
|
|
|
|
|
|
|
&log(INFO, "Test Rsync Collision\n");
|
|
|
|
|
|
|
|
# Create the file object
|
|
|
|
my $oFile = (BackRest::File->new
|
|
|
|
(
|
|
|
|
$strStanza,
|
2015-03-12 18:15:19 +02:00
|
|
|
BackRestTestCommon_RepoPathGet(),
|
2015-03-26 23:42:45 +02:00
|
|
|
NONE,
|
|
|
|
$oLocal
|
2015-01-03 19:56:44 +02:00
|
|
|
))->clone();
|
|
|
|
|
|
|
|
# Create the test database
|
|
|
|
BackRestTestBackup_Create(false, false);
|
|
|
|
|
|
|
|
# Create test paths
|
|
|
|
my $strPathRsync1 = BackRestTestCommon_TestPathGet() . "/rsync1";
|
|
|
|
my $strPathRsync2 = BackRestTestCommon_TestPathGet() . "/rsync2";
|
|
|
|
|
|
|
|
BackRestTestCommon_PathCreate($strPathRsync1);
|
|
|
|
BackRestTestCommon_PathCreate($strPathRsync2);
|
|
|
|
|
|
|
|
# Rsync command
|
|
|
|
my $strCommand = "rsync -vvrt ${strPathRsync1}/ ${strPathRsync2}";
|
|
|
|
|
|
|
|
# File modified in the same second after the manifest is taken and file is copied
|
|
|
|
while ($iRun < $iRunMax)
|
|
|
|
{
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
|
|
|
if (!BackRestTestCommon_Run(++$iRun,
|
|
|
|
"rsync test")) {next}
|
|
|
|
|
|
|
|
# Create test file
|
|
|
|
&log(INFO, "create test file");
|
|
|
|
BackRestTestCommon_FileCreate("${strPathRsync1}/test.txt", 'TEST1');
|
|
|
|
|
|
|
|
# Stat the file to get size/modtime after the backup has started
|
|
|
|
my $strBeginChecksum = $oFile->hash(PATH_DB_ABSOLUTE, "${strPathRsync1}/test.txt");
|
|
|
|
|
|
|
|
# Rsync
|
|
|
|
&log(INFO, "rsync 1st time");
|
|
|
|
BackRestTestCommon_Execute($strCommand, false, false, true);
|
|
|
|
|
2015-01-23 04:20:49 +02:00
|
|
|
# Sleep for a while to show there is a large window where this can happen
|
2015-01-23 21:12:53 +02:00
|
|
|
&log(INFO, 'time ' . gettimeofday());
|
2015-01-25 19:20:12 +02:00
|
|
|
hsleep(.5);
|
2015-01-23 21:12:53 +02:00
|
|
|
&log(INFO, 'time ' . gettimeofday());
|
2015-01-23 04:20:49 +02:00
|
|
|
|
2015-01-03 19:56:44 +02:00
|
|
|
# Modify the test file within the same second
|
|
|
|
&log(INFO, "modify test file");
|
|
|
|
BackRestTestCommon_FileCreate("${strPathRsync1}/test.txt", 'TEST2');
|
|
|
|
|
|
|
|
my $strEndChecksum = $oFile->hash(PATH_DB_ABSOLUTE, "${strPathRsync1}/test.txt");
|
|
|
|
|
|
|
|
# Rsync again
|
|
|
|
&log(INFO, "rsync 2nd time");
|
|
|
|
BackRestTestCommon_Execute($strCommand, false, false, true);
|
|
|
|
|
|
|
|
my $strTestChecksum = $oFile->hash(PATH_DB_ABSOLUTE, "${strPathRsync2}/test.txt");
|
|
|
|
|
|
|
|
# Error if checksums are not the same after rsync
|
|
|
|
&log(INFO, " begin hash ${strBeginChecksum} - end hash ${strEndChecksum} - test hash ${strTestChecksum}");
|
|
|
|
|
|
|
|
if ($strTestChecksum ne $strEndChecksum)
|
|
|
|
{
|
|
|
|
&log(ERROR, "end and test checksums are not the same");
|
|
|
|
$iRun = $iRunMax;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
2015-01-30 21:54:08 +02:00
|
|
|
BackRestTestBackup_Drop(true);
|
2015-01-03 19:56:44 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-22 17:30:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|