#################################################################################################################################### # ExpireExpireTest.pm - Tests for expire command #################################################################################################################################### package pgBackRestTest::Expire::ExpireExpireTest; use parent 'pgBackRestTest::Full::FullCommonTest'; #################################################################################################################################### # Perl includes #################################################################################################################################### use strict; use warnings FATAL => qw(all); use Carp qw(confess); use File::Basename qw(dirname); use pgBackRest::ArchiveInfo; use pgBackRest::BackupInfo; use pgBackRest::DbVersion; use pgBackRest::Common::Exception; use pgBackRest::Common::Ini; use pgBackRest::Common::Log; use pgBackRest::Common::Wait; use pgBackRest::Config::Config; use pgBackRest::File; use pgBackRest::FileCommon; use pgBackRest::Manifest; use pgBackRestTest::Common::ExecuteTest; use pgBackRestTest::Common::RunTest; use pgBackRestTest::Full::FullCommonTest; use pgBackRestTest::Expire::ExpireCommonTest; #################################################################################################################################### # run #################################################################################################################################### sub run { my $self = shift; if ($self->begin("local")) { # Create hosts, file object, and config my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oFile) = $self->setup(true, $self->expect()); # Create the test object my $oExpireTest = new pgBackRestTest::Expire::ExpireCommonTest($oHostBackup, $self->backrestExe(), $oFile, $self->expect()); # ??? This function creates data elements in the $oExpireTest object that are used by the $oExpireTest functions. But # should probably change to use the stanza-create command especially with stanza-upgrade. $oExpireTest->stanzaCreate($self->stanza(), PG_VERSION_92); use constant SECONDS_PER_DAY => 86400; my $lBaseTime = time() - (SECONDS_PER_DAY * 56); #----------------------------------------------------------------------------------------------------------------------- my $strDescription = 'Nothing to expire'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY, 246); $oExpireTest->process($self->stanza(), 1, 1, BACKUP_TYPE_FULL, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire oldest full backup, archive expire falls on segment major boundary'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), 1, 1, BACKUP_TYPE_FULL, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire oldest full backup'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY, 256); $oExpireTest->process($self->stanza(), 1, 1, BACKUP_TYPE_FULL, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire oldest diff backup, archive expire does not fall on major segment boundary'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY, undef, 0); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY, undef, 0); $oExpireTest->process($self->stanza(), 1, 1, BACKUP_TYPE_DIFF, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire oldest diff backup (cascade to incr)'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), 1, 1, BACKUP_TYPE_DIFF, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire archive based on newest incr backup'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), 1, 1, BACKUP_TYPE_INCR, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire diff treating full as diff'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), 2, 1, BACKUP_TYPE_DIFF, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire diff with retention-archive with warning retention-diff not set'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), undef, undef, BACKUP_TYPE_DIFF, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire full with retention-archive with warning retention-full not set'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), undef, undef, BACKUP_TYPE_FULL, 1, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire no archive with warning since retention-archive not set for INCR'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), 1, 1, BACKUP_TYPE_INCR, undef, $strDescription); #----------------------------------------------------------------------------------------------------------------------- $strDescription = 'Expire no archive with warning since neither retention-archive nor retention-diff is set'; $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY); $oExpireTest->process($self->stanza(), undef, undef, BACKUP_TYPE_DIFF, undef, $strDescription); } } 1;