3 +-------------------------------------------------------------------------+
4 | Copyright 2010-2011, Davide Franco |
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. |
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 +-------------------------------------------------------------------------+
18 include_once( 'config/global.inc.php' );
27 $days_stored_bytes = array();
28 $days_stored_files = array();
30 // ===============================================================
31 // Get Backup Job name from GET or POST
32 // ===============================================================
33 $http_post = CHttpRequest::getRequestVars( $_POST );
34 $http_get = CHttpRequest::getRequestVars( $_GET );
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'];
41 die( "Please specify a backup job name " );
43 // Generate Backup Job report period string
44 $backupjob_period = "From " . date( "Y-m-d", (NOW-WEEK) ) . " to " . date( "Y-m-d", NOW );
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 );
50 $backupjob_files = $dbSql->getStoredFiles( LAST_WEEK, NOW, $backupjob_name );
51 $backupjob_files = number_format( $backupjob_files, 0, '.', "'");
53 // Get the last 7 days interval (start and end)
54 $days = CTimeUtils::getLastDaysIntervals( 7 );
56 // ===============================================================
57 // Last 7 days stored Bytes graph
58 // ===============================================================
59 $graph = new CGraph( "graph2.png" );
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 );
67 $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
68 $graph->SetGraphSize( 400, 230 );
69 $graph->SetYTitle( "GB" );
72 $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );
74 // ===============================================================
75 // Getting last 7 days stored files graph
76 // ===============================================================
77 $graph = new CGraph("graph3.png" );
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 );
84 $graph->SetData( $days_stored_files, 'bars', 'text-data' );
85 $graph->SetGraphSize( 400, 230 );
86 $graph->SetYTitle( "Files" );
89 $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() );
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 ";
99 $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' );
102 $result = $dbSql->db_link->runQuery( $query );
104 foreach( $result->fetchAll() as $job )
106 // Job level description
107 $job['joblevel'] = $joblevel[ $job['level'] ];
109 // Job execution execution time
110 $job['elapsedtime'] = CTimeUtils::Get_Elapsed_Time( $job['starttime'], $job['endtime'] );
113 if( count($jobs) % 2)
114 $job['row_class'] = 'odd';
116 // Job bytes more easy to read
117 $job['jobbytes'] = CUtils::Get_Human_Size( $job['jobbytes'] );
118 $job['jobfiles'] = number_format($job['jobfiles'], 0 , '.', "'");
122 }catch(PDOExceptin $e) {
123 CDBError::raiseError($e);
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 );
132 // Process and display the template
133 $dbSql->tpl->display('backupjob-report.tpl');