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