App-MBUtiny

 view release on metacpan or  search on metacpan

lib/App/MBUtiny.pm  view on Meta::CPAN

                MONTH => sprintf("%02d", $ymd[1]),
                DAY   => sprintf("%02d", $ymd[2]),
                EXT   => value($arc, 'ext') || '',
            );
        my $archive_name = dformat($arcmask, {%maskfmt});
        push @header, ["Backup mask", $arcmask];


        #
        # Checking collectors
        #
        $step = "Collectors checking";
        $self->debug($step);
        my $collector = new App::MBUtiny::Collector(
                collector_config => $self->_getCollector($host),
                dbi => $self->getdbi, # For local storage only
            );
        my $colret = $collector->check;
        if ($collector->error) {
            $self->log_error(sprintf("Collector error: %s", $collector->error));
            push @errors, $collector->error, "";
        }
        $tbl->row(dtf(DATE_FORMAT), $step,
            $collector->error ? "No available collectors" : $colret,
            $collector->error ? 'FAIL' : $colret ? 'PASS' : 'SKIP',
        );


        #
        # Getting information about file on collector
        #
        my %info = $collector->info(name => $name, file => $is_now ? undef : $archive_name);
        if ($collector->error) {
            $self->log_error(sprintf("Collector error: %s", $collector->error));
            push @errors, $collector->error, "";
        }
        if ($info{status}) {
            $archive_name = $info{file} if $is_now;
            push @header, ["Archive name", $archive_name];
            push @header, (
                ["Archive size", $info{size}],
                ["Archive MD5", $info{md5}],
                ["Archive SHA1", $info{sha1}],
            );
        } else {
            push @header, ["Archive name", $archive_name];
        }
        my $archive_file = File::Spec->catfile($self->rstdir, $archive_name);
        push @header, ["Archive file", $archive_file];


        #
        # 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
                        my $md5 = md5sum($file) // "";
                        unless ($md5 eq $info{md5}) {
                            $strg->error(sprintf("File MD5 checksum incorrect: got=%s; expected=%s", $md5, $info{md5}));
                            return 0;
                        }
                    }
                    if ($info{sha1}) { # Valid sha1
                        my $sha1 = sha1sum($file) // "";
                        unless ($sha1 eq $info{sha1}) {
                            $strg->error(sprintf("File SHA1 checksum incorrect: got=%s; expected=%s", $sha1, $info{sha1}));
                            return 0;
                        }
                    }
                    return 1;
                });
        my $test = $storage->test or do {
            $self->log_error($storage->error);
            push @errors, $storage->error;
            $ostat = 0;
        };
        {
            my $j = 0; my $i = 0;
            foreach my $tr ($storage->test_report) {
                my ($st, $vl, $er) = @$tr;
                $j++ if $st && $st > 0;
                $tbl->row(dtf(DATE_FORMAT), sprintf("Testing storage #%d", ++$i),
                    $vl, $st ? $st < 0 ? 'SKIP' : 'PASS' : 'FAIL'
                );
                push @errors, $er if $er;
            }
            $tbl->row(dtf(DATE_FORMAT), $step,
                $j ? sprintf("Will be used %d storages", $j) : "No available storages found",
                $test ? $test < 0 ? 'SKIP' : 'PASS' : 'FAIL'
            );
            push @errors, "" unless $test;
        }


        #
        # File list fetching
        #
        $step = "File list fetching";
        $self->debug($step);
        my @filelist = $storage->list;
        $tbl->row(dtf(DATE_FORMAT), $step,
            join("\n", @filelist) || "No files found",
            $storage->error ? 'FAIL' : @filelist ? 'PASS' : 'SKIP',
        );
        if ($storage->error) {
            $self->log_error($storage->error);



( run in 1.503 second using v1.01-cache-2.11-cpan-39bf76dae61 )