1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Starting on archive unit tests.

This commit is contained in:
David Steele
2014-07-13 10:37:16 -04:00
parent 375545320d
commit 8d398e4bff
4 changed files with 67 additions and 23 deletions

View File

@ -73,10 +73,16 @@ my $strConfigFile; # Configuration file
my $strStanza; # Stanza in the configuration file to load my $strStanza; # Stanza in the configuration file to load
my $strType; # Type of backup: full, differential (diff), incremental (incr) 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, GetOptions ("config=s" => \$strConfigFile,
"stanza=s" => \$strStanza, "stanza=s" => \$strStanza,
"type=s" => \$strType) "type=s" => \$strType,
or die("Error in command line arguments\n");
# Test parameters - not for general use
"no-fork" => \$bNoFork)
or confess("Error in command line arguments\n");
#################################################################################################################################### ####################################################################################################################################
# Global variables # Global variables
@ -349,11 +355,19 @@ if ($strOperation eq OP_ARCHIVE_PUSH)
} }
# Fork and exit the parent process so the async process can continue # Fork and exit the parent process so the async process can continue
if (!$bNoFork)
{
if (fork()) if (fork())
{ {
remote_exit(0); remote_exit(0);
} }
} }
# Else the no-fork flag has been specified for testing
else
{
&log(INFO, "No fork on archive local for TESTING");
}
}
# If no backup host is defined it makes no sense to run archive-push without a specified archive file so throw an error # If no backup host is defined it makes no sense to run archive-push without a specified archive file so throw an error
if (!defined(config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST))) if (!defined(config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_HOST)))
@ -371,6 +385,7 @@ if ($strOperation eq OP_ARCHIVE_PUSH)
&log(DEBUG, "archive-push process is already running - exiting"); &log(DEBUG, "archive-push process is already running - exiting");
remote_exit(0); remote_exit(0);
} }
# Build the basic command string that will be used to modify the command during processing # Build the basic command string that will be used to modify the command during processing
my $strCommand = $^X . " " . $0 . " --stanza=${strStanza}"; 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) 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; my $iLogTotal;
while (!defined($iLogTotal) || $iLogTotal > 0) 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) 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 else
{ {

View File

@ -22,7 +22,7 @@ use BackRest::Db;
use Exporter qw(import); 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); backup backup_expire archive_list_get);
my $oDb; my $oDb;
@ -302,9 +302,9 @@ sub archive_push
} }
#################################################################################################################################### ####################################################################################################################################
# ARCHIVE_PULL # ARCHIVE_xfer
#################################################################################################################################### ####################################################################################################################################
sub archive_pull sub archive_xfer
{ {
my $strArchivePath = shift; my $strArchivePath = shift;
my $strStopFile = shift; my $strStopFile = shift;
@ -384,13 +384,12 @@ sub archive_pull
# Construct the archive filename to backup # Construct the archive filename to backup
my $strArchiveFile = "${strArchivePath}/${strFile}"; my $strArchiveFile = "${strArchivePath}/${strFile}";
&log(INFO, "backing up archive file ${strFile}");
# Determine if the source file is already compressed # 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) # 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 # Figure out whether the compression extension needs to be added or removed
my $bDestinationCompress = $bArchiveFile && $bCompress; my $bDestinationCompress = $bArchiveFile && $bCompress;
@ -405,6 +404,9 @@ sub archive_pull
$strDestinationFile = substr($strDestinationFile, 0, length($strDestinationFile) - 3); $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 # Copy the archive file
$oFile->copy(PATH_DB_ABSOLUTE, $strArchiveFile, # Source file $oFile->copy(PATH_DB_ABSOLUTE, $strArchiveFile, # Source file
PATH_BACKUP_ARCHIVE, $strDestinationFile, # Destination file PATH_BACKUP_ARCHIVE, $strDestinationFile, # Destination file

View File

@ -98,9 +98,11 @@ sub BackRestTestBackup_Drop
sub BackRestTestBackup_Create sub BackRestTestBackup_Create
{ {
my $bRemote = shift; my $bRemote = shift;
my $bCluster = shift;
# Set defaults # Set defaults
$bRemote = defined($bRemote) ? $bRemote : false; $bRemote = defined($bRemote) ? $bRemote : false;
$bCluster = defined($bCluster) ? $bCluster : true;
# Drop the old test directory # Drop the old test directory
BackRestTestBackup_Drop(); BackRestTestBackup_Drop();
@ -133,7 +135,10 @@ sub BackRestTestBackup_Create
} }
# Create the cluster # Create the cluster
if ($bCluster)
{
BackRestTestBackup_ClusterCreate(BackRestTestCommon_DbCommonPathGet(), BackRestTestCommon_DbPortGet()); BackRestTestBackup_ClusterCreate(BackRestTestCommon_DbCommonPathGet(), BackRestTestCommon_DbPortGet());
}
} }
#################################################################################################################################### ####################################################################################################################################
@ -162,6 +167,28 @@ sub BackRestTestBackup_Test
# Print test banner # Print test banner
&log(INFO, "BACKUP MODULE ******************************************************************"); &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') if ($strTest eq 'all' || $strTest eq 'full')
{ {
$iRun = 0; $iRun = 0;
@ -187,6 +214,11 @@ sub BackRestTestBackup_Test
$oBackupConfigHash{'global:backup'}{hardlink} = 'y'; $oBackupConfigHash{'global:backup'}{hardlink} = 'y';
} }
# if (!$bArchiveLocal)
# {
# next;
# }
BackRestTestCommon_ConfigCreate('db', BackRestTestCommon_ConfigCreate('db',
($bRemote ? REMOTE_BACKUP : undef), $bArchiveLocal, \%oDbConfigHash); ($bRemote ? REMOTE_BACKUP : undef), $bArchiveLocal, \%oDbConfigHash);
BackRestTestCommon_ConfigCreate('backup', BackRestTestCommon_ConfigCreate('backup',
@ -203,6 +235,7 @@ sub BackRestTestBackup_Test
"/pg_backrest.conf --type=incr --stanza=${strStanza} backup"; "/pg_backrest.conf --type=incr --stanza=${strStanza} backup";
BackRestTestCommon_Execute($strCommand, $bRemote); BackRestTestCommon_Execute($strCommand, $bRemote);
# exit 0;
for (my $iIncr = 1; $iIncr <= 1; $iIncr++) for (my $iIncr = 1; $iIncr <= 1; $iIncr++)
{ {

View File

@ -140,12 +140,6 @@ sub BackRestTestCommon_ConfigCreate
{ {
$oParamHash{'global:backup'}{'host'} = $strCommonHost; $oParamHash{'global:backup'}{'host'} = $strCommonHost;
$oParamHash{'global:backup'}{'user'} = $strCommonUserBackRest; $oParamHash{'global:backup'}{'user'} = $strCommonUserBackRest;
# if ($bArchiveLocal)
# {
# $oParamHash{'global:archive'}{'host'} = $strCommonHost;
# $oParamHash{'global:archive'}{'user'} = $strCommonUserBackRest;
# }
} }
elsif (defined($strRemote) && $strRemote eq REMOTE_DB) elsif (defined($strRemote) && $strRemote eq REMOTE_DB)
{ {
@ -161,7 +155,7 @@ sub BackRestTestCommon_ConfigCreate
elsif ($strLocal eq REMOTE_DB) elsif ($strLocal eq REMOTE_DB)
{ {
$oParamHash{'global:log'}{'level-console'} = 'trace'; $oParamHash{'global:log'}{'level-console'} = 'trace';
$oParamHash{'global:backup'}{compress} = 'n'; # $oParamHash{'global:backup'}{compress} = 'n';
} }
else else
{ {
@ -171,7 +165,7 @@ sub BackRestTestCommon_ConfigCreate
if ($bArchiveLocal) if ($bArchiveLocal)
{ {
$oParamHash{'global:archive'}{path} = BackRestTestCommon_ArchivePathGet(); $oParamHash{'global:archive'}{path} = BackRestTestCommon_ArchivePathGet();
$oParamHash{'global:archive'}{compress} = 'n'; # $oParamHash{'global:archive'}{compress} = 'n';
} }
$oParamHash{$strCommonStanza}{'path'} = $strCommonDbCommonPath; $oParamHash{$strCommonStanza}{'path'} = $strCommonDbCommonPath;