From: Eric Bollengier Date: Thu, 6 Mar 2008 08:59:57 +0000 (+0000) Subject: ebl Add bcheck.pl X-Git-Tag: Release-3.0.0~1751 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=addd2946f08f19a0bd9c3419e82887a15e4a4389;p=bacula%2Fbacula ebl Add bcheck.pl Fix btime.pl git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6539 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/gui/bweb/cgi/btime.pl b/gui/bweb/cgi/btime.pl index 6b682e130f..ee75074c2d 100755 --- a/gui/bweb/cgi/btime.pl +++ b/gui/bweb/cgi/btime.pl @@ -47,7 +47,7 @@ $conf->load(); my $bweb = new Bweb(info => $conf); $bweb->can_do('r_view_stat'); -my $arg = $bweb->get_form(qw/qiso_begin qiso_end qusage qpools qpoolusage qnojob +my $arg = $bweb->get_form(qw/qnocache qiso_begin qiso_end qusage qpools qpoolusage qnojob jclient_groups db_client_groups qclient_groups/); my ($filter1, undef) = $bweb->get_param('pool'); @@ -62,7 +62,7 @@ my $md5_rep = md5_hex("$arg->{qiso_begin}:$arg->{qiso_end}:$arg->{qusage}:" . print CGI::header('text/html'); $bweb->display_begin(); -if ($arg->{qiso_begin} && -f "$conf->{fv_write_path}/$md5_rep.png") { +if (!$arg->{qnocache} && $arg->{qiso_begin} && -f "$conf->{fv_write_path}/$md5_rep.png") { $arg->{result} = "/bweb/fv/$md5_rep.png"; $bweb->display($arg, 'btime.tpl'); @@ -86,6 +86,17 @@ my $reg = $bweb->{sql}->{MATCH}; my %regs = ( + end_job => ': Bacula', + start_job => ': Start Backup|: D.marrage du ', + data_despool_time => ': Despooling elapsed time|: Temps du tran', + attr_despool_time => ': Sending spooled attrs|: Transfert des attributs', + get_drive => ': Using Device', + start_spool => ': Spooling', + end_spool => ': User specified spool|: Taille du spool', + end_spool2 => ': Committing spooled data to|: Transfert des donn', + ); + +my %regs_en = ( end_job => ': Bacula', start_job => ': Start Backup', data_despool_time => ': Despooling elapsed time', @@ -135,7 +146,7 @@ FROM Log INNER JOIN Job USING (JobId) JOIN Pool USING (PoolId) ORDER BY Job.JobId,Log.LogId,Log.Time "; -print STDERR $query if ($conf->{debug}); +print STDERR $query if (1 || $conf->{debug}); my $all = $bweb->dbh_selectall_arrayref($query); my $lastid = 0; @@ -174,10 +185,10 @@ foreach my $elt (@$all) # end => $elt->[1], # }; # - } elsif ($elt->[2] =~ /$regs{get_drive} "([\w\d]+)"/) { + } elsif ($elt->[2] =~ /(?:$regs{get_drive}) "([\w\d]+)"/) { $drive = $1; - } elsif ($elt->[2] =~ /$regs{data_despool_time}.+? = (\d+):(\d+):(\d+)/) { + } elsif ($elt->[2] =~ /(?:$regs{data_despool_time}).*? = (\d+):(\d+):(\d+)/) { # on connait le temps de despool my $t = $1*60*60+ $2*60 + $3; diff --git a/gui/bweb/script/bcheck.pl b/gui/bweb/script/bcheck.pl new file mode 100644 index 0000000000..2b94a51cb4 --- /dev/null +++ b/gui/bweb/script/bcheck.pl @@ -0,0 +1,187 @@ +#!/usr/bin/perl -w + +=head1 DESCRIPTION + + +=head2 USAGE + + bcheck.pl [client=yes] + +=head1 LICENSE + + Bweb - A Bacula web interface + Bacula® - The Network Backup Solution + + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + + The main author of Bweb is Eric Bollengier. + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation plus additions + that are listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich, + Switzerland, email:ftf@fsfeurope.org. + +=cut + +use strict ; +use Getopt::Long ; +use Data::Dumper ; +use Bweb; +use CGI; +my $verbose; + +my $conf = new Bweb::Config(config_file => $Bweb::config_file); +$conf->load(); +my $bweb = new Bweb(info => $conf); + +my $b = $bweb->get_bconsole(); +my $ret = $b->director_get_sched(1); + +if (CGI::param('client')) { + + print " +Check clients +-------------\n"; + +# check for next backup that client are online + foreach my $elt (@$ret) { + next unless ($elt->{name}); + + my $job = $b->send_cmd("show job=\"$elt->{name}\""); + my $obj = $bweb->run_parse_job($job); + +# print "I: test $obj->{client}\n" if $verbose; + next unless ($obj->{client}); + my $out = $b->send_cmd("st client=\"$obj->{client}\""); + if ($out !~ /Daemon started/m or $out !~ /^ Heap:/m) { + print "E: Can't connect to $obj->{client}\n"; + } + exit 0; + } +} + +print " +Check for backup size +---------------------\n"; + +my $arg = $bweb->get_form('age', 'since'); +my ($limit, $label) = $bweb->get_limit(age => $arg->{age}, + since => $arg->{since}); +my $query = " +SELECT Job.ClientId AS c0, Job.Name AS c1, + Client.Name AS c2 + FROM Job JOIN Client USING (ClientId) + WHERE Type = 'B' + AND JobStatus = 'T' + AND Level = 'F' + $limit + GROUP BY Job.Name,Job.ClientId,Client.Name +"; + +my $old = $bweb->dbh_selectall_arrayref($query); + +foreach my $elt (@$old) { + $elt->[1] = $bweb->dbh_quote($elt->[1]); + $query = " +SELECT JobId AS jobid, JobBytes AS jobbytes + FROM Job + WHERE Type = 'B' + AND JobStatus = 'T' + AND Level = 'F' + AND Job.ClientId = $elt->[0] + AND Job.Name = $elt->[1] + $limit + ORDER BY StartTime DESC + LIMIT 1 +"; + + my $last_bkp = $bweb->dbh_selectrow_hashref($query); + + $query = " +SELECT COUNT(1) as nbjobs, AVG(JobBytes) as nbbytes + FROM + (SELECT StartTime,JobBytes + FROM Job + WHERE JobId < $last_bkp->{jobid} + AND Type = 'B' + AND JobStatus = 'T' + AND Level = 'F' + AND ClientId = $elt->[0] + AND Job.Name = $elt->[1] + ORDER BY JobId DESC + LIMIT 4 + ) AS T +"; + + my $avg_bkp = $bweb->dbh_selectrow_hashref($query); + + if ($avg_bkp->{nbjobs} > 3) { + if ($last_bkp->{jobbytes} > ($avg_bkp->{nbbytes} * 1.2)) { + print "W: Last backup $elt->[1] on $elt->[2] is greater than 20% (last=", + &Bweb::human_size($last_bkp->{jobbytes}), " avg=", + &Bweb::human_size($avg_bkp->{nbbytes}), ")\n"; + } + if ($last_bkp->{jobbytes} < ($avg_bkp->{nbbytes} * 0.8)) { + print "W: Last backup $elt->[1] on $elt->[2] is lower than 20% (last=", + &Bweb::human_size($last_bkp->{jobbytes}), " avg=", + &Bweb::human_size($avg_bkp->{nbbytes}), ")\n"; + } + } +} +print " +Check missing backup for 2 weeks +---------------------------------\n"; + +# we check that each job have been run one time for 2 weeks +my @jobs = $b->list_job(); +($limit, $label) = $bweb->get_limit(age => 2*7*24*60*60); + +foreach my $j (@jobs) { + + $j = $bweb->dbh_quote($j); + $query = " +SELECT 1 as run + FROM Job + WHERE Type = 'B' + AND JobStatus = 'T' + AND Job.Name = $j +$limit +LIMIT 1 +"; + my $row = $bweb->dbh_selectrow_hashref($query); + + if (!$row) { + $query = " +SELECT StartTime AS starttime, Level AS level + FROM Job + WHERE Type = 'B' + AND JobStatus = 'T' + AND Job.Name = $j +LIMIT 1 +"; + $row = $bweb->dbh_selectrow_hashref($query); + print "W: No job for $j "; + if ($row) { + print "($row->{level} $row->{starttime})"; + } + print "\n"; + } +} + diff --git a/gui/bweb/technotes-2.3 b/gui/bweb/technotes-2.3 index 5613d7e4cf..417c1c6e3f 100644 --- a/gui/bweb/technotes-2.3 +++ b/gui/bweb/technotes-2.3 @@ -1,3 +1,13 @@ +07Mar08 +ebl Fix btime.pl + +15Feb08 +ebl Add bcheck.pl script that check various things in + you bacula setup. + - Try to connect to each client + - Reports you big backup size change + - Reports you useless (or unconfigured) Job + 14Feb08 ebl Cleanup some SQL