mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Starting on archive unit tests.
This commit is contained in:
parent
375545320d
commit
8d398e4bff
@ -73,10 +73,16 @@ my $strConfigFile; # Configuration file
|
||||
my $strStanza; # Stanza in the configuration file to load
|
||||
my $strType; # Type of backup: full, differential (diff), incremental (incr)
|
||||
|
||||
# Test parameters - not for general use
|
||||
my $bNoFork = false; # Prevents the archive process from forking when local archiving is enabled
|
||||
|
||||
GetOptions ("config=s" => \$strConfigFile,
|
||||
"stanza=s" => \$strStanza,
|
||||
"type=s" => \$strType)
|
||||
or die("Error in command line arguments\n");
|
||||
"type=s" => \$strType,
|
||||
|
||||
# Test parameters - not for general use
|
||||
"no-fork" => \$bNoFork)
|
||||
or confess("Error in command line arguments\n");
|
||||
|
||||
####################################################################################################################################
|
||||
# Global variables
|
||||
@ -349,9 +355,17 @@ if ($strOperation eq OP_ARCHIVE_PUSH)
|
||||
}
|
||||
|
||||
# Fork and exit the parent process so the async process can continue
|
||||
if (fork())
|
||||
if (!$bNoFork)
|
||||
{
|
||||
remote_exit(0);
|
||||
if (fork())
|
||||
{
|
||||
remote_exit(0);
|
||||
}
|
||||
}
|
||||
# Else the no-fork flag has been specified for testing
|
||||
else
|
||||
{
|
||||
&log(INFO, "No fork on archive local for TESTING");
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,6 +385,7 @@ if ($strOperation eq OP_ARCHIVE_PUSH)
|
||||
&log(DEBUG, "archive-push process is already running - exiting");
|
||||
remote_exit(0);
|
||||
}
|
||||
|
||||
# Build the basic command string that will be used to modify the command during processing
|
||||
my $strCommand = $^X . " " . $0 . " --stanza=${strStanza}";
|
||||
|
||||
@ -404,16 +419,16 @@ if ($strOperation eq OP_ARCHIVE_PUSH)
|
||||
config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_THREAD_TIMEOUT)
|
||||
);
|
||||
|
||||
# Call the archive_pull function Continue to loop as long as there are files to process.
|
||||
# Call the archive_xfer function and continue to loop as long as there are files to process
|
||||
my $iLogTotal;
|
||||
|
||||
while (!defined($iLogTotal) || $iLogTotal > 0)
|
||||
{
|
||||
$iLogTotal = archive_pull($strArchivePath . "/archive/${strStanza}", $strStopFile, $strCommand, $iArchiveMaxMB);
|
||||
$iLogTotal = archive_xfer($strArchivePath . "/archive/${strStanza}", $strStopFile, $strCommand, $iArchiveMaxMB);
|
||||
|
||||
if ($iLogTotal > 0)
|
||||
{
|
||||
&log(DEBUG, "${iLogTotal} archive logs were transferred, calling archive_pull() again");
|
||||
&log(DEBUG, "${iLogTotal} archive logs were transferred, calling archive_xfer() again");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ use BackRest::Db;
|
||||
|
||||
use Exporter qw(import);
|
||||
|
||||
our @EXPORT = qw(backup_init backup_thread_kill archive_push archive_pull archive_get archive_compress
|
||||
our @EXPORT = qw(backup_init backup_thread_kill archive_push archive_xfer archive_get archive_compress
|
||||
backup backup_expire archive_list_get);
|
||||
|
||||
my $oDb;
|
||||
@ -302,9 +302,9 @@ sub archive_push
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# ARCHIVE_PULL
|
||||
# ARCHIVE_xfer
|
||||
####################################################################################################################################
|
||||
sub archive_pull
|
||||
sub archive_xfer
|
||||
{
|
||||
my $strArchivePath = shift;
|
||||
my $strStopFile = shift;
|
||||
@ -384,13 +384,12 @@ sub archive_pull
|
||||
# Construct the archive filename to backup
|
||||
my $strArchiveFile = "${strArchivePath}/${strFile}";
|
||||
|
||||
&log(INFO, "backing up archive file ${strFile}");
|
||||
|
||||
# Determine if the source file is already compressed
|
||||
my $bSourceCompressed = $strArchiveFile =~ "^.*\.$oFile->{strCompressExtension}\$";
|
||||
my $bSourceCompressed = $strArchiveFile =~ "^.*\.$oFile->{strCompressExtension}\$" ? true : false;
|
||||
|
||||
# Determine if this is an archive file (don't want to do compression or checksum on .backup files)
|
||||
my $bArchiveFile = basename($strArchiveFile) =~ /^[0-F]{24}$/ ? true : false;
|
||||
my $bArchiveFile = basename($strFile) =~
|
||||
"^[0-F]{24}(-[0-f]+){0,1}(\\.$oFile->{strCompressExtension}){0,1}\$" ? true : false;
|
||||
|
||||
# Figure out whether the compression extension needs to be added or removed
|
||||
my $bDestinationCompress = $bArchiveFile && $bCompress;
|
||||
@ -405,6 +404,9 @@ sub archive_pull
|
||||
$strDestinationFile = substr($strDestinationFile, 0, length($strDestinationFile) - 3);
|
||||
}
|
||||
|
||||
&log(DEBUG, "backup archive file ${strFile}, archive ${bArchiveFile}, source_compressed = ${bSourceCompressed}, " .
|
||||
"destination_compress ${bDestinationCompress}, default_compress = ${bCompress}");
|
||||
|
||||
# Copy the archive file
|
||||
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveFile, # Source file
|
||||
PATH_BACKUP_ARCHIVE, $strDestinationFile, # Destination file
|
||||
|
@ -98,9 +98,11 @@ sub BackRestTestBackup_Drop
|
||||
sub BackRestTestBackup_Create
|
||||
{
|
||||
my $bRemote = shift;
|
||||
my $bCluster = shift;
|
||||
|
||||
# Set defaults
|
||||
$bRemote = defined($bRemote) ? $bRemote : false;
|
||||
$bCluster = defined($bCluster) ? $bCluster : true;
|
||||
|
||||
# Drop the old test directory
|
||||
BackRestTestBackup_Drop();
|
||||
@ -133,7 +135,10 @@ sub BackRestTestBackup_Create
|
||||
}
|
||||
|
||||
# Create the cluster
|
||||
BackRestTestBackup_ClusterCreate(BackRestTestCommon_DbCommonPathGet(), BackRestTestCommon_DbPortGet());
|
||||
if ($bCluster)
|
||||
{
|
||||
BackRestTestBackup_ClusterCreate(BackRestTestCommon_DbCommonPathGet(), BackRestTestCommon_DbPortGet());
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
@ -162,6 +167,28 @@ sub BackRestTestBackup_Test
|
||||
# Print test banner
|
||||
&log(INFO, "BACKUP MODULE ******************************************************************");
|
||||
|
||||
if ($strTest eq 'all' || $strTest eq 'archive')
|
||||
{
|
||||
$iRun = 0;
|
||||
|
||||
&log(INFO, "Test Full Backup\n");
|
||||
|
||||
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
||||
{
|
||||
BackRestTestBackup_Create($bRemote, false);
|
||||
|
||||
for (my $bArchiveLocal = false; $bArchiveLocal <= $bRemote; $bArchiveLocal++)
|
||||
{
|
||||
$iRun++;
|
||||
|
||||
# &log(INFO, "run ${iRun} - " .
|
||||
# "remote ${bRemote}, archive_local ${bArchiveLocal}, full ${iFull}");
|
||||
}
|
||||
|
||||
# BackRestTestBackup_Drop();
|
||||
}
|
||||
}
|
||||
|
||||
if ($strTest eq 'all' || $strTest eq 'full')
|
||||
{
|
||||
$iRun = 0;
|
||||
@ -187,6 +214,11 @@ sub BackRestTestBackup_Test
|
||||
$oBackupConfigHash{'global:backup'}{hardlink} = 'y';
|
||||
}
|
||||
|
||||
# if (!$bArchiveLocal)
|
||||
# {
|
||||
# next;
|
||||
# }
|
||||
|
||||
BackRestTestCommon_ConfigCreate('db',
|
||||
($bRemote ? REMOTE_BACKUP : undef), $bArchiveLocal, \%oDbConfigHash);
|
||||
BackRestTestCommon_ConfigCreate('backup',
|
||||
@ -203,6 +235,7 @@ sub BackRestTestBackup_Test
|
||||
"/pg_backrest.conf --type=incr --stanza=${strStanza} backup";
|
||||
|
||||
BackRestTestCommon_Execute($strCommand, $bRemote);
|
||||
# exit 0;
|
||||
|
||||
for (my $iIncr = 1; $iIncr <= 1; $iIncr++)
|
||||
{
|
||||
|
@ -140,12 +140,6 @@ sub BackRestTestCommon_ConfigCreate
|
||||
{
|
||||
$oParamHash{'global:backup'}{'host'} = $strCommonHost;
|
||||
$oParamHash{'global:backup'}{'user'} = $strCommonUserBackRest;
|
||||
|
||||
# if ($bArchiveLocal)
|
||||
# {
|
||||
# $oParamHash{'global:archive'}{'host'} = $strCommonHost;
|
||||
# $oParamHash{'global:archive'}{'user'} = $strCommonUserBackRest;
|
||||
# }
|
||||
}
|
||||
elsif (defined($strRemote) && $strRemote eq REMOTE_DB)
|
||||
{
|
||||
@ -161,7 +155,7 @@ sub BackRestTestCommon_ConfigCreate
|
||||
elsif ($strLocal eq REMOTE_DB)
|
||||
{
|
||||
$oParamHash{'global:log'}{'level-console'} = 'trace';
|
||||
$oParamHash{'global:backup'}{compress} = 'n';
|
||||
# $oParamHash{'global:backup'}{compress} = 'n';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -171,7 +165,7 @@ sub BackRestTestCommon_ConfigCreate
|
||||
if ($bArchiveLocal)
|
||||
{
|
||||
$oParamHash{'global:archive'}{path} = BackRestTestCommon_ArchivePathGet();
|
||||
$oParamHash{'global:archive'}{compress} = 'n';
|
||||
# $oParamHash{'global:archive'}{compress} = 'n';
|
||||
}
|
||||
|
||||
$oParamHash{$strCommonStanza}{'path'} = $strCommonDbCommonPath;
|
||||
|
Loading…
Reference in New Issue
Block a user