2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2018-04-08 18:57:02 +02:00
|
|
|
# Tests for expire command
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2018-04-08 18:57:02 +02:00
|
|
|
package pgBackRestTest::Module::Mock::MockExpireTest;
|
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);
|
|
|
|
|
|
|
|
use File::Basename qw(dirname);
|
2017-04-03 16:42:55 +02:00
|
|
|
use Storable qw(dclone);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2020-03-10 21:41:56 +02:00
|
|
|
use pgBackRestDoc::Common::Exception;
|
|
|
|
use pgBackRestDoc::Common::Ini;
|
|
|
|
use pgBackRestDoc::Common::Log;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Env::ArchiveInfo;
|
|
|
|
use pgBackRestTest::Env::BackupInfo;
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::ExpireEnvTest;
|
2020-03-09 23:41:59 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
2017-06-12 16:52:32 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostS3Test;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRestTest::Env::HostEnvTest;
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Env::Manifest;
|
|
|
|
use pgBackRestTest::Common::DbVersion;
|
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::RunTest;
|
|
|
|
use pgBackRestTest::Common::StorageRepo;
|
|
|
|
use pgBackRestTest::Common::VmTest;
|
|
|
|
use pgBackRestTest::Common::Wait;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
use constant SECONDS_PER_DAY => 86400;
|
|
|
|
my $lBaseTime = time() - (SECONDS_PER_DAY * 56);
|
|
|
|
my $strDescription;
|
|
|
|
|
2019-03-01 19:04:26 +02:00
|
|
|
foreach my $rhRun
|
|
|
|
(
|
2020-05-13 00:55:20 +02:00
|
|
|
{vm => VM2, storage => S3, encrypt => true},
|
|
|
|
{vm => VM3, storage => POSIX, encrypt => false},
|
2020-07-02 22:24:34 +02:00
|
|
|
{vm => VM4, storage => AZURE, encrypt => true},
|
2019-03-01 19:04:26 +02:00
|
|
|
)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2019-03-01 19:04:26 +02:00
|
|
|
# Only run tests for this vm
|
2019-11-02 11:35:48 +02:00
|
|
|
next if ($rhRun->{vm} ne vmTest($self->vm()));
|
2019-03-01 19:04:26 +02:00
|
|
|
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
2020-05-13 00:55:20 +02:00
|
|
|
my $strStorage = $rhRun->{storage};
|
2019-03-01 19:04:26 +02:00
|
|
|
my $bEncrypt = $rhRun->{encrypt};
|
|
|
|
|
2020-05-13 00:55:20 +02:00
|
|
|
if ($strStorage ne POSIX && ($self->vm() eq VM3))
|
2019-05-16 15:53:55 +02:00
|
|
|
{
|
2020-05-13 00:55:20 +02:00
|
|
|
confess &log("cannot configure non-posix storage for expect log tests");
|
2019-05-16 15:53:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
############################################################################################################################
|
2020-05-13 00:55:20 +02:00
|
|
|
if ($self->begin("simple, enc ${bEncrypt}, storage ${strStorage}"))
|
2017-11-06 19:51:12 +02:00
|
|
|
{
|
|
|
|
# Create hosts, file object, and config
|
2020-06-16 20:06:38 +02:00
|
|
|
my ($oHostDbPrimary, $oHostDbStandby, $oHostBackup) = $self->setup(
|
2020-05-13 00:55:20 +02:00
|
|
|
true, $self->expect(), {strStorage => $strStorage, bRepoEncrypt => $bEncrypt});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Create the test object
|
|
|
|
my $oExpireTest = new pgBackRestTest::Env::ExpireEnvTest(
|
2020-06-16 20:06:38 +02:00
|
|
|
$oHostBackup, $self->backrestExe(), storageRepo(), $oHostDbPrimary->dbPath(), $self->expect(), $self);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->stanzaCreate($self->stanza(), PG_VERSION_92);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Nothing to expire';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY, 246);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->process($self->stanza(), 1, 1, CFGOPTVAL_BACKUP_TYPE_FULL, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire oldest full backup, archive expire falls on segment major boundary';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 1, 1, CFGOPTVAL_BACKUP_TYPE_FULL, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire oldest full backup';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY, 256);
|
|
|
|
$oExpireTest->process($self->stanza(), 1, 1, CFGOPTVAL_BACKUP_TYPE_FULL, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire oldest diff backup, archive expire does not fall on major segment boundary';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY, undef, 0);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY, undef, 0);
|
|
|
|
$oExpireTest->process($self->stanza(), 1, 1, CFGOPTVAL_BACKUP_TYPE_DIFF, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire oldest diff backup (cascade to incr)';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 1, 1, CFGOPTVAL_BACKUP_TYPE_DIFF, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire archive based on newest incr backup';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 1, 1, CFGOPTVAL_BACKUP_TYPE_INCR, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire diff treating full as diff';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 2, 1, CFGOPTVAL_BACKUP_TYPE_DIFF, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-02-19 22:07:24 +02:00
|
|
|
$strDescription = 'Expire diff with repo-retention-archive with warning repo-retention-diff not set';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), undef, undef, CFGOPTVAL_BACKUP_TYPE_DIFF, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-02-19 22:07:24 +02:00
|
|
|
$strDescription = 'Expire full with repo-retention-archive with warning repo-retention-full not set';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), undef, undef, CFGOPTVAL_BACKUP_TYPE_FULL, 1, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-02-19 22:07:24 +02:00
|
|
|
$strDescription = 'Expire no archive with warning since repo-retention-archive not set for INCR';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 1, 1, CFGOPTVAL_BACKUP_TYPE_INCR, undef, $strDescription);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-02-19 22:07:24 +02:00
|
|
|
$strDescription = 'Expire no archive with warning since neither repo-retention-archive nor repo-retention-diff is set';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), undef, undef, CFGOPTVAL_BACKUP_TYPE_DIFF, undef, $strDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
############################################################################################################################
|
2020-05-13 00:55:20 +02:00
|
|
|
if ($self->begin("stanzaUpgrade, enc ${bEncrypt}, storage ${strStorage}"))
|
2017-11-06 19:51:12 +02:00
|
|
|
{
|
|
|
|
# Create hosts, file object, and config
|
2020-06-16 20:06:38 +02:00
|
|
|
my ($oHostDbPrimary, $oHostDbStandby, $oHostBackup) = $self->setup(
|
2020-05-13 00:55:20 +02:00
|
|
|
true, $self->expect(), {strStorage => $strStorage, bRepoEncrypt => $bEncrypt});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Create the test object
|
|
|
|
my $oExpireTest = new pgBackRestTest::Env::ExpireEnvTest(
|
2020-06-16 20:06:38 +02:00
|
|
|
$oHostBackup, $self->backrestExe(), storageRepo(), $oHostDbPrimary->dbPath(), $self->expect(), $self);
|
2017-11-06 19:51:12 +02:00
|
|
|
|
|
|
|
$oExpireTest->stanzaCreate($self->stanza(), PG_VERSION_92);
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Create backups in current db version';
|
|
|
|
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), undef, undef, CFGOPTVAL_BACKUP_TYPE_DIFF, undef, $strDescription);
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Upgrade stanza and expire only earliest db backup and archive';
|
|
|
|
|
|
|
|
$oExpireTest->stanzaUpgrade($self->stanza(), PG_VERSION_93);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY, 246);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 3, undef, CFGOPTVAL_BACKUP_TYPE_FULL, undef, $strDescription);
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Upgrade the stanza, create full back - earliest db orphaned archive removed and earliest full backup ' .
|
|
|
|
'and archive in previous db version removed';
|
|
|
|
|
2017-12-19 01:51:19 +02:00
|
|
|
$oExpireTest->stanzaUpgrade($self->stanza(), PG_VERSION_10);
|
2017-11-06 19:51:12 +02:00
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 2, undef, CFGOPTVAL_BACKUP_TYPE_FULL, undef, $strDescription);
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire all archive last full backup through pitr';
|
|
|
|
|
|
|
|
$oExpireTest->backupCreate($self->stanza(), CFGOPTVAL_BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
|
|
|
|
$oExpireTest->process($self->stanza(), 3, 1, CFGOPTVAL_BACKUP_TYPE_DIFF, 1, $strDescription);
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
$strDescription = 'Expire all archive except for the current database';
|
|
|
|
|
|
|
|
$oExpireTest->process($self->stanza(), 2, undef, CFGOPTVAL_BACKUP_TYPE_FULL, undef, $strDescription);
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|