diff --git a/bin/pg_backrest.pl b/bin/pg_backrest.pl index 5e36d1daa..e76ced37e 100755 --- a/bin/pg_backrest.pl +++ b/bin/pg_backrest.pl @@ -398,12 +398,12 @@ if ($strOperation eq OP_ARCHIVE_PUSH) my $bCompress = $bCompressAsync ? false : config_key_load($strSection, CONFIG_KEY_COMPRESS, true, 'y') eq 'y' ? true : false; # Create the file object - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strRemote => $bArchiveLocal ? REMOTE_NONE : $strRemote, - oRemote => $bArchiveLocal ? undef : remote_get(), - strBackupPath => config_key_load($strSection, CONFIG_KEY_PATH, true) + $strStanza, + config_key_load($strSection, CONFIG_KEY_PATH, true), + $bArchiveLocal ? REMOTE_NONE : $strRemote, + $bArchiveLocal ? undef : remote_get() ); # Init backup @@ -469,12 +469,12 @@ if ($strOperation eq OP_ARCHIVE_PUSH) # eval # { # Create the file object - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strRemote => $strRemote, - oRemote => remote_get(), - strBackupPath => config_key_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true) + $strStanza, + config_key_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true), + $strRemote, + remote_get() ); # Init backup @@ -572,12 +572,12 @@ if ($strOperation eq OP_ARCHIVE_GET) } # Init the file object - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strRemote => $strRemote, - oRemote => remote_get(), - strBackupPath => config_key_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true) + $strStanza, + config_key_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true), + $strRemote, + remote_get() ); # Init the backup object @@ -645,12 +645,12 @@ if (!lock_file_create($strLockPath)) } # Initialize the default file object -my $oFile = BackRest::File->new +my $oFile = new BackRest::File ( - strStanza => $strStanza, - strRemote => $strRemote, - oRemote => remote_get(), - strBackupPath => config_key_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true) + $strStanza, + config_key_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_PATH, true), + $strRemote, + remote_get() ); # Initialize the db object diff --git a/bin/pg_backrest_remote.pl b/bin/pg_backrest_remote.pl index 5430f30b7..6983b45a3 100755 --- a/bin/pg_backrest_remote.pl +++ b/bin/pg_backrest_remote.pl @@ -54,12 +54,15 @@ sub param_get log_level_set(OFF, OFF); # Create the remote object -my $oRemote = BackRest::Remote->new(); +my $oRemote = new BackRest::Remote(); # Create the file object -my $oFile = BackRest::File->new +my $oFile = new BackRest::File ( - oRemote => $oRemote + undef, + undef, + undef, + $oRemote ); # Write the greeting so remote process knows who we are diff --git a/lib/BackRest/Backup.pm b/lib/BackRest/Backup.pm index a398e6956..8a6b40ac7 100644 --- a/lib/BackRest/Backup.pm +++ b/lib/BackRest/Backup.pm @@ -1143,7 +1143,7 @@ sub backup_file } } - # End each thread queue and start the backu_file threads + # End each thread queue and start the backup_file threads for (my $iThreadIdx = 0; $iThreadIdx < $iThreadLocalMax; $iThreadIdx++) { # Output info about how much work each thread is going to do diff --git a/lib/BackRest/Exception.pm b/lib/BackRest/Exception.pm index d8a922117..c908d7104 100644 --- a/lib/BackRest/Exception.pm +++ b/lib/BackRest/Exception.pm @@ -48,4 +48,4 @@ sub message return $self->{strMessage}; } -return 1; +1; diff --git a/lib/BackRest/File.pm b/lib/BackRest/File.pm index eb61c24cd..61c1cc56d 100644 --- a/lib/BackRest/File.pm +++ b/lib/BackRest/File.pm @@ -8,7 +8,6 @@ use strict; use warnings; use Carp; -use Moose; use Net::OpenSSH; use File::Basename; use File::Copy qw(cp); @@ -41,24 +40,6 @@ our @EXPORT = qw(PATH_ABSOLUTE PATH_DB PATH_DB_ABSOLUTE PATH_BACKUP PATH_BACKUP_ OP_FILE_LIST OP_FILE_EXISTS OP_FILE_HASH OP_FILE_REMOVE OP_FILE_MANIFEST OP_FILE_COMPRESS OP_FILE_MOVE OP_FILE_COPY OP_FILE_COPY_OUT OP_FILE_COPY_IN OP_FILE_PATH_CREATE); -# Extension and permissions -has strCompressExtension => (is => 'ro', default => 'gz'); -has strDefaultPathPermission => (is => 'bare', default => '0750'); -has strDefaultFilePermission => (is => 'ro', default => '0640'); - -# Command strings -has strCommand => (is => 'bare'); - -# Module variables -has strRemote => (is => 'bare'); # Remote type (db or backup) -has oRemote => (is => 'bare'); # Remote object - -has strBackupPath => (is => 'bare'); # Backup base path - -# Process flags -has strStanza => (is => 'bare'); -has iThreadIdx => (is => 'bare'); - #################################################################################################################################### # COMMAND Error Constants #################################################################################################################################### @@ -130,9 +111,34 @@ use constant #################################################################################################################################### # CONSTRUCTOR #################################################################################################################################### -sub BUILD +sub new { - my $self = shift; + my $class = shift; + my $strStanza = shift; + my $strBackupPath = shift; + my $strRemote = shift; + my $oRemote = shift; + my $strDefaultPathPermission = shift; + my $strDefaultFilePermission = shift; + my $iThreadIdx = shift; + + # Create the class hash + my $self = {}; + bless $self, $class; + + # Default compression extension to gz + $self->{strCompressExtension} = 'gz'; + + # Default file and path permissions + $self->{strDefaultPathPermission} = defined($strDefaultPathPermission) ? $strDefaultPathPermission : '0750'; + $self->{strDefaultFilePermission} = defined($strDefaultFilePermission) ? $strDefaultFilePermission : '0640'; + + # Initialize other variables + $self->{strStanza} = $strStanza; + $self->{strBackupPath} = $strBackupPath; + $self->{strRemote} = $strRemote; + $self->{oRemote} = $oRemote; + $self->{iThreadIdx} = $iThreadIdx; # If remote is defined check parameters and open session if (defined($self->{strRemote}) && $self->{strRemote} ne REMOTE_NONE) @@ -140,7 +146,8 @@ sub BUILD # Make sure remote is valid if ($self->{strRemote} ne REMOTE_DB && $self->{strRemote} ne REMOTE_BACKUP) { - confess &log(ASSERT, 'strRemote must be "' . REMOTE_DB . '" or "' . REMOTE_BACKUP . '"'); + confess &log(ASSERT, 'strRemote must be "' . REMOTE_DB . '" or "' . REMOTE_BACKUP . + "\", $self->{strRemote} was passed"); } # Remote object must be set @@ -149,6 +156,8 @@ sub BUILD confess &log(ASSERT, 'oRemote must be defined'); } } + + return $self; } #################################################################################################################################### @@ -179,12 +188,13 @@ sub clone return BackRest::File->new ( - strCommand => $self->{strCommand}, - strRemote => $self->{strRemote}, - oRemote => defined($self->{oRemote}) ? $self->{oRemote}->clone($iThreadIdx) : undef, - strBackupPath => $self->{strBackupPath}, - strStanza => $self->{strStanza}, - iThreadIdx => $iThreadIdx + $self->{strStanza}, + $self->{strBackupPath}, + $self->{strRemote}, + defined($self->{oRemote}) ? $self->{oRemote}->clone() : undef, + $self->{strDefaultPathPermission}, + $self->{strDefaultFilePermission}, + $iThreadIdx ); } @@ -1467,5 +1477,4 @@ sub copy return true; } -no Moose; -__PACKAGE__->meta->make_immutable; +1; diff --git a/lib/BackRest/ProcessAsync.pm b/lib/BackRest/ProcessAsync.pm index 6233dd7fd..b6eb26953 100644 --- a/lib/BackRest/ProcessAsync.pm +++ b/lib/BackRest/ProcessAsync.pm @@ -216,4 +216,4 @@ sub process_end } } -true; +1; diff --git a/lib/BackRest/Remote.pm b/lib/BackRest/Remote.pm index 0551214d7..870a9b275 100644 --- a/lib/BackRest/Remote.pm +++ b/lib/BackRest/Remote.pm @@ -718,4 +718,4 @@ sub command_execute return $self->output_read($bOutputRequired, $strErrorPrefix); } -return true; +1; diff --git a/test/lib/BackRestTest/BackupTest.pm b/test/lib/BackRestTest/BackupTest.pm index 9c35a18ac..ab2fc1f0d 100755 --- a/test/lib/BackRestTest/BackupTest.pm +++ b/test/lib/BackRestTest/BackupTest.pm @@ -294,12 +294,12 @@ sub BackRestTestBackup_Test if ($bCreate) { # Create the file object - $oFile = (BackRest::File->new + $oFile = (new BackRest::File ( - strStanza => $strStanza, - strBackupPath => BackRestTestCommon_BackupPathGet(), - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + BackRestTestCommon_BackupPathGet(), + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ))->clone(); BackRestTestBackup_Create($bRemote, false); @@ -426,10 +426,10 @@ sub BackRestTestBackup_Test # Create the file object $oFile = (BackRest::File->new ( - strStanza => $strStanza, - strBackupPath => BackRestTestCommon_BackupPathGet(), - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + BackRestTestCommon_BackupPathGet(), + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ))->clone(); BackRestTestBackup_Create($bRemote, false); diff --git a/test/lib/BackRestTest/FileTest.pm b/test/lib/BackRestTest/FileTest.pm index acbc521a5..51c375ea2 100755 --- a/test/lib/BackRestTest/FileTest.pm +++ b/test/lib/BackRestTest/FileTest.pm @@ -109,13 +109,13 @@ sub BackRestTestFile_Test for (my $bRemote = 0; $bRemote <= 1; $bRemote++) { # Create the file object - my $oFile = (BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef - ))->clone(); + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef + ); # Loop through error for (my $bError = 0; $bError <= 1; $bError++) @@ -217,13 +217,13 @@ sub BackRestTestFile_Test for (my $bRemote = 0; $bRemote <= 0; $bRemote++) { # Create the file object - my $oFile = BackRest::File->new + my $oFile = (new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef - ); + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef + ))->clone(1); # Loop through source exists for (my $bSourceExists = 0; $bSourceExists <= 1; $bSourceExists++) @@ -316,12 +316,12 @@ sub BackRestTestFile_Test for (my $bRemote = 0; $bRemote <= 0; $bRemote++) { # Create the file object - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ); # Loop through exists @@ -419,12 +419,12 @@ sub BackRestTestFile_Test for (my $bRemote = 0; $bRemote <= 1; $bRemote++) { # Create the file object - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ); for (my $bError = 0; $bError <= 1; $bError++) @@ -561,12 +561,12 @@ sub BackRestTestFile_Test for (my $bRemote = false; $bRemote <= true; $bRemote++) { # Create the file object - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ); for (my $bSort = false; $bSort <= true; $bSort++) @@ -687,12 +687,12 @@ sub BackRestTestFile_Test for (my $bRemote = 0; $bRemote <= 1; $bRemote++) { - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ); # Loop through exists @@ -790,12 +790,12 @@ sub BackRestTestFile_Test for (my $bRemote = false; $bRemote <= true; $bRemote++) { - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ); # Loop through error @@ -880,12 +880,12 @@ sub BackRestTestFile_Test for (my $bRemote = 0; $bRemote <= 1; $bRemote++) { - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $bRemote ? 'backup' : undef, - oRemote => $bRemote ? $oRemote : undef + $strStanza, + $strTestPath, + $bRemote ? 'backup' : undef, + $bRemote ? $oRemote : undef ); # Loop through exists @@ -978,12 +978,12 @@ sub BackRestTestFile_Test my $strRemote = $bBackupRemote ? 'backup' : $bDbRemote ? 'db' : undef; # Create the file object - my $oFile = BackRest::File->new + my $oFile = new BackRest::File ( - strStanza => $strStanza, - strBackupPath => $strTestPath, - strRemote => $strRemote, - oRemote => defined($strRemote) ? $oRemote : undef + $strStanza, + $strTestPath, + $strRemote, + defined($strRemote) ? $oRemote : undef ); # Loop through source compression