]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/backupjob-report.php
5918aec36d15a77edbcddd85f6feee1bea558871
[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();\r
18   include_once( 'config.inc.php' );
19 \r
20   $dbSql = new Bweb();\r
21 \r
22   $backupjob_name               = "";
23   $backupjob_bytes              = 0;
24   $backupjob_files              = 0;
25 \r
26   $days                                 = array();
27   $days_stored_bytes    = array();
28   $days_stored_files    = array();
29
30   // ===============================================================
31   // Get Backup Job name from GET or POST\r
32   // ===============================================================
33   if( isset( $_POST["backupjob_name"] ) )\r
34     $backupjob_name = $_POST["backupjob_name"];\r
35   elseif( isset( $_GET["backupjob_name"] ) )\r
36         $backupjob_name = $_GET["backupjob_name"];\r
37   else\r
38         die( "Please specify a backup job name " );\r
39 \r
40   // Get the last 7 days interval (start and end)\r
41   for( $c = 6 ; $c >= 0 ; $c-- ) {\r
42           $today = ( mktime() - ($c * LAST_DAY) );\r
43           array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );\r
44   }\r
45   
46   // Generate Backup Job report period string\r
47   $backupjob_period = "From " . date( "Y-m-d", mktime()-LAST_WEEK ) . " to " . date( "Y-m-d", mktime() );\r
48   
49   // ===============================================================
50   // Last 7 days stored Bytes graph\r
51   // ===============================================================  
52   $graph = new BGraph( "graph2.png" );\r
53 \r
54   foreach( $days as $day )\r
55     array_push( $days_stored_bytes, $dbSql->GetStoredBytesByJob( $backupjob_name, $day['start'], $day['end'] ) );\r
56  \r
57   // Calculate total bytes for this period\r
58   foreach( $days_stored_bytes as $day )\r
59         $backupjob_bytes += $day[1];\r
60         \r
61   $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );\r
62   $graph->SetGraphSize( 400, 230 );\r
63   $graph->SetYTitle( "GB" );
64 \r
65   $graph->Render();\r
66   $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() ); 
67   \r
68   // ===============================================================
69   // Getting last 7 days stored files graph\r
70   // ===============================================================
71   $graph = new BGraph("graph3.png" );\r
72   \r
73   foreach( $days as $day )\r
74     array_push( $days_stored_files, $dbSql->GetStoredFilesByJob( $backupjob_name, $day['start'], $day['end'] ) );\r
75 \r
76   // Calculate total files for this period      \r
77   foreach( $days_stored_files as $day )\r
78         $backupjob_files += $day[1];\r
79   \r
80   $graph->SetData( $days_stored_files, 'bars', 'text-data' );\r
81   $graph->SetGraphSize( 400, 230 );\r
82   $graph->SetYTitle( "Files" );
83 \r
84   $graph->Render();\r
85   $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() );
86 \r
87   // Last 10 jobs\r
88   $query    = "SELECT JobId, Level, JobFiles, JobBytes, JobStatus, EndTime, Name ";  \r
89   $query   .= "FROM Job ";\r
90   $query   .= "WHERE Name = '$backupjob_name' ";\r
91   $query   .= "ORDER BY EndTime DESC ";\r
92   $query   .= "LIMIT 10 ";\r
93   \r
94   $jobs         = array();\r
95   $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' );\r
96   $result       = $dbSql->db_link->query( $query );\r
97   \r
98   if( ! PEAR::isError( $result ) )\r
99   {\r
100         while( $job = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {\r
101                 $job['Level'] = $joblevel[ $job['Level'] ];\r
102                 array_push( $jobs, $job);\r
103         }               
104   }else\r
105         die( "Unable to get last jobs from catalog " . $result->getMessage() );\r
106     \r
107   $dbSql->tpl->assign('jobs', $jobs );
108   $dbSql->tpl->assign('backupjob_name', $backupjob_name );
109   $dbSql->tpl->assign('backupjob_period', $backupjob_period );
110   $dbSql->tpl->assign('backupjob_bytes', $backupjob_bytes );
111   $dbSql->tpl->assign('backupjob_files', $backupjob_files );
112   \r
113   // Process and display the template \r
114   $dbSql->tpl->display('backupjob-report.tpl'); 
115   \r
116 ?>\r