App-MBUtiny
view release on metacpan or search on metacpan
lib/App/MBUtiny.pm view on Meta::CPAN
#
# Testing storages
#
$step = "Storages testing";
$self->debug($step);
my $storage = new App::MBUtiny::Storage(
name => $name, # Backup name
host => $host, # Host config section
path => $self->rstdir, # Where is located restored backup archive
validate => sub {
my $strg = shift; # storage object
my $file = shift; # fetched file
if ($info{size}) { # Valid sizes
my $size = filesize($file) // 0;
unless ($size == $info{size}) {
$strg->error(sprintf("File size incorrect: got=%d; expected=%d", $size, $info{size}));
return 0;
}
}
if ($info{md5}) { # Valid md5
lib/App/MBUtiny/Storage.pm view on Meta::CPAN
name => $name, # Backup name
host => $host, # Host config section
path => "/tmp/mbutiny/files", # Where is located backup archive
fixup => sub {
my $strg = shift; # Storage object
my $oper = shift // 'noop'; # Operation name
my @args = @_;
return 1;
},
validate => sub {
my $strg = shift; # storage object
my $file = shift; # fetched file name
return 1;
},
);
Returns storage object
=head2 cleanup
lib/App/MBUtiny/Storage.pm view on Meta::CPAN
);
}
Returns list of test result for each storage as:
[
[STATUS, NAME, ERROR],
# ...
]
=head2 validate
Callback the "validate" method. This method called automatically
when the get method performs
This method can returns 0 or 1. 0 - validation failed; 1 - validation successful
=head1 HISTORY
See C<Changes> file
=head1 TO DO
lib/App/MBUtiny/Storage.pm view on Meta::CPAN
my $host = $args{host} || {};
my $path = $args{path} || '.';
my $self = bless {
errors => [],
status => 1, # 1 - Ok; 0 - Error
name => $name,
host => $host,
path => $path,
fixup => $args{fixup},
validate=> $args{validate},
storages=> {},
test => {},
list => {},
}, $class;
return $self->init();
}
sub error {
my $cnt = @_;
my $self = shift;
lib/App/MBUtiny/Storage.pm view on Meta::CPAN
}
return (sort {$a cmp $b} uniq(@files));
}
sub fixup {
my $self = shift;
my @ar = @_;
my $fixup = $self->{fixup};
return SKIP unless $fixup && ref($fixup) eq 'CODE';
return $self->$fixup(@ar);
}
sub validate {
my $self = shift;
my @ar = @_;
my $validate = $self->{validate};
return SKIP unless $validate && ref($validate) eq 'CODE';
return $self->$validate(@ar);
}
1;
__END__
lib/App/MBUtiny/Storage/Command.pm view on Meta::CPAN
my $exe_out = execute($cmd_get, undef, \$exe_err);
my $exe_stt = $? >> 8;
if ($exe_stt) {
$self->error(sprintf("Can't execute %s", $cmd_get));
$self->error($exe_out) if $exe_out;
$self->error($exe_err) if $exe_err;
next;
}
# Validate
unless ($self->validate($file)) { # FAIL validation!
$self->error(sprintf("Command storage %s failed: file %s is not valid!", $cmd_get, $file));
next
}
# Done!
return $self->storage_status(STORAGE_SIGN, 1);
}
$self->storage_status(STORAGE_SIGN, 0);
$self->maybe::next::method(%params);
lib/App/MBUtiny/Storage/FTP.pm view on Meta::CPAN
$ftp->quit if $ftp;
# Check size
my $dst_size = filesize($file) // 0;
unless ($src_size == $dst_size) {
$self->error(sprintf("An error occurred while fetching data from %s. Sizes are different: SRC=%d; DST=%d", $url_wop, $src_size, $dst_size));
next;
}
# Validate
unless ($self->validate($file)) { # FAIL validation!
$self->error(sprintf("FTP storage %s failed: file %s is not valid!", $url_wop, $file));
next
}
# Done!
return $self->storage_status(STORAGE_SIGN, 1);
}
$self->storage_status(STORAGE_SIGN, 0);
$self->maybe::next::method(%params);
lib/App/MBUtiny/Storage/HTTP.pm view on Meta::CPAN
if (my $res = $client->res) {
$src_size = $res->content_length || 0
}
my $dst_size = filesize($file) // 0;
unless ($src_size == $dst_size) {
$self->error(sprintf("An error occurred while fetching data from %s. Sizes are different: SRC=%d; DST=%d", $url_wop, $src_size, $dst_size));
next;
}
# Validate
unless ($self->validate($file)) { # FAIL validation!
$self->error(sprintf("HTTP storage %s failed: file %s is not valid!", $url_wop, $file));
next
}
# Done!
return $self->storage_status(STORAGE_SIGN, 1);
}
$self->storage_status(STORAGE_SIGN, 0);
$self->maybe::next::method(%params);
lib/App/MBUtiny/Storage/Local.pm view on Meta::CPAN
my $file = $params{file}; # destination archive file path
foreach my $local_node ($self->local_storages) {
my $localdirs = array($local_node, 'localdir') || [];
foreach my $dir (@$localdirs) {
my $src = File::Spec->catfile($dir, $name);
my $src_size = filesize($src) // 0;
if (copy($src, $file)) {
my $dst_size = filesize($file) // 0;
if ($src_size == $dst_size) {
unless ($self->validate($file)) { # FAIL validation!
$self->error(sprintf("Local storage dir %s failed: file %s is not valid!", $dir, $file));
next;
}
return $self->storage_status(STORAGE_SIGN, 1); # Done!
} else {
$self->error(sprintf("Copy \"%s\" to \"%s\" failed: size is different", $src, $file, $!));
}
} else {
$self->error(sprintf("Copy \"%s\" to \"%s\" failed: %s", $src, $file, $!));
};
lib/App/MBUtiny/Storage/SFTP.pm view on Meta::CPAN
unless ($src_size == $dst_size) {
$self->error(sprintf("An error occurred while sending data to %s. Sizes are different: SRC=%d; DST=%d", $url_wop, $src_size, $dst_size));
$sftp->disconnect;
next;
}
# Disconnect
$sftp->disconnect;
# Validate
unless ($self->validate($file)) { # FAIL validation!
$self->error(sprintf("SFTP storage %s failed: file %s is not valid!", $url_wop, $file));
next
}
# Done!
return $self->storage_status(STORAGE_SIGN, 1);
}
$self->storage_status(STORAGE_SIGN, 0);
$self->maybe::next::method(%params);
( run in 1.098 second using v1.01-cache-2.11-cpan-a5abf4f5562 )