mirror of
https://github.com/e107inc/e107.git
synced 2025-07-30 19:30:25 +02:00
Basic implementation of a system DB backup cron added. Needs testing.
This commit is contained in:
@@ -47,7 +47,7 @@ class cron_admin extends e_admin_dispatcher
|
||||
|
||||
protected $adminMenu = array(
|
||||
'main/list' => array('caption'=> 'Manage', 'perm' => '0'),
|
||||
// 'main/create' => array('caption'=> LAN_CREATE, 'perm' => '0'),
|
||||
'main/refresh' => array('caption'=> "Refresh", 'perm' => '0','url'=>'cron.php'),
|
||||
// 'main/prefs' => array('caption'=> 'Settings', 'perm' => '0'),
|
||||
// 'main/custom' => array('caption'=> 'Custom Page', 'perm' => '0')
|
||||
);
|
||||
@@ -151,9 +151,16 @@ class cron_admin_ui extends e_admin_ui
|
||||
'description' => 'Process bounce retriggers<br />Only needed if retriggering of bans enabled.',
|
||||
'available' => e107::getPref('ban_retrigger')
|
||||
),
|
||||
4 => array(
|
||||
'name' => 'Database Backup',
|
||||
'category' => 'backup',
|
||||
'function' => 'dbBackup',
|
||||
'description' => 'Backup the system database to '.e_SYSTEM.'backups/',
|
||||
'available' => e107::getPref('ban_retrigger')
|
||||
),
|
||||
);
|
||||
|
||||
if(!$_GET['action'])
|
||||
if(!$_GET['action'] || $_GET['action'] == 'refresh')
|
||||
{
|
||||
|
||||
$this->cronImport($cronDefaults); // import Core Crons (if missing)
|
||||
|
@@ -93,6 +93,64 @@ class _system_cron
|
||||
}
|
||||
}
|
||||
|
||||
// Very basic and needs improvement. (for large DBs)
|
||||
function dbBackup()
|
||||
{
|
||||
require(e_BASE."e107_config.php");
|
||||
|
||||
$sql = e107::getDb();
|
||||
$dbtable = $mySQLdefaultdb; // TODO - retrieve this in a better way. (without including e107_config)
|
||||
|
||||
$backupFile = e_SYSTEM."backups/".SITENAME."_".date("Y-m-d-H-i-s").".sql";
|
||||
$result = mysql_list_tables($dbtable);
|
||||
|
||||
while ($tab = mysql_fetch_array($result, MYSQL_NUM))
|
||||
{
|
||||
$table = $tab[0];
|
||||
$text = "";
|
||||
|
||||
$sql->db_Select_gen("SHOW CREATE TABLE `".$table."`");
|
||||
$row2 = $sql->db_Fetch();
|
||||
$text .= $row2['Create Table'];
|
||||
$text .= ";\n\n";
|
||||
|
||||
$sql->db_Select_gen("SELECT * FROM `".$table."`");
|
||||
$data_array = array();
|
||||
|
||||
while($row = $sql->db_Fetch())
|
||||
{
|
||||
if(!$fields)
|
||||
{
|
||||
$fields = array_keys($row);
|
||||
}
|
||||
|
||||
$d = array();
|
||||
foreach($fields as $val)
|
||||
{
|
||||
$d[] = "'".mysql_real_escape_string($row[$val])."'";
|
||||
}
|
||||
|
||||
$data_array[] = "(".implode(", ",$d).")";
|
||||
|
||||
}
|
||||
|
||||
|
||||
$text .= "\nINSERT INTO `".$table."` (`".implode("` ,`",$fields)."`) VALUES \n";
|
||||
$text .= implode(",\n",$data_array);
|
||||
$text .= ";\n\n\n";
|
||||
$c++;
|
||||
|
||||
file_put_contents($backupFile,$text,FILE_APPEND);
|
||||
unset($fields);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user