]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/baculum/protected/Class/Database.php
baculum: Assign Baculum copyright to Kern Sibbald
[bacula/bacula] / gui / baculum / protected / Class / Database.php
index 0d6a9b356a342a5b4eee7155018c54865b64a04a..361b19e21a1e46fd76319d40fe4503d30e4ddb5b 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2015 Marcin Haba
+ * Copyright (C) 2013-2016 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -119,5 +119,38 @@ class Database extends TModule {
                $ret = (array_key_exists('versionid', $result) === true) ? $result['versionid'] : false;
                return $ret;
        }
+
+       public function getDatabaseSize() {
+               $configuration = $this->Application->getModule('configuration');
+               $db_params = $this->getDBParams();
+               $dbtype = $db_params['type'];
+               $dbname = $db_params['name'];
+
+               $db = new ActiveRecord();
+               $connection = $db->getDbConnection();
+               $connection->setActive(true);
+               $pdo = $connection->getPdoInstance();
+
+               $dbsize = 0;
+               if ($configuration->isPostgreSQLType($dbtype)) {
+                       $sql = "SELECT pg_database_size('$dbname') AS dbsize";
+                       $result = $pdo->query($sql);
+                       $dbsize = $result->fetch();
+               } else if ($configuration->isMySQLType($dbtype)) {
+                       $sql = "SELECT Sum(data_length + index_length) AS dbsize FROM information_schema.tables";
+                       $result = $pdo->query($sql);
+                       $dbsize = $result->fetch();
+               } else if ($configuration->isSQLiteType($dbtype)) {
+                       $sql = "PRAGMA page_count";
+                       $result = $pdo->query($sql);
+                       $page_count = $result->fetch();
+                       $sql = "PRAGMA page_size";
+                       $result = $pdo->query($sql);
+                       $page_size = $result->fetch();
+                       $dbsize = array('dbsize' => ($page_count['page_count'] * $page_size['page_size']));
+               }
+               $pdo = null;
+               return $dbsize['dbsize'];
+       }
 }
-?>
\ No newline at end of file
+?>