]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/backupjob-report.php
bacula-web: New getClientInfos() function in bweb class
[bacula/bacula] / gui / bacula-web / backupjob-report.php
1 <?php\r
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright 2010-2011, Davide Franco                                              |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+ 
16 */
17         session_start();
18         include_once( 'config/global.inc.php' );
19
20         $dbSql = new Bweb();
21
22         $backupjob_name                 = "";
23         $backupjob_bytes                = 0;
24         $backupjob_files                = 0;
25
26         $days                           = array();
27         $days_stored_bytes      = array();
28         $days_stored_files      = array();
29
30         // ===============================================================
31         // Get Backup Job name from GET or POST
32         // ===============================================================
33         $http_post = CHttpRequest::getRequestVars( $_POST );
34         $http_get  = CHttpRequest::getRequestVars( $_GET );
35         
36         if( isset( $http_post['backupjob_name'] ) )
37                 $backupjob_name = $http_post['backupjob_name'];
38         elseif( isset( $http_get['backupjob_name'] ) )
39                 $backupjob_name = $http_get['backupjob_name'];
40         else
41                 die( "Please specify a backup job name " );
42
43         // Generate Backup Job report period string
44         $backupjob_period = "From " . date( "Y-m-d", (NOW-WEEK) ) . " to " . date( "Y-m-d", NOW );
45
46         // Calculate total bytes for this period
47         $backupjob_bytes = $dbSql->getStoredBytes( LAST_WEEK, NOW, $backupjob_name );
48         $backupjob_bytes = CUtils::Get_Human_Size( $backupjob_bytes );
49
50         $backupjob_files = $dbSql->getStoredFiles( LAST_WEEK, NOW, $backupjob_name );
51         $backupjob_files = number_format( $backupjob_files, 0, '.', "'");
52
53         // Get the last 7 days interval (start and end)
54         $days = CTimeUtils::getLastDaysIntervals( 7 );
55
56         // ===============================================================
57         // Last 7 days stored Bytes graph
58         // ===============================================================  
59         $graph = new CGraph( "graph2.png" );
60
61         foreach( $days as $day ) {
62                 $stored_bytes            = $dbSql->getStoredBytes( $day['start'], $day['end'], $backupjob_name);
63                 $stored_bytes            = CUtils::Get_Human_Size( $stored_bytes, 1, 'GB', false );
64                 $days_stored_bytes[] = array( date("m-d", $day['start']), $stored_bytes );
65         }
66
67         $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
68         $graph->SetGraphSize( 400, 230 );
69         $graph->SetYTitle( "GB" );
70
71         $graph->Render();
72         $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );   
73
74         // ===============================================================
75         // Getting last 7 days stored files graph
76         // ===============================================================
77         $graph = new CGraph("graph3.png" );
78
79         foreach( $days as $day ) {
80                 $stored_files            = $dbSql->getStoredFiles( $day['start'], $day['end'], $backupjob_name);
81                 $days_stored_files[] = array( date("m-d", $day['start']), $stored_files );
82         }
83
84         $graph->SetData( $days_stored_files, 'bars', 'text-data' );
85         $graph->SetGraphSize( 400, 230 );
86         $graph->SetYTitle( "Files" );
87
88         $graph->Render();
89         $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() );
90
91         // Last 10 jobs
92         $query    = "SELECT JobId, Level, JobFiles, JobBytes, JobStatus, StartTime, EndTime, Name ";  
93         $query   .= "FROM Job ";
94         $query   .= "WHERE Name = '$backupjob_name' ";
95         $query   .= "ORDER BY EndTime DESC ";
96         $query   .= "LIMIT 10 ";
97
98         $jobs           = array();
99         $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' );
100
101         try {
102                 $result = $dbSql->db_link->runQuery( $query );
103           
104                 foreach( $result->fetchAll() as $job )
105                 {
106                         // Job level description
107                         $job['joblevel']        = $joblevel[ $job['level'] ];
108
109                         // Job execution execution time
110                         $job['elapsedtime'] = CTimeUtils::Get_Elapsed_Time( $job['starttime'], $job['endtime'] );
111
112                         // odd and even row
113                         if( count($jobs) % 2)
114                                 $job['row_class'] = 'odd';
115
116                         // Job bytes more easy to read
117                         $job['jobbytes'] = CUtils::Get_Human_Size( $job['jobbytes'] );
118                         $job['jobfiles'] = number_format($job['jobfiles'], 0 , '.', "'");
119
120                         $jobs[] = $job;
121                 } // end while          
122         }catch(PDOExceptin $e) {
123                 CDBError::raiseError($e);
124         }  
125
126         $dbSql->tpl->assign('jobs', $jobs );
127         $dbSql->tpl->assign('backupjob_name', $backupjob_name );
128         $dbSql->tpl->assign('backupjob_period', $backupjob_period );
129         $dbSql->tpl->assign('backupjob_bytes', $backupjob_bytes );
130         $dbSql->tpl->assign('backupjob_files', $backupjob_files );
131
132         // Process and display the template 
133         $dbSql->tpl->display('backupjob-report.tpl'); 
134
135 ?>\r