Skip to content

Commit

Permalink
Updated db backup class
Browse files Browse the repository at this point in the history
  • Loading branch information
eSilverStrike committed Oct 14, 2016
1 parent 9cedfba commit 7fcd949
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions system/classes/dbbackup.class.php
@@ -1,5 +1,6 @@
<?php
/**
* Geeklog Database Backup Class.
* Based on the Wordpress wp-db-backup plugin by Austin Matzko
* http://www.ilfilosofo.com/
*
Expand Down Expand Up @@ -50,6 +51,7 @@ class dbBackup
*/
public function __construct($fromCron = false)
{
global $_CONF, $_TABLES;

$this->setGZip(true);
$this->fromCron = $fromCron ? true : false;
Expand Down Expand Up @@ -78,8 +80,11 @@ public function setBackupFilename($filename)
*/
public function getBackupFilename()
{
global $_CONF;

// Create the backup filename
$table_prefix = empty($_CONF['dbdump_filename_prefix']) ?
'geeklog_db_backup_' : $_CONF['dbdump_filename_prefix'] . '_';
$datum = date("Y_m_d_H_i_s");
$this->backup_filename = $table_prefix . $datum . '.sql';
if ($this->gzip) $this->backup_filename .= '.gz';
Expand Down Expand Up @@ -418,6 +423,7 @@ public function initBackup()
}

//Begin new backup of MySql
$this->stow("# Geeklog MySQL database backup\n");
$this->stow("#\n");
$this->stow('# Generated: ' . date('l j. F Y H:i T') . "\n");
$this->stow("# Hostname: $_DB_host\n");
Expand All @@ -439,12 +445,14 @@ public function initBackup()
*/
private function backupDB()
{
global $_TABLES, $_CONF;

if ( $this->initBackup() === false ) {
return false;
}

foreach ($this->tablenames as $key=>$table) {
if (isset($_CONF['dbdump_tables_only']) && $_CONF['dbdump_tables_only']) {
$this->backupTable($table,true);
} else {
$this->backupTable($table);
Expand Down Expand Up @@ -601,6 +609,7 @@ private function SendMail(

/**
* Deliver a backup file.
* Originally had the option of "http" or "smtp", but for Geeklog
* only "smtp" is needed. Files can be downloaded at any time via
* the backup admin interface.
*/
Expand Down Expand Up @@ -656,12 +665,14 @@ public function cron_backup()
*/
function setGZip($val=true)
{
global $_CONF;

switch ($val) {
case false:
$this->gzip = false;
break;
case true:
if (isset($_CONF['dbdump_gzip']) && $_CONF['dbdump_gzip']) {
$this->gzip = function_exists('gzopen') ? true : false;
} else {
$this->gzip = false;
Expand All @@ -679,9 +690,12 @@ function setGZip($val=true)
*/
public function Purge($files = 0)
{
global $_CONF;

if ( !isset($_CONF['dbdump_max_files'])) $_CONF['dbdump_max_files'] = 5;

if ($files == 0) {
$files = (int)$_CONF['dbdump_max_files'];
}
if ($files == 0) return;

Expand Down

0 comments on commit 7fcd949

Please sign in to comment.