From b1e17f3c450c80d833411a7a59db02f0b0a37627 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Thu, 17 Feb 2011 18:21:10 +0100 Subject: [PATCH] bacula-web: Improved PHP code for GetDbSize() function in bweb.inc.php --- gui/bacula-web/bweb.inc.php | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php index 39deeaab53..79d7cfc8de 100644 --- a/gui/bacula-web/bweb.inc.php +++ b/gui/bacula-web/bweb.inc.php @@ -211,7 +211,38 @@ class Bweb extends DB { function GetDbSize() { - $database_size = 0; + $database_size = 0; + $query = ""; + + switch( $this->driver ) + { + case 'mysql': + $query = "SELECT table_schema AS 'database', sum( data_length + index_length) AS 'dbsize' "; + $query .= "FROM information_schema.TABLES "; + $query .= "WHERE table_schema = 'bacula' "; + $query .= "GROUP BY table_schema"; + break; + case 'pgsql': + $query = "SELECT pg_database_size('bacula') AS dbsize"; + break; + case 'sqlite': + // Not yet implemented + return "0 MB"; + break; + } + + $result = $this->db_link->query( $query ); + + if(! PEAR::isError( $result ) ) + { + $db = $result->fetchRow( DB_FETCHMODE_ASSOC ); + $database_size =+ $db['dbsize']; + }else + die( "Unable to get database size
" . $jobs->getMessage() ); + + return $this->human_file_size( $database_size ); + + /* if ( $this->driver == "mysql") { $dbsize = $this->db_link->query("show table status") or die ("classes.inc: Error query: 3"); @@ -237,8 +268,7 @@ class Bweb extends DB { } // end if $dbsize->free(); - - return $this->human_file_size( $database_size ); + */ } // end function GetDbSize() public function Get_Nb_Clients() -- 2.39.2