]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/backupjob-report.php
fd9f4391f07b6741095b07d58c2cfa5bf7ed0ed6
[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 \r
64   $graph->Render();\r
65   $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() ); 
66   \r
67   // ===============================================================
68   // Getting last 7 days stored files graph\r
69   // ===============================================================
70   $graph = new BGraph("graph3.png" );\r
71   \r
72   foreach( $days as $day )\r
73     array_push( $days_stored_files, $dbSql->GetStoredFilesByJob( $backupjob_name, $day['start'], $day['end'] ) );\r
74 \r
75   // Calculate total files for this period      \r
76   foreach( $days_stored_files as $day )\r
77         $backupjob_files += $day[1];\r
78   \r
79   $graph->SetData( $days_stored_files, 'bars', 'text-data' );\r
80   $graph->SetGraphSize( 400, 230 );\r
81 \r
82   $graph->Render();\r
83   $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() );
84 \r
85   // Last 10 jobs\r
86   $query    = "SELECT JobId, Level, JobFiles, JobBytes, JobStatus, EndTime, Name ";  \r
87   $query   .= "FROM Job ";\r
88   $query   .= "WHERE Name = '$backupjob_name' ";\r
89   $query   .= "ORDER BY EndTime DESC ";\r
90   $query   .= "LIMIT 10 ";\r
91   \r
92   $jobs         = array();\r
93   $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' );\r
94   $result       = $dbSql->db_link->query( $query );\r
95   \r
96   if( ! PEAR::isError( $result ) )\r
97   {\r
98         while( $job = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {\r
99                 $job['Level'] = $joblevel[ $job['Level'] ];\r
100                 array_push( $jobs, $job);\r
101         }               
102   }else\r
103         die( "Unable to get last jobs from catalog " . $result->getMessage() );\r
104     \r
105   $dbSql->tpl->assign('jobs', $jobs );
106   $dbSql->tpl->assign('backupjob_name', $backupjob_name );
107   $dbSql->tpl->assign('backupjob_period', $backupjob_period );
108   $dbSql->tpl->assign('backupjob_bytes', $backupjob_bytes );
109   $dbSql->tpl->assign('backupjob_files', $backupjob_files );
110   \r
111   // Process and display the template \r
112   $dbSql->tpl->display('backupjob-report.tpl'); 
113   \r
114 ?>\r