From eb4e71af55e3fbd002dc1fb1f9e1a45f0176096e Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 11 Mar 2008 13:03:10 +0000 Subject: [PATCH] ebl Fix JobFiles estimation (we use only Full backup) git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6583 91ce42f0-d328-0410-95d8-f526ca767f89 --- gui/bweb/lib/Bweb.pm | 95 ++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/gui/bweb/lib/Bweb.pm b/gui/bweb/lib/Bweb.pm index b4ab538517..0d8212a672 100644 --- a/gui/bweb/lib/Bweb.pm +++ b/gui/bweb/lib/Bweb.pm @@ -3875,74 +3875,99 @@ GROUP BY VolStatus "display_pool.tpl"); } -sub display_running_job +# With this function, we get an estimation of next jobfiles/jobbytes count +sub get_estimate_query { - my ($self) = @_; - return if $self->cant_do('r_view_running_job'); - - my $arg = $self->get_form('jobid'); - - return $self->error("Can't get jobid") unless ($arg->{jobid}); - + my ($self, $mode, $job, $level) = @_; # get security filter my $filter = $self->get_client_filter(); - my $query = " -SELECT Client.Name AS name, Job.Name AS jobname, - Job.Level AS level -FROM Job INNER JOIN Client USING (ClientId) $filter -WHERE Job.JobId = $arg->{jobid} -"; - - my $row = $self->dbh_selectrow_hashref($query); - - if ($row) { - $arg->{client} = $row->{name}; - } else { - return $self->error("Can't get client"); - } - - if ($self->dbh_is_mysql()) { # mysql doesn't have statistics functions + my $query; + + if (1 || $self->dbh_is_mysql()) { # mysql doesn't have statistics functions $query = " SELECT jobname AS jobname, 0.1 AS corr_jobbytes, AVG(jobbytes) AS jobbytes, - 0.1 AS corr_jobfiles, AVG(jobfiles) AS jobfiles, - COUNT(1) AS nb "; + COUNT(1) AS nb_jobbytes "; } else { # postgresql have functions that permit to handle lineal regression # in y=ax + b # REGR_SLOPE(Y,X) = get x # REGR_INTERCEPT(Y,X) = get b # and we need y when x=now() - # CORR gives the correlation (TODO: display progress bar only if CORR > 0.8) + # CORR gives the correlation + # (TODO: display progress bar only if CORR > 0.8) my $now = scalar(time); $query = " SELECT temp.jobname AS jobname, CORR(jobbytes,jobtdate) AS corr_jobbytes, - ($now*REGR_SLOPE(jobbytes,jobtdate) + REGR_INTERCEPT(jobbytes,jobtdate)) AS jobbytes, - CORR(jobfiles,jobtdate) AS corr_jobfiles, - ($now*REGR_SLOPE(jobfiles,jobtdate) + REGR_INTERCEPT(jobfiles,jobtdate)) AS jobfiles, - COUNT(1) AS nb "; + ($now*REGR_SLOPE(jobbytes,jobtdate) + + REGR_INTERCEPT(jobbytes,jobtdate)) AS jobbytes, + COUNT(1) AS nb_jobbytes "; } $query .= " FROM ( SELECT Job.Name AS jobname, JobBytes AS jobbytes, - JobFiles AS jobfiles, JobTDate AS jobtdate FROM Job INNER JOIN Client USING (ClientId) $filter - WHERE Job.Name = '$row->{jobname}' - AND Job.Level = '$row->{level}' + WHERE Job.Name = '$job' + AND Job.Level = '$level' AND Job.JobStatus = 'T' ORDER BY StartTime DESC LIMIT 4 ) AS temp GROUP BY temp.jobname "; + + if ($mode eq 'jobfiles') { + $query =~ s/jobbytes/jobfiles/g; + $query =~ s/JobBytes/JobFiles/g; + } + return $query; +} + +sub display_running_job +{ + my ($self) = @_; + return if $self->cant_do('r_view_running_job'); + + my $arg = $self->get_form('jobid'); + + return $self->error("Can't get jobid") unless ($arg->{jobid}); + + # get security filter + my $filter = $self->get_client_filter(); + + my $query = " +SELECT Client.Name AS name, Job.Name AS jobname, + Job.Level AS level +FROM Job INNER JOIN Client USING (ClientId) $filter +WHERE Job.JobId = $arg->{jobid} +"; + + my $row = $self->dbh_selectrow_hashref($query); + + if ($row) { + $arg->{client} = $row->{name}; + } else { + return $self->error("Can't get client"); + } + # for jobfiles, we use only last Full backup. status client= returns + # all files that have been checked + my $query1 = $self->get_estimate_query('jobfiles', $row->{jobname}, 'F'); + my $query2 = $self->get_estimate_query('jobbytes', + $row->{jobname}, $row->{level}); + + # LEFT JOIN because we always have a previous Full + $query = " +SELECT corr_jobbytes, jobbytes, corr_jobfiles, jobfiles + FROM ($query1) AS A LEFT JOIN ($query2) AS B USING (jobname) +"; $row = $self->dbh_selectrow_hashref($query); - if (!$row or $row->{nb} == 0) { + if (!$row) { $row->{jobbytes} = $row->{jobfiles} = 0; } my $cli = new Bweb::Client(name => $arg->{client}); -- 2.39.5