2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-06-20 00:55:00 +02:00
|
|
|
# Test All Commands on Mock Data
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-06-20 00:55:00 +02:00
|
|
|
package pgBackRestTest::Module::Mock::MockAllTest;
|
2017-05-12 22:43:04 +02:00
|
|
|
use parent 'pgBackRestTest::Env::HostEnvTest';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
2017-04-10 19:24:45 +02:00
|
|
|
use File::Basename qw(basename dirname);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-21 14:02:21 +02:00
|
|
|
use pgBackRest::Archive::Info;
|
2017-05-15 22:01:00 +02:00
|
|
|
use pgBackRest::Backup::Common;
|
|
|
|
use pgBackRest::Backup::Info;
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRest::DbVersion;
|
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::Wait;
|
|
|
|
use pgBackRest::Config::Config;
|
2017-04-03 16:42:55 +02:00
|
|
|
use pgBackRest::InfoCommon;
|
2017-01-30 20:59:00 +02:00
|
|
|
use pgBackRest::LibC qw(:checksum);
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRest::Manifest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRest::Version;
|
|
|
|
|
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::FileTest;
|
|
|
|
use pgBackRestTest::Common::RunTest;
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
2017-06-12 16:52:32 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostS3Test;
|
|
|
|
use pgBackRestTest::Env::HostEnvTest;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-01-30 20:59:00 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Build PostgreSQL pages for testing
|
|
|
|
####################################################################################################################################
|
|
|
|
sub pageBuild
|
|
|
|
{
|
|
|
|
my $tPageSource = shift;
|
|
|
|
my $iBlockNo = shift;
|
|
|
|
my $iWalId = shift;
|
|
|
|
my $iWalOffset = shift;
|
|
|
|
|
|
|
|
my $tPage = defined($iWalId) ? pack('I', $iWalId) . pack('I', $iWalOffset) . substr($tPageSource, 8) : $tPageSource;
|
|
|
|
my $iChecksum = pageChecksum($tPage, $iBlockNo, length($tPage));
|
|
|
|
|
|
|
|
return substr($tPage, 0, 8) . pack('S', $iChecksum) . substr($tPage, 10);
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bS3 (false, true)
|
|
|
|
{
|
|
|
|
foreach my $bRemote ($bS3 ? (true) : (false, true))
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-11-06 19:51:12 +02:00
|
|
|
my $bRepoEncrypt = $bS3 ? true : false;
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$self->begin("rmt ${bRemote}, s3 ${bS3}, enc ${bRepoEncrypt}")) {next}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create hosts, file object, and config
|
2017-06-12 16:52:32 +02:00
|
|
|
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3) = $self->setup(
|
2017-11-06 19:51:12 +02:00
|
|
|
true, $self->expect(), {bHostBackup => $bRemote, bCompress => false, bS3 => $bS3, bRepoEncrypt => $bRepoEncrypt});
|
2017-06-22 00:47:25 +02:00
|
|
|
|
|
|
|
# Reduce log level for many tests
|
2017-08-25 22:47:47 +02:00
|
|
|
my $strLogReduced = '--' . cfgOptionName(CFGOPT_LOG_LEVEL_CONSOLE) . '=' . lc(DETAIL);
|
2017-06-22 00:47:25 +02:00
|
|
|
|
|
|
|
# If S3 set process max to 2. This seems like the best place for parallel testing since it will help speed S3 processing
|
|
|
|
# without slowing down the other tests too much.
|
|
|
|
if ($bS3)
|
|
|
|
{
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_PROCESS_MAX) => 2}});
|
|
|
|
$oHostDbMaster->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_PROCESS_MAX) => 2}});
|
2017-06-22 00:47:25 +02:00
|
|
|
|
|
|
|
# Reduce log level to detail because parallel tests do not create deterministic logs
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_LOG_LEVEL_CONSOLE) => lc(WARN)}});
|
|
|
|
$oHostDbMaster->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_LOG_LEVEL_CONSOLE) => lc(WARN)}});
|
|
|
|
$strLogReduced = '--' . cfgOptionName(CFGOPT_LOG_LEVEL_CONSOLE) . '=' . lc(WARN);
|
2017-06-22 00:47:25 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Get base time
|
|
|
|
my $lTime = time() - 10000;
|
|
|
|
|
|
|
|
# Build the manifest
|
|
|
|
my %oManifest;
|
|
|
|
|
|
|
|
$oManifest{&INI_SECTION_BACKREST}{&INI_KEY_VERSION} = BACKREST_VERSION;
|
|
|
|
$oManifest{&INI_SECTION_BACKREST}{&INI_KEY_FORMAT} = BACKREST_FORMAT;
|
|
|
|
$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_BACKUP_STANDBY} = JSON::PP::false;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_CHECKSUM_PAGE} = JSON::PP::true;
|
2017-06-15 21:32:10 +02:00
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS} = JSON::PP::false;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_HARDLINK} = JSON::PP::false;
|
2016-12-23 15:22:59 +02:00
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_ONLINE} = JSON::PP::false;
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
if ($bRepoEncrypt)
|
|
|
|
{
|
|
|
|
$oManifest{&INI_SECTION_CIPHER}{&INI_KEY_CIPHER_PASS} = 'REPLACEME';
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_CATALOG} = 201409291;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_CONTROL} = 942;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_SYSTEM_ID} = 6353949018581704918;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_DB_VERSION} = PG_VERSION_94;
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_DB}{&MANIFEST_KEY_DB_ID} = 1;
|
|
|
|
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_TARGET}{&MANIFEST_TARGET_PGDATA}{&MANIFEST_SUBKEY_PATH} =
|
|
|
|
$oHostDbMaster->dbBasePath();
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_TARGET}{&MANIFEST_TARGET_PGDATA}{&MANIFEST_SUBKEY_TYPE} = MANIFEST_VALUE_PATH;
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_FILE_PGVERSION, PG_VERSION_94,
|
|
|
|
'184473f470864e067ee3a22e64b47b0a1c356f29', $lTime, undef, true);
|
|
|
|
|
|
|
|
# Load sample page
|
2017-06-09 23:51:41 +02:00
|
|
|
my $tBasePage = ${storageTest()->get($self->dataPath() . '/page.bin')};
|
2016-12-23 15:22:59 +02:00
|
|
|
my $iBasePageChecksum = 0x1B99;
|
|
|
|
|
|
|
|
# Create base path
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base');
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/1');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/1/12000', $tBasePage,
|
|
|
|
'22c98d248ff548311eda88559e4a8405ed77c003', $lTime);
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/1/' . DB_FILE_PGVERSION,
|
|
|
|
PG_VERSION_94, '184473f470864e067ee3a22e64b47b0a1c356f29', $lTime, '660');
|
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
executeTest('sudo chown 7777 ' . $oHostDbMaster->dbBasePath() . '/base/1/' . DB_FILE_PGVERSION);
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{MANIFEST_TARGET_PGDATA . '/base/1/' . DB_FILE_PGVERSION}
|
|
|
|
{&MANIFEST_SUBKEY_USER} = INI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $tPageInvalid17000 = $tBasePage . $tBasePage;
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384/17000', $tPageInvalid17000,
|
|
|
|
'e0101dd8ffb910c9c202ca35b5f828bcb9697bed', $lTime, undef, undef, '1');
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384/' . DB_FILE_PGVERSION,
|
|
|
|
PG_VERSION_94, '184473f470864e067ee3a22e64b47b0a1c356f29', $lTime);
|
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
executeTest('sudo chown :7777 ' . $oHostDbMaster->dbBasePath() . '/base/16384/' . DB_FILE_PGVERSION);
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{MANIFEST_TARGET_PGDATA . '/base/16384/' . DB_FILE_PGVERSION}
|
|
|
|
{&MANIFEST_SUBKEY_GROUP} = INI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/32768');
|
|
|
|
|
|
|
|
my $tPageValid =
|
2017-01-30 20:59:00 +02:00
|
|
|
pageBuild($tBasePage, 0) .
|
|
|
|
pageBuild($tBasePage, 1) .
|
|
|
|
pageBuild($tBasePage, 2) .
|
|
|
|
pageBuild($tBasePage, 0, 0xFFFF, 0xFFFF);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-01-30 20:59:00 +02:00
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/32768/33000', $tPageValid, '4a383e4fb8b5cd2a4e8fab91ef63dce48e532a2f',
|
|
|
|
$lTime);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-03-01 21:15:46 +02:00
|
|
|
my $iBlockOffset = 32767 * 131072;
|
|
|
|
|
|
|
|
my $tPageValidSeg32767 =
|
|
|
|
pageBuild($tBasePage, $iBlockOffset + 0) .
|
|
|
|
pageBuild($tBasePage, $iBlockOffset + 1) .
|
2017-03-13 21:50:13 +02:00
|
|
|
("\0" x 8192) .
|
2017-03-01 21:15:46 +02:00
|
|
|
pageBuild($tBasePage, 0, 0xFFFF, 0xFFFF);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/32768/33000.32767', $tPageValidSeg32767,
|
2017-03-13 21:50:13 +02:00
|
|
|
'21e2c7c1a326682c07053b7d6a5a40dbd49c2ec5', $lTime);
|
2017-03-01 21:15:46 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
my $tPageInvalid33001 =
|
2017-01-30 20:59:00 +02:00
|
|
|
pageBuild($tBasePage, 1) .
|
|
|
|
pageBuild($tBasePage, 1) .
|
|
|
|
pageBuild($tBasePage, 2) .
|
|
|
|
pageBuild($tBasePage, 0) .
|
|
|
|
pageBuild($tBasePage, 0) .
|
|
|
|
pageBuild($tBasePage, 0) .
|
|
|
|
pageBuild($tBasePage, 6) .
|
|
|
|
pageBuild($tBasePage, 0);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/32768/33001', $tPageInvalid33001,
|
|
|
|
'6bf316f11d28c28914ea9be92c00de9bea6d9a6b', $lTime, undef, undef, '0, [3, 5], 7');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/32768/' . DB_FILE_PGVERSION,
|
|
|
|
PG_VERSION_94, '184473f470864e067ee3a22e64b47b0a1c356f29', $lTime);
|
|
|
|
|
|
|
|
# Create global path
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'global');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_FILE_PGCONTROL, '[replaceme]',
|
|
|
|
'89373d9f2973502940de06bc5212489df3f8a912', $lTime - 100, undef, true);
|
|
|
|
|
|
|
|
# Copy pg_control
|
|
|
|
executeTest(
|
|
|
|
'cp ' . $self->dataPath() . '/backup.pg_control_' . WAL_VERSION_94 . '.bin ' . $oHostDbMaster->dbBasePath() . '/' .
|
|
|
|
DB_FILE_PGCONTROL);
|
|
|
|
utime($lTime - 100, $lTime - 100, $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL)
|
|
|
|
or confess &log(ERROR, "unable to set time");
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{MANIFEST_TARGET_PGDATA . '/' . DB_FILE_PGCONTROL}
|
|
|
|
{&MANIFEST_SUBKEY_SIZE} = 8192;
|
|
|
|
|
|
|
|
# Create tablespace path
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGTBLSPC);
|
|
|
|
|
|
|
|
# Create paths/files to ignore
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# Create temp dir and file that will be ignored
|
|
|
|
$oHostDbMaster->dbPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/' . DB_FILE_PREFIX_TMP);
|
|
|
|
$oHostDbMaster->dbFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/' . DB_FILE_PREFIX_TMP . '/' . DB_FILE_PREFIX_TMP . '.1', 'IGNORE');
|
|
|
|
|
|
|
|
# Create pg_dynshmem dir and file - only file will be ignored
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGDYNSHMEM);
|
2017-09-04 14:26:57 +02:00
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGDYNSHMEM . '/anything.tmp', 'IGNORE');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create pg_notify dir and file - only file will be ignored
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGNOTIFY);
|
2017-09-04 14:26:57 +02:00
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGNOTIFY . '/anything.tmp', 'IGNORE');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create pg_replslot dir and file - only file will be ignored
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGREPLSLOT);
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGREPLSLOT . '/anything.tmp', 'IGNORE');
|
|
|
|
|
|
|
|
# Create pg_serial dir and file - only file will be ignored
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSERIAL);
|
2017-09-04 14:26:57 +02:00
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSERIAL . '/anything.tmp', 'IGNORE');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create pg_snaphots dir and file - only file will be ignored
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSNAPSHOTS);
|
2017-09-04 14:26:57 +02:00
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSNAPSHOTS . '/anything.tmp', 'IGNORE');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create pg_stat_tmp dir and file - only file will be ignored
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSTATTMP);
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSTATTMP . '/anything.tmp', 'IGNORE');
|
|
|
|
|
|
|
|
# Create pg_subtrans dir and file - only file will be ignored
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSUBTRANS);
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_PATH_PGSUBTRANS . '/anything.tmp', 'IGNORE');
|
|
|
|
|
|
|
|
# More files to ignore
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_FILE_POSTGRESQLAUTOCONFTMP, 'IGNORE');
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_FILE_POSTMASTEROPTS, 'IGNORE');
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_FILE_RECOVERYCONF, 'IGNORE');
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, DB_FILE_RECOVERYDONE, 'IGNORE');
|
2017-09-04 14:26:57 +02:00
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'global/' . DB_FILE_PGINTERNALINIT, 'IGNORE');
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Backup Info (with no stanzas)
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->info('no stanzas exist');
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostDbMaster->info('no stanzas exist', {strOutput => CFGOPTVAL_INFO_OUTPUT_JSON});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Full backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strType = CFGOPTVAL_BACKUP_TYPE_FULL;
|
2016-12-23 15:22:59 +02:00
|
|
|
my $strOptionalParam = '--manifest-save-threshold=3';
|
|
|
|
my $strTestPoint;
|
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
if ($bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$strOptionalParam .= ' --protocol-timeout=2 --db-timeout=1';
|
|
|
|
|
2017-02-26 19:58:48 +02:00
|
|
|
# ??? This test is flapping and needs to implemented as a unit test instead
|
|
|
|
# if ($self->processMax() > 1)
|
|
|
|
# {
|
|
|
|
# $strTestPoint = TEST_KEEP_ALIVE;
|
|
|
|
# }
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create the archive info file
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->stanzaCreate('create required data for stanza', {strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create a file link
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbPath() . '/pg_config', {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
testFileCreate(
|
|
|
|
$oHostDbMaster->dbPath() . '/pg_config/postgresql.conf', "listen_addresses = *\n", $lTime - 100);
|
|
|
|
testLinkCreate($oHostDbMaster->dbPath() . '/pg_config/postgresql.conf.link', './postgresql.conf');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestLinkCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'postgresql.conf',
|
|
|
|
'../pg_config/postgresql.conf', true);
|
|
|
|
|
|
|
|
# This link will cause errors because it points to the same location as above
|
|
|
|
$oHostDbMaster->manifestLinkCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'pg_config_bad',
|
|
|
|
'../../db/pg_config');
|
|
|
|
|
|
|
|
my $strFullBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'error on identical link destinations',
|
2017-06-22 00:47:25 +02:00
|
|
|
{oExpectedManifest => \%oManifest, strOptionalParam => $strLogReduced,
|
2016-12-23 15:22:59 +02:00
|
|
|
iExpectedExitStatus => ERROR_LINK_DESTINATION});
|
|
|
|
|
|
|
|
# Remove failing link
|
|
|
|
$oHostDbMaster->manifestLinkRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'pg_config_bad');
|
|
|
|
|
|
|
|
# This link will fail because it points to a link
|
|
|
|
$oHostDbMaster->manifestLinkCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'postgresql.conf.bad',
|
|
|
|
'../pg_config/postgresql.conf.link');
|
|
|
|
|
|
|
|
# Fail bacause two links point to the same place
|
|
|
|
$strFullBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'error on link to a link',
|
2017-06-22 00:47:25 +02:00
|
|
|
{oExpectedManifest => \%oManifest, strOptionalParam => $strLogReduced,
|
2016-12-23 15:22:59 +02:00
|
|
|
iExpectedExitStatus => ERROR_LINK_DESTINATION});
|
|
|
|
|
|
|
|
# Remove failing link
|
|
|
|
$oHostDbMaster->manifestLinkRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'postgresql.conf.bad');
|
|
|
|
|
|
|
|
# Create stat directory link and file
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbPath() . '/pg_stat', {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestLinkCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'pg_stat', '../pg_stat');
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA . '/pg_stat', 'global.stat', 'stats',
|
|
|
|
'e350d5ce0153f3e22d5db21cf2a4eff00f3ee877', $lTime - 100, undef, true);
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'pg_clog');
|
|
|
|
|
|
|
|
$strFullBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'create pg_stat link, pg_clog dir',
|
|
|
|
{oExpectedManifest => \%oManifest,
|
2017-09-19 16:14:18 +02:00
|
|
|
strOptionalParam => $strOptionalParam .
|
|
|
|
# Pass ssh path to make sure it is used
|
|
|
|
($bRemote ? ' --' . cfgOptionName(CFGOPT_CMD_SSH) . '=/usr/bin/ssh' : '') .
|
|
|
|
# Pass bogus ssh port to make sure it is passed through the protocol layer (it won't be used)
|
|
|
|
($bRemote ? ' --' . cfgOptionName(CFGOPT_DB_PORT) . '=9999' : '') .
|
|
|
|
# Pass bogus socket path to make sure it is passed through the protocol layer (it won't be used)
|
|
|
|
($bRemote ? ' --' . cfgOptionName(CFGOPT_DB_SOCKET_PATH) . ' =/test_socket_path' : '') .
|
|
|
|
' --' . cfgOptionName(CFGOPT_BUFFER_SIZE) . '=16384 --' . cfgOptionName(CFGOPT_CHECKSUM_PAGE) .
|
|
|
|
' --' . cfgOptionName(CFGOPT_PROCESS_MAX) . '=1',
|
2017-08-25 22:47:47 +02:00
|
|
|
strRepoType => $bS3 ? undef : CFGOPTVAL_REPO_TYPE_CIFS, strTest => $strTestPoint, fTestDelay => 0});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Error on backup option to check logging
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid cmd line',
|
|
|
|
{oExpectedManifest => \%oManifest, strStanza => BOGUS, iExpectedExitStatus => ERROR_OPTION_REQUIRED});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test protocol timeout
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-22 00:47:25 +02:00
|
|
|
if ($bRemote && !$bS3)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'protocol timeout',
|
|
|
|
{oExpectedManifest => \%oManifest, strOptionalParam => '--protocol-timeout=1 --db-timeout=.1',
|
2017-06-09 23:51:41 +02:00
|
|
|
strTest => TEST_BACKUP_START, fTestDelay => 1, iExpectedExitStatus => ERROR_FILE_READ});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Stop operations and make sure the correct error occurs
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bS3)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# Test a backup abort
|
|
|
|
my $oExecuteBackup = $oHostBackup->backupBegin(
|
|
|
|
$strType, 'abort backup - local',
|
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_BACKUP_START, fTestDelay => 5,
|
|
|
|
iExpectedExitStatus => ERROR_TERM});
|
|
|
|
|
|
|
|
$oHostDbMaster->stop({bForce => true});
|
|
|
|
|
|
|
|
$oHostBackup->backupEnd($strType, $oExecuteBackup, {oExpectedManifest => \%oManifest});
|
|
|
|
|
|
|
|
# Test global stop
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'global stop',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_STOP});
|
|
|
|
|
|
|
|
# Test stanza stop
|
|
|
|
$oHostDbMaster->stop({strStanza => $oHostDbMaster->stanza()});
|
|
|
|
|
|
|
|
# This time a warning should be generated
|
|
|
|
$oHostDbMaster->stop({strStanza => $oHostDbMaster->stanza()});
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'stanza stop',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_STOP});
|
|
|
|
|
|
|
|
$oHostDbMaster->start({strStanza => $self->stanza()});
|
|
|
|
$oHostDbMaster->start();
|
|
|
|
|
|
|
|
# This time a warning should be generated
|
|
|
|
$oHostDbMaster->start();
|
|
|
|
|
|
|
|
# If the backup is remote then test remote stops
|
|
|
|
if ($bRemote)
|
|
|
|
{
|
|
|
|
my $oExecuteBackup = $oHostBackup->backupBegin(
|
|
|
|
$strType, 'abort backup - remote',
|
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_BACKUP_START, fTestDelay => 5,
|
|
|
|
iExpectedExitStatus => ERROR_TERM});
|
|
|
|
|
|
|
|
$oHostBackup->stop({bForce => true});
|
|
|
|
|
|
|
|
$oHostBackup->backupEnd($strType, $oExecuteBackup, {oExpectedManifest => \%oManifest});
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'global stop',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_STOP});
|
|
|
|
|
|
|
|
$oHostBackup->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Resume Full Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_FULL;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# These files should never be backed up (this requires the next backup to do --force)
|
|
|
|
testFileCreate($oHostDbMaster->dbBasePath() . '/' . DB_FILE_POSTMASTERPID, 'JUNK');
|
|
|
|
testFileCreate($oHostDbMaster->dbBasePath() . '/' . DB_FILE_BACKUPLABELOLD, 'JUNK');
|
|
|
|
testFileCreate($oHostDbMaster->dbBasePath() . '/' . DB_FILE_RECOVERYCONF, 'JUNK');
|
|
|
|
testFileCreate($oHostDbMaster->dbBasePath() . '/' . DB_FILE_RECOVERYDONE, 'JUNK');
|
|
|
|
|
|
|
|
# Create files in root tblspc paths that should not be copied or deleted.
|
|
|
|
# This will be checked later after a --force restore.
|
|
|
|
my $strDoNotDeleteFile = $oHostDbMaster->tablespacePath(1, 2) . '/donotdelete.txt';
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate(dirname($strDoNotDeleteFile), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
testFileCreate($strDoNotDeleteFile, 'DONOTDELETE-1-2');
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->tablespacePath(1), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
testFileCreate($oHostDbMaster->tablespacePath(1) . '/donotdelete.txt', 'DONOTDELETE-1');
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->tablespacePath(2), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
testFileCreate($oHostDbMaster->tablespacePath(2) . '/donotdelete.txt', 'DONOTDELETE-2');
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->tablespacePath(2, 2), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
testFileCreate($oHostDbMaster->tablespacePath(2, 2) . '/donotdelete.txt', 'DONOTDELETE-2-2');
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->tablespacePath(11), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Resume by copying the valid full backup over the last aborted full backup if it exists, or by creating a new path
|
|
|
|
my $strResumeBackup = (storageRepo()->list(
|
|
|
|
STORAGE_REPO_BACKUP, {strExpression => backupRegExpGet(true, true, true), strSortOrder => 'reverse'}))[0];
|
|
|
|
my $strResumePath = storageRepo()->pathGet('backup/' . $self->stanza() . '/' .
|
|
|
|
($strResumeBackup ne $strFullBackup ? $strResumeBackup : backupLabel(storageRepo(), $strType, undef, time())));
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
forceStorageRemove(storageRepo(), $strResumePath, {bRecurse => true});
|
|
|
|
forceStorageMove(storageRepo(), 'backup/' . $self->stanza() . "/${strFullBackup}", $strResumePath);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$oHostBackup->manifestMunge(
|
|
|
|
basename($strResumePath),
|
2017-04-10 19:24:45 +02:00
|
|
|
{&MANIFEST_SECTION_TARGET_FILE =>
|
|
|
|
{(&MANIFEST_TARGET_PGDATA . '/' . &DB_FILE_PGVERSION) => {&MANIFEST_SUBKEY_CHECKSUM => undef}}},
|
|
|
|
false);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Remove the main manifest so the backup appears aborted
|
|
|
|
forceStorageRemove(storageRepo(), "${strResumePath}/" . FILE_MANIFEST);
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Create a temp file in backup temp root to be sure it's deleted correctly
|
2017-06-15 21:32:10 +02:00
|
|
|
my $strTempFile = "${strResumePath}/file.tmp";
|
2017-06-12 16:52:32 +02:00
|
|
|
|
|
|
|
if ($bS3)
|
|
|
|
{
|
|
|
|
$oHostS3->executeS3('cp /etc/hosts s3://' . HOST_S3_BUCKET . "${strTempFile}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
executeTest("sudo touch ${strTempFile}", {bRemote => $bRemote});
|
2017-06-15 21:32:10 +02:00
|
|
|
executeTest("sudo chown " . BACKREST_USER . " ${strResumePath}/file.tmp");
|
2017-06-12 16:52:32 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$strFullBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'resume',
|
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_BACKUP_RESUME,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => '--force --' . cfgOptionName(CFGOPT_CHECKSUM_PAGE)});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Remove postmaster.pid so restore will succeed (the rest will be cleaned up by the delta)
|
|
|
|
storageDb->remove($oHostDbMaster->dbBasePath() . '/' . DB_FILE_POSTMASTERPID);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Misconfigure repo-path and check errors
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-15 21:32:10 +02:00
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid repo',
|
2017-08-25 22:47:47 +02:00
|
|
|
{oExpectedManifest => \%oManifest, strOptionalParam => '--' . cfgOptionName(CFGOPT_REPO_PATH) . '=/bogus_path' .
|
2017-06-22 00:47:25 +02:00
|
|
|
" ${strLogReduced}", iExpectedExitStatus => $bS3 ? ERROR_FILE_MISSING : ERROR_PATH_MISSING});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restore - tests various mode, extra files/paths, missing files/paths
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
my $bDelta = true;
|
|
|
|
my $bForce = false;
|
|
|
|
|
|
|
|
# Munge permissions/modes on files that will be fixed by the restore
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
executeTest("sudo chown :7777 " . $oHostDbMaster->dbBasePath() . '/base/1/' . DB_FILE_PGVERSION);
|
|
|
|
executeTest("sudo chmod 600 " . $oHostDbMaster->dbBasePath() . '/base/1/' . DB_FILE_PGVERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a path and file that are not in the manifest
|
|
|
|
$oHostDbMaster->dbPathCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'deleteme');
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'deleteme/deleteme.txt', 'DELETEME');
|
|
|
|
|
|
|
|
# Change path mode
|
|
|
|
$oHostDbMaster->dbPathMode(\%oManifest, MANIFEST_TARGET_PGDATA, 'base', '0777');
|
|
|
|
|
|
|
|
# Remove a path
|
|
|
|
$oHostDbMaster->dbPathRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'pg_clog');
|
|
|
|
|
|
|
|
# Remove a file
|
|
|
|
$oHostDbMaster->dbFileRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384/17000');
|
|
|
|
|
|
|
|
# Restore will reset invalid user and group so do the same in the manifest
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
delete($oManifest{&MANIFEST_SECTION_TARGET_FILE}{MANIFEST_TARGET_PGDATA . '/base/1/' . DB_FILE_PGVERSION}
|
|
|
|
{&MANIFEST_SUBKEY_USER});
|
|
|
|
delete($oManifest{&MANIFEST_SECTION_TARGET_FILE}{MANIFEST_TARGET_PGDATA . '/base/16384/' . DB_FILE_PGVERSION}
|
|
|
|
{&MANIFEST_SUBKEY_GROUP});
|
|
|
|
}
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
|
|
|
'add and delete files', undef, ' --link-all' . ($bRemote ? ' --cmd-ssh=/usr/bin/ssh' : ''),
|
2017-06-15 21:32:10 +02:00
|
|
|
undef, !$bRemote ? 'root' : undef);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Fix permissions on the restore log & remove lock files
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
executeTest('sudo chown -R ' . TEST_USER . ':' . TEST_GROUP . ' ' . $oHostBackup->logPath());
|
2016-12-23 15:22:59 +02:00
|
|
|
executeTest('sudo rm -rf ' . $oHostDbMaster->lockPath() . '/*');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Change an existing link to the wrong directory
|
|
|
|
$oHostDbMaster->dbFileRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'pg_stat');
|
|
|
|
$oHostDbMaster->dbLinkCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'pg_stat', '../wrong');
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
'fix broken symlink', undef, " --link-all ${strLogReduced} ${strLogReduced}");
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Additional restore tests that don't need to be performed for every permutation
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# This time manually restore all links
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
'restore all links by mapping', undef, $strLogReduced .
|
2016-12-23 15:22:59 +02:00
|
|
|
' --link-map=pg_stat=../pg_stat --link-map=postgresql.conf=../pg_config/postgresql.conf');
|
|
|
|
|
|
|
|
# Error when links overlap
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
|
|
|
'restore all links by mapping', ERROR_LINK_DESTINATION, '--log-level-console=warn' .
|
|
|
|
' --link-map=pg_stat=../pg_stat --link-map=postgresql.conf=../pg_stat/postgresql.conf');
|
|
|
|
|
|
|
|
# Error when links still exist on non-delta restore
|
|
|
|
$bDelta = false;
|
|
|
|
|
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->dbBasePath() . "/*");
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
|
|
|
'error on existing linked path', ERROR_PATH_NOT_EMPTY, '--log-level-console=warn --link-all');
|
|
|
|
|
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->dbPath() . "/pg_stat/*");
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
|
|
|
'error on existing linked file', ERROR_PATH_NOT_EMPTY, '--log-level-console=warn --link-all');
|
|
|
|
|
2017-04-12 15:53:07 +02:00
|
|
|
# Error when postmaster.pid is present
|
|
|
|
executeTest('touch ' . $oHostDbMaster->dbBasePath() . qw(/) . DB_FILE_POSTMASTERPID);
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
|
|
|
'error on postmaster.pid exists', ERROR_POSTMASTER_RUNNING, '--log-level-console=warn');
|
|
|
|
|
|
|
|
executeTest('rm ' . $oHostDbMaster->dbBasePath() . qw(/) . DB_FILE_POSTMASTERPID);
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Now a combination of remapping
|
|
|
|
$bDelta = true;
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
|
|
|
'restore all links --link-all and mapping', undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
"${strLogReduced} --link-map=pg_stat=../pg_stat --link-all");
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Restore - test errors when $PGDATA cannot be verified
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$bDelta = true;
|
|
|
|
$bForce = true;
|
|
|
|
|
|
|
|
# Remove PG_VERSION
|
|
|
|
$oHostDbMaster->dbFileRemove(\%oManifest, MANIFEST_TARGET_PGDATA, DB_FILE_PGVERSION);
|
|
|
|
|
|
|
|
# Attempt the restore
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
'fail on missing ' . DB_FILE_PGVERSION, ERROR_PATH_NOT_EMPTY, $strLogReduced);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Write a backup.manifest file to make $PGDATA valid
|
|
|
|
testFileCreate($oHostDbMaster->dbBasePath() . '/backup.manifest', 'BOGUS');
|
|
|
|
|
|
|
|
# Munge the user to make sure it gets reset on the next run
|
|
|
|
$oHostBackup->manifestMunge(
|
2017-04-10 19:24:45 +02:00
|
|
|
$strFullBackup,
|
|
|
|
{&MANIFEST_SECTION_TARGET_FILE =>
|
|
|
|
{&MANIFEST_FILE_PGCONTROL => {&MANIFEST_SUBKEY_USER => 'bogus', &MANIFEST_SUBKEY_GROUP => 'bogus'}}},
|
|
|
|
false);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restore succeeds
|
|
|
|
$oHostDbMaster->manifestLinkMap(\%oManifest, MANIFEST_TARGET_PGDATA . '/pg_stat');
|
|
|
|
$oHostDbMaster->manifestLinkMap(\%oManifest, MANIFEST_TARGET_PGDATA . '/postgresql.conf');
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strFullBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
'restore succeeds with backup.manifest file', undef, $strLogReduced);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Various broken info tests
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_INCR;
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestReference(\%oManifest, $strFullBackup);
|
|
|
|
|
|
|
|
# Break the database version
|
|
|
|
$oHostBackup->infoMunge(
|
2017-06-09 23:51:41 +02:00
|
|
|
storageRepo()->pathGet(STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO),
|
2016-12-23 15:22:59 +02:00
|
|
|
{&INFO_BACKUP_SECTION_DB => {&INFO_BACKUP_KEY_DB_VERSION => '8.0'}});
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid database version',
|
2017-06-22 00:47:25 +02:00
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_BACKUP_MISMATCH, strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Break the database system id
|
|
|
|
$oHostBackup->infoMunge(
|
2017-06-09 23:51:41 +02:00
|
|
|
storageRepo()->pathGet(STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO),
|
2016-12-23 15:22:59 +02:00
|
|
|
{&INFO_BACKUP_SECTION_DB => {&INFO_BACKUP_KEY_SYSTEM_ID => 6999999999999999999}});
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid system id',
|
2017-06-22 00:47:25 +02:00
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_BACKUP_MISMATCH, strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Break the control version
|
|
|
|
$oHostBackup->infoMunge(
|
2017-06-09 23:51:41 +02:00
|
|
|
storageRepo()->pathGet(STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO),
|
2016-12-23 15:22:59 +02:00
|
|
|
{&INFO_BACKUP_SECTION_DB => {&INFO_BACKUP_KEY_CONTROL => 842}});
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid control version',
|
2017-06-22 00:47:25 +02:00
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_BACKUP_MISMATCH, strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Break the catalog version
|
|
|
|
$oHostBackup->infoMunge(
|
2017-06-09 23:51:41 +02:00
|
|
|
storageRepo()->pathGet(STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO),
|
2016-12-23 15:22:59 +02:00
|
|
|
{&INFO_BACKUP_SECTION_DB => {&INFO_BACKUP_KEY_CATALOG => 197208141}});
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid catalog version',
|
2017-06-22 00:47:25 +02:00
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_BACKUP_MISMATCH, strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restore the file to its original condition
|
2017-06-09 23:51:41 +02:00
|
|
|
$oHostBackup->infoRestore(storageRepo()->pathGet(STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO));
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Test broken tablespace configuration
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_INCR;
|
2016-12-23 15:22:59 +02:00
|
|
|
my $strTblSpcPath = $oHostDbMaster->dbBasePath() . '/' . DB_PATH_PGTBLSPC;
|
|
|
|
|
|
|
|
# Create a directory in pg_tablespace
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate("${strTblSpcPath}/path", {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid path in ' . DB_PATH_PGTBLSPC,
|
2017-06-22 00:47:25 +02:00
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_LINK_EXPECTED, strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testPathRemove("${strTblSpcPath}/path");
|
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
# Create a relative link in PGDATA
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", '../');
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid relative tablespace is ../',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", '..');
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid relative tablespace is ..',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", '../../base/');
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid relative tablespace is ../../$PGDATA',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", '../../base');
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid relative tablespace is ../../$PGDATA',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
|
|
|
|
# Create a link to a link
|
|
|
|
testLinkCreate($oHostDbMaster->dbPath() . "/intermediate_link", $oHostDbMaster->dbPath() . '/tablespace/ts1');
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", $oHostDbMaster->dbPath() . "/intermediate_link");
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'tablespace link references a link',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_LINK_DESTINATION,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove($oHostDbMaster->dbPath() . "/intermediate_link");
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a relative link in PGDATA
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", '../invalid_tblspc');
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid relative tablespace in $PGDATA',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
|
|
|
|
# Create tablespace with same initial dir name as $PGDATA
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", $oHostDbMaster->dbBasePath() . '_tbs');
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
2017-02-14 02:59:14 +02:00
|
|
|
$strType, '$PGDATA is a substring of valid tblspc excluding / (file missing err expected)',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_FILE_MISSING,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create tablespace in PGDATA
|
|
|
|
testLinkCreate("${strTblSpcPath}/99999", $oHostDbMaster->dbBasePath() . '/invalid_tblspc');
|
|
|
|
|
|
|
|
$oHostBackup->backup(
|
|
|
|
$strType, 'invalid tablespace in $PGDATA',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
testFileRemove("${strTblSpcPath}/99999");
|
|
|
|
|
|
|
|
# Incr backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_INCR;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Add tablespace 1
|
|
|
|
$oHostDbMaster->manifestTablespaceCreate(\%oManifest, 1);
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/1', '16384');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/1', '16384/tablespace1.txt', 'TBLSPC1',
|
|
|
|
'd85de07d6421d90aa9191c11c889bfde43680f0f', $lTime, undef, undef, false);
|
|
|
|
$oHostDbMaster->manifestFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'badchecksum.txt', 'BADCHECKSUM',
|
|
|
|
'f927212cd08d11a42a666b2f04235398e9ceeb51', $lTime, undef, true);
|
|
|
|
|
|
|
|
# Create temp dir and file that will be ignored
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$oHostDbMaster->dbPathCreate(\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/1', DB_FILE_PREFIX_TMP);
|
|
|
|
$oHostDbMaster->dbFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/1', DB_FILE_PREFIX_TMP . '/' . DB_FILE_PREFIX_TMP . '.1', 'IGNORE');
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'add tablespace 1', {oExpectedManifest => \%oManifest, strOptionalParam => '--test'});
|
|
|
|
|
|
|
|
# Resume Incr Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_INCR;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Create resumable backup from last backup
|
|
|
|
$strResumePath =
|
|
|
|
storageRepo()->pathGet('backup/' . $self->stanza() . '/' .
|
|
|
|
backupLabel(storageRepo(), $strType, substr($strBackup, 0, 16), time()));
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
forceStorageRemove(storageRepo(), $strResumePath);
|
|
|
|
forceStorageMove(storageRepo(), 'backup/' . $self->stanza() . "/${strBackup}", $strResumePath);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$oHostBackup->manifestMunge(
|
|
|
|
basename($strResumePath),
|
2017-04-10 19:24:45 +02:00
|
|
|
{&MANIFEST_SECTION_TARGET_FILE =>
|
|
|
|
{(&MANIFEST_TARGET_PGDATA . '/badchecksum.txt') => {&MANIFEST_SUBKEY_CHECKSUM => BOGUS}}},
|
|
|
|
false);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Remove the main manifest so the backup appears aborted
|
|
|
|
forceStorageRemove(storageRepo(), "${strResumePath}/" . FILE_MANIFEST);
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Add tablespace 2
|
|
|
|
$oHostDbMaster->manifestTablespaceCreate(\%oManifest, 2);
|
|
|
|
$oHostDbMaster->manifestPathCreate(\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/2', '32768');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/2', '32768/tablespace2.txt', 'TBLSPC2',
|
|
|
|
'dc7f76e43c46101b47acc55ae4d593a9e6983578', $lTime, undef, undef, false);
|
|
|
|
|
2017-09-04 14:26:57 +02:00
|
|
|
# Make sure pg_internal.init is ignored in tablespaces
|
|
|
|
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/2', '32768/' . DB_FILE_PGINTERNALINIT, 'IGNORE');
|
2017-03-02 20:50:29 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Also create tablespace 11 to be sure it does not conflict with path of tablespace 1
|
2017-06-15 21:32:10 +02:00
|
|
|
$oHostDbMaster->manifestTablespaceCreate(\%oManifest, 11);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backup(
|
2017-06-22 00:47:25 +02:00
|
|
|
$strType, 'resume and add tablespace 2',
|
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_BACKUP_RESUME,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => '--' . cfgOptionName(CFGOPT_PROCESS_MAX) . '=1'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Resume Diff Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_DIFF;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Drop tablespace 11
|
2017-06-15 21:32:10 +02:00
|
|
|
$oHostDbMaster->manifestTablespaceDrop(\%oManifest, 11);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Create resumable backup from last backup
|
|
|
|
$strResumePath = storageRepo()->pathGet('backup/' . $self->stanza() . "/${strBackup}");
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Remove the main manifest so the backup appears aborted
|
|
|
|
forceStorageRemove(storageRepo(), "${strResumePath}/" . FILE_MANIFEST);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'cannot resume - new diff',
|
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_BACKUP_NORESUME,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => "$strLogReduced --" . cfgOptionName(CFGOPT_PROCESS_MAX) . '=1'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Resume Diff Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_DIFF;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Create resumable backup from last backup
|
|
|
|
$strResumePath = storageRepo()->pathGet('backup/' . $self->stanza() . "/${strBackup}");
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Remove the main manifest so the backup appears aborted
|
|
|
|
forceStorageRemove(storageRepo(), "${strResumePath}/" . FILE_MANIFEST);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'cannot resume - disabled / no repo link',
|
2017-06-09 23:51:41 +02:00
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_BACKUP_NORESUME,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => "--no-resume ${strLogReduced} --" . cfgOptionName(CFGOPT_PROCESS_MAX) . '=1'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restore
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$bDelta = false;
|
|
|
|
$bForce = false;
|
|
|
|
|
|
|
|
# Fail on used path
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strBackup, \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
'fail on used path', ERROR_PATH_NOT_EMPTY, $strLogReduced);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Remap the base and tablespace paths
|
|
|
|
my %oRemapHash;
|
|
|
|
$oRemapHash{&MANIFEST_TARGET_PGDATA} = $oHostDbMaster->dbBasePath(2);
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbBasePath(2), {strMode => '0700', bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
$oRemapHash{&MANIFEST_TARGET_PGTBLSPC . '/1'} = $oHostDbMaster->tablespacePath(1, 2);
|
|
|
|
$oRemapHash{&MANIFEST_TARGET_PGTBLSPC . '/2'} = $oHostDbMaster->tablespacePath(2, 2);
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strBackup, \%oManifest, \%oRemapHash, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
'remap all paths', undef, $strLogReduced);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restore (make sure file in root tablespace path is not deleted by --delta)
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$bDelta = true;
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
|
|
|
$strBackup, \%oManifest, \%oRemapHash, $bDelta, $bForce, undef, undef, undef, undef, undef, undef,
|
2017-06-22 00:47:25 +02:00
|
|
|
'ensure file in tblspc root remains after --delta', undef, $strLogReduced);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
if (!-e $strDoNotDeleteFile)
|
|
|
|
{
|
|
|
|
confess "${strDoNotDeleteFile} was deleted by --delta";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Incr Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_INCR;
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestReference(\%oManifest, $strBackup);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/base2.txt', 'BASE2', '09b5e31766be1dba1ec27de82f975c1b6eea2a92',
|
|
|
|
$lTime, undef, undef, false);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestTablespaceDrop(\%oManifest, 1, 2);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/2', '32768/tablespace2b.txt', 'TBLSPC2B',
|
|
|
|
'e324463005236d83e6e54795dbddd20a74533bf3', $lTime, undef, undef, false);
|
|
|
|
|
|
|
|
# Munge the version to make sure it gets corrected on the next run
|
2017-04-10 19:24:45 +02:00
|
|
|
$oHostBackup->manifestMunge($strBackup, {&INI_SECTION_BACKREST => {&INI_KEY_VERSION => '0.00'}}, false);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'add files and remove tablespace 2',
|
2017-08-25 22:47:47 +02:00
|
|
|
{oExpectedManifest => \%oManifest, strOptionalParam => "$strLogReduced --" . cfgOptionName(CFGOPT_PROCESS_MAX) . '=1'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Incr Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_INCR;
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestReference(\%oManifest, $strBackup);
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Delete the backup.info and make sure the backup fails - the user must then run a stanza-create --force. If backup.info is
|
|
|
|
# encrypted is cannot be deleted, so copy it to old instead.
|
|
|
|
my $strBackupInfoFile = STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO;
|
|
|
|
my $strBackupInfoCopyFile = STORAGE_REPO_BACKUP . qw{/} . FILE_BACKUP_INFO . INI_COPY_EXT;
|
|
|
|
my $strBackupInfoOldFile = "${strBackupInfoFile}.old";
|
|
|
|
my $strBackupInfoCopyOldFile = "${strBackupInfoCopyFile}.old";
|
|
|
|
|
|
|
|
if ($bRepoEncrypt)
|
|
|
|
{
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoFile, $strBackupInfoOldFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoCopyFile, $strBackupInfoCopyOldFile, {bRecurse => false});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forceStorageRemove(storageRepo(), $strBackupInfoFile);
|
|
|
|
forceStorageRemove(storageRepo(), $strBackupInfoCopyFile);
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384/17000', 'BASEUPDT', '9a53d532e27785e681766c98516a5e93f096a501',
|
|
|
|
$lTime, undef, undef, false);
|
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!$bRemote)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
$strBackup =$oHostBackup->backup(
|
|
|
|
$strType, 'update files - fail on missing backup.info',
|
|
|
|
{oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_FILE_MISSING,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Fail on attempt to create the stanza data since force was not used
|
2017-06-09 23:51:41 +02:00
|
|
|
$oHostBackup->stanzaCreate('fail on backup directory missing backup.info',
|
2017-08-25 22:47:47 +02:00
|
|
|
{iExpectedExitStatus => ERROR_FILE_MISSING, strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
2017-11-06 19:51:12 +02:00
|
|
|
|
|
|
|
# Use force to create the stanza (this is expected to fail for encrypted repos)
|
|
|
|
$oHostBackup->stanzaCreate('create required data for stanza',
|
|
|
|
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE),
|
|
|
|
iExpectedExitStatus => $bRepoEncrypt ? ERROR_FILE_MISSING : undef});
|
|
|
|
|
|
|
|
# Copy encrypted backup info files back so testing can proceed
|
|
|
|
if ($bRepoEncrypt)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-11-06 19:51:12 +02:00
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoOldFile, $strBackupInfoFile, {bRecurse => false});
|
|
|
|
forceStorageMove(storageRepo(), $strBackupInfoCopyOldFile, $strBackupInfoCopyFile, {bRecurse => false});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Perform the backup
|
|
|
|
$strBackup =$oHostBackup->backup(
|
2017-06-22 00:47:25 +02:00
|
|
|
$strType, 'update files', {oExpectedManifest => \%oManifest, strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Diff Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_DIFF;
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestReference(\%oManifest, $strFullBackup, true);
|
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backup(
|
2017-06-22 00:47:25 +02:00
|
|
|
$strType, 'updates since last full', {oExpectedManifest => \%oManifest,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => "$strLogReduced --" . cfgOptionName(CFGOPT_PROCESS_MAX) . '=1'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Incr Backup
|
|
|
|
#
|
|
|
|
# Remove a file from the db after the manifest has been built but before files are copied. The file will not be shown
|
|
|
|
# as removed in the log because it had not changed since the last backup so it will only be referenced. This test also
|
|
|
|
# checks that everything works when there are no jobs to run.
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_INCR;
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestReference(\%oManifest, $strBackup);
|
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
# Enable compression to ensure a warning is raised
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_COMPRESS) => 'y'}});
|
2017-06-15 21:32:10 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
my $oBackupExecute = $oHostBackup->backupBegin(
|
|
|
|
$strType, 'remove files - but won\'t affect manifest',
|
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_MANIFEST_BUILD, fTestDelay => 1,
|
2017-06-22 00:47:25 +02:00
|
|
|
strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->dbFileRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384/17000');
|
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backupEnd($strType, $oBackupExecute, {oExpectedManifest => \%oManifest});
|
|
|
|
|
|
|
|
# Diff Backup
|
|
|
|
#
|
|
|
|
# Remove base2.txt and changed tablespace2c.txt during the backup. The removed file should be logged and the changed
|
|
|
|
# file should have the new, larger size logged and in the manifest.
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestReference(\%oManifest, $strFullBackup, true);
|
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_DIFF;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384/17000');
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileRemove(\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/2', '32768/tablespace2b.txt', true);
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/2', '32768/tablespace2c.txt', 'TBLSPC2C',
|
|
|
|
'ad7df329ab97a1e7d35f1ff0351c079319121836', $lTime, undef, undef, false);
|
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
# Enable hardlinks (except for s3) to ensure a warning is raised
|
|
|
|
if (!$bS3)
|
|
|
|
{
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_HARDLINK) => 'y'}});
|
2017-06-15 21:32:10 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
$oBackupExecute = $oHostBackup->backupBegin(
|
|
|
|
$strType, 'remove files during backup',
|
|
|
|
{oExpectedManifest => \%oManifest, strTest => TEST_MANIFEST_BUILD, fTestDelay => 1,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => "$strLogReduced --" . cfgOptionName(CFGOPT_PROCESS_MAX) . '=1'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGTBLSPC . '/2', '32768/tablespace2c.txt', 'TBLSPCBIGGER',
|
|
|
|
'dfcb8679956b734706cf87259d50c88f83e80e66', $lTime, undef, undef, false);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileRemove(\%oManifest, MANIFEST_TARGET_PGDATA, 'base/base2.txt', true);
|
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backupEnd($strType, $oBackupExecute, {oExpectedManifest => \%oManifest});
|
|
|
|
|
|
|
|
# Full Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_FULL;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
# Now the compression and hardlink changes will take effect
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS} = JSON::PP::true;
|
|
|
|
|
|
|
|
if (!$bS3)
|
|
|
|
{
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_HARDLINK} = JSON::PP::true;
|
|
|
|
$oHostBackup->{bHardLink} = true;
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->manifestReference(\%oManifest);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/16384/17000', 'BASEUPDT2', '7579ada0808d7f98087a0a586d0df9de009cdc33',
|
|
|
|
$lTime, undef, undef, false);
|
|
|
|
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_CHECKSUM_PAGE} = JSON::PP::false;
|
|
|
|
|
|
|
|
$strFullBackup = $oHostBackup->backup(
|
2017-06-22 00:47:25 +02:00
|
|
|
$strType, 'update file', {oExpectedManifest => \%oManifest, strOptionalParam => $strLogReduced});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Backup Info
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->info('normal output', {strStanza => $oHostDbMaster->stanza()});
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->info('normal output', {strStanza => $oHostBackup->stanza(), strOutput => CFGOPTVAL_INFO_OUTPUT_JSON});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Call expire
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-15 21:32:10 +02:00
|
|
|
$oHostBackup->expire({iRetentionFull => 1});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Diff Backup
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strType = CFGOPTVAL_BACKUP_TYPE_DIFF;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->manifestReference(\%oManifest, $strFullBackup);
|
|
|
|
|
|
|
|
$oHostDbMaster->manifestFileCreate(
|
|
|
|
\%oManifest, MANIFEST_TARGET_PGDATA, 'base/base2.txt', 'BASE2UPDT', 'cafac3c59553f2cfde41ce2e62e7662295f108c0',
|
|
|
|
$lTime, undef, undef, false);
|
|
|
|
|
|
|
|
# Munge the prior manifest so that option-checksum-page is missing to be sure the logic works for backups before page
|
|
|
|
# checksums were introduced
|
2017-04-10 19:24:45 +02:00
|
|
|
$oHostBackup->manifestMunge(
|
|
|
|
$strFullBackup, {&MANIFEST_SECTION_BACKUP_OPTION => {&MANIFEST_KEY_CHECKSUM_PAGE => undef}}, false);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'add file', {oExpectedManifest => \%oManifest,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => "${strLogReduced} --" . cfgOptionName(CFGOPT_CHECKSUM_PAGE)});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Selective Restore
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$bDelta = true;
|
|
|
|
|
|
|
|
# Remove mapping for tablespace 1
|
|
|
|
delete($oRemapHash{&MANIFEST_TARGET_PGTBLSPC . '/1'});
|
|
|
|
|
|
|
|
# Remove checksum to match zeroed files
|
|
|
|
delete($oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_data/base/32768/33000'}{&MANIFEST_SUBKEY_CHECKSUM});
|
|
|
|
delete($oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_data/base/32768/33001'}{&MANIFEST_SUBKEY_CHECKSUM});
|
|
|
|
delete($oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_tblspc/2/PG_9.4_201409291/32768/tablespace2.txt'}
|
|
|
|
{&MANIFEST_SUBKEY_CHECKSUM});
|
|
|
|
delete($oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_tblspc/2/PG_9.4_201409291/32768/tablespace2c.txt'}
|
|
|
|
{&MANIFEST_SUBKEY_CHECKSUM});
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-11-02 14:14:13 +02:00
|
|
|
cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET), \%oManifest, \%oRemapHash, $bDelta, $bForce, undef, undef, undef,
|
2017-08-25 22:47:47 +02:00
|
|
|
undef, undef, undef, 'selective restore 16384', undef, "${strLogReduced} --db-include=16384");
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Restore checksum values for next test
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_data/base/32768/33000'}{&MANIFEST_SUBKEY_CHECKSUM} =
|
2017-01-30 20:59:00 +02:00
|
|
|
'4a383e4fb8b5cd2a4e8fab91ef63dce48e532a2f';
|
2016-12-23 15:22:59 +02:00
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_data/base/32768/33001'}{&MANIFEST_SUBKEY_CHECKSUM} =
|
|
|
|
'6bf316f11d28c28914ea9be92c00de9bea6d9a6b';
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_tblspc/2/PG_9.4_201409291/32768/tablespace2.txt'}
|
|
|
|
{&MANIFEST_SUBKEY_CHECKSUM} = 'dc7f76e43c46101b47acc55ae4d593a9e6983578';
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_tblspc/2/PG_9.4_201409291/32768/tablespace2c.txt'}
|
|
|
|
{&MANIFEST_SUBKEY_CHECKSUM} = 'dfcb8679956b734706cf87259d50c88f83e80e66';
|
|
|
|
|
|
|
|
# Remove checksum to match zeroed file
|
|
|
|
delete($oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_data/base/16384/17000'}{&MANIFEST_SUBKEY_CHECKSUM});
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-11-02 14:14:13 +02:00
|
|
|
cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET), \%oManifest, \%oRemapHash, $bDelta, $bForce, undef, undef, undef,
|
2017-08-25 22:47:47 +02:00
|
|
|
undef, undef, undef, 'selective restore 32768', undef, "${strLogReduced} --db-include=32768");
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{'pg_data/base/16384/17000'}{&MANIFEST_SUBKEY_CHECKSUM} =
|
|
|
|
'7579ada0808d7f98087a0a586d0df9de009cdc33';
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-11-02 14:14:13 +02:00
|
|
|
cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET), \%oManifest, \%oRemapHash, $bDelta, $bForce, undef, undef, undef,
|
2017-08-25 22:47:47 +02:00
|
|
|
undef, undef, undef, 'error on invalid id', ERROR_DB_MISSING, '--log-level-console=warn --db-include=7777');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-11-02 14:14:13 +02:00
|
|
|
cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET), \%oManifest, \%oRemapHash, $bDelta, $bForce, undef, undef, undef,
|
2017-08-25 22:47:47 +02:00
|
|
|
undef, undef, undef, 'error on system id', ERROR_DB_INVALID, '--log-level-console=warn --db-include=1');
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Compact Restore
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2016-12-23 15:22:59 +02:00
|
|
|
$bDelta = false;
|
|
|
|
|
|
|
|
executeTest('rm -rf ' . $oHostDbMaster->dbBasePath(2) . "/*");
|
|
|
|
|
|
|
|
my $strDbPath = $oHostDbMaster->dbBasePath(2) . '/base';
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($strDbPath, {strMode => '0700'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oRemapHash{&MANIFEST_TARGET_PGDATA} = $strDbPath;
|
|
|
|
delete($oRemapHash{&MANIFEST_TARGET_PGTBLSPC . '/2'});
|
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-11-02 14:14:13 +02:00
|
|
|
cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET), \%oManifest, \%oRemapHash, $bDelta, $bForce, undef, undef, undef,
|
2017-08-25 22:47:47 +02:00
|
|
|
undef, undef, undef, 'no tablespace remap - error when tablespace dir does not exist', ERROR_PATH_MISSING,
|
2017-06-22 00:47:25 +02:00
|
|
|
"${strLogReduced} --tablespace-map-all=../../tablespace", false);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbBasePath(2) . '/tablespace', {strMode => '0700'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->restore(
|
2017-11-02 14:14:13 +02:00
|
|
|
cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET), \%oManifest, undef, $bDelta, $bForce, undef, undef, undef, undef,
|
2017-08-25 22:47:47 +02:00
|
|
|
undef, undef, 'no tablespace remap', undef, "--tablespace-map-all=../../tablespace ${strLogReduced}", false);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oManifest{&MANIFEST_SECTION_BACKUP_TARGET}{'pg_tblspc/2'}{&MANIFEST_SUBKEY_PATH} = '../../tablespace/ts2';
|
|
|
|
$oManifest{&MANIFEST_SECTION_TARGET_LINK}{'pg_data/pg_tblspc/2'}{&MANIFEST_SUBKEY_DESTINATION} = '../../tablespace/ts2';
|
|
|
|
|
|
|
|
# Backup Info (with an empty stanza)
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-09 23:51:41 +02:00
|
|
|
forceStorageMode(storageRepo(), 'backup', 'g+w');
|
|
|
|
storageRepo()->pathCreate(storageRepo()->pathGet('backup/db_empty'), {strMode => '0770'});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostBackup->info('normal output');
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostDbMaster->info('normal output', {strOutput => CFGOPTVAL_INFO_OUTPUT_JSON});
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostBackup->info('bogus stanza', {strStanza => BOGUS});
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostDbMaster->info('bogus stanza', {strStanza => BOGUS, strOutput => CFGOPTVAL_INFO_OUTPUT_JSON});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Dump out history path at the end to verify all history files are being recorded. This test is only performed locally
|
|
|
|
# because for some reason sort order is different when this command is executed via ssh (even though the content of the
|
|
|
|
# directory is identical).
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$bRemote && !$bS3)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
executeTest('ls -1R ' . storageRepo()->pathGet('backup/' . $self->stanza() . '/' . PATH_BACKUP_HISTORY),
|
2016-12-23 15:22:59 +02:00
|
|
|
{oLogTest => $self->expect(), bRemote => $bRemote});
|
|
|
|
}
|
|
|
|
|
2017-05-16 17:28:51 +02:00
|
|
|
# Test config file validation
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-15 21:32:10 +02:00
|
|
|
if ($bRemote)
|
2017-05-16 17:28:51 +02:00
|
|
|
{
|
2017-06-15 21:32:10 +02:00
|
|
|
# Save off config file and add an invalid option to the remote (DB master) and confirm no warning thrown
|
|
|
|
executeTest("cp " . $oHostDbMaster->backrestConfig() . " " . $oHostDbMaster->backrestConfig() . ".save");
|
|
|
|
$oHostDbMaster->executeSimple("echo " . BOGUS . "=" . BOGUS . " >> " . $oHostDbMaster->backrestConfig(), undef,
|
|
|
|
'root');
|
2017-05-16 17:28:51 +02:00
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
$strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'config file not validated on remote', {oExpectedManifest => \%oManifest,
|
|
|
|
strOptionalParam => '--log-level-console=info'});
|
2017-05-16 17:28:51 +02:00
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
executeTest('sudo rm '. $oHostDbMaster->backrestConfig());
|
|
|
|
executeTest("mv " . $oHostDbMaster->backrestConfig() . ".save" . " " . $oHostDbMaster->backrestConfig());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Save off config file and add an invalid option to the local backup host and confirm a warning is thrown
|
|
|
|
executeTest("cp " . $oHostBackup->backrestConfig() . " " . $oHostBackup->backrestConfig() . ".save");
|
|
|
|
$oHostBackup->executeSimple("echo " . BOGUS . "=" . BOGUS . " >> " . $oHostBackup->backrestConfig(), undef, 'root');
|
2017-05-16 17:28:51 +02:00
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
$strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'config file warning on local', {oExpectedManifest => \%oManifest,
|
|
|
|
strOptionalParam => '--log-level-console=info 2>&1'});
|
2017-05-16 17:28:51 +02:00
|
|
|
|
2017-06-15 21:32:10 +02:00
|
|
|
executeTest('sudo rm '. $oHostBackup->backrestConfig());
|
|
|
|
executeTest("mv " . $oHostBackup->backrestConfig() . ".save" . " " . $oHostBackup->backrestConfig());
|
2017-05-16 17:28:51 +02:00
|
|
|
}
|
|
|
|
|
2017-05-12 22:05:44 +02:00
|
|
|
# Test backup from standby warning that standby not configured so option reset
|
2017-08-25 22:47:47 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-15 21:32:10 +02:00
|
|
|
if (!defined($oHostDbStandby))
|
2017-05-12 22:05:44 +02:00
|
|
|
{
|
|
|
|
$strBackup = $oHostBackup->backup(
|
|
|
|
$strType, 'option backup-standby reset - backup performed from master', {oExpectedManifest => \%oManifest,
|
2017-08-25 22:47:47 +02:00
|
|
|
strOptionalParam => '--log-level-console=info --' . cfgOptionName(CFGOPT_BACKUP_STANDBY)});
|
2017-05-12 22:05:44 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|