pgbackrest.git / summary / log / commit / refs

commit    d12773ca85fb73fedac018aecdc6ea5283ddbd2f
Author:   David Steele <gitlab@thelabyrinth.net>
Date:     Thu Dec 12 01:39:07 2013 +0000

    Added generic config command


pg_backrest.pl | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/pg_backrest.pl b/pg_backrest.pl index 8adcf8f3a..7a05a86d8 100755 --- a/pg_backrest.pl +++ b/pg_backrest.pl @@ -1,10 +1,10 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use strict; +use warnings; use File::Basename; use Getopt::Long; use Config::IniFiles; -#use Readonly; # Process flags my $bNoCompression; @@ -65,6 +65,31 @@ sub execute return($strOutput); } +#################################################################################################################################### +# CONFIG_LOAD - Get a value from the config and be sure that it is defined (unless bRequired is false) +#################################################################################################################################### +sub config_load +{ + my $oConfigRef = shift; + my $strSection = shift; + my $strKey = shift; + my $bRequired = shift; + + if (!defined($bRequired)) + { + $bRequired = 1; + } + + my $strValue = ${$oConfigRef}{"${strSection}"}{"${strKey}"}; + + if ($bRequired && !defined($strValue)) + { + die &log(ERROR, 'config value ${strSection}->${strKey} is undefined'); + } + + return $strValue; +} + #################################################################################################################################### # FILE_HASH_GET - get the sha1 hash for a file #################################################################################################################################### @@ -189,6 +214,11 @@ if (!defined($strConfigFile)) my %oConfig; tie %oConfig, 'Config::IniFiles', (-file => $strConfigFile) or die "Unable to find config file"; +# Load commands required for archive-push +my $strCommandChecksum = config_load(\%oConfig, "command", "checksum", !$bNoChecksum); +my $strCommandCompress = config_load(\%oConfig, "command", "compress", !$bNoCompression); +my $strCommandCopy = config_load(\%oConfig, "command", "copy", $bNoCompression); + #################################################################################################################################### # ARCHIVE-PUSH Command #################################################################################################################################### @@ -226,7 +256,7 @@ if ($strOperation eq "archive-push") # Calculate sha1 hash for the file (unless disabled) if (!$bNoChecksum) { - $strDestinationFile .= "-" . file_hash_get($oConfig{command}{checksum}, $strSourceFile); + $strDestinationFile .= "-" . file_hash_get($strCommandChecksum, $strSourceFile); } # Setup the copy command @@ -234,13 +264,13 @@ if ($strOperation eq "archive-push") if ($bNoCompression) { - $strCommand = $oConfig{command}{copy}; + $strCommand = $strCommandCopy; $strCommand =~ s/\%source\%/$strSourceFile/g; $strCommand =~ s/\%destination\%/$strDestinationFile/g; } else { - $strCommand = $oConfig{command}{compress}; + $strCommand = $strCommandCompress; $strCommand =~ s/\%file\%/$strSourceFile/g; $strCommand .= " > $strDestinationFile.gz"; } @@ -281,13 +311,8 @@ unless (-e $strBackupClusterPath) mkdir $strBackupClusterPath or die &log(ERROR, "cluster backup path '${strBackupClusterPath}' create failed"); } -# Load and check manifest command -my $strCommandManifest = $oConfig{command}{manifest}; - -if (!defined($strCommandManifest)) -{ - die &log(ERROR, "command:manifest undefined"); -} +# Load commands required for backup +my $strCommandManifest = config_load(\%oConfig, "command", "manifest"); #################################################################################################################################### # BACKUP [parent: 4aa480b858bb]