1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Improved database backup and added file-backup for non-core elements.

This commit is contained in:
Cameron 2014-01-25 15:56:20 -08:00
parent bd7a336c3a
commit 1a03a883bd
4 changed files with 177 additions and 8 deletions

View File

@ -66,7 +66,49 @@ if(isset($_POST['exportXmlFile']))
}
if(e_AJAX_REQUEST )
{
session_write_close();
while (@ob_end_clean());
if(varset($_GET['mode']) == 'backup') //FIXME - not displaying progress until complete. Use e-progress?
{
echo "Starting file backup...<br />";
$data = array();
$data[] = e_MEDIA;
$data[] = e_LOG;
$data[] = e_IMPORT;
$data[] = e_TEMP;
$data[] = e_SYSTEM."filetypes.xml";
$data[] = e_THEME.e107::getPref('sitetheme');
$plugins = e107::getPlugin()->getOtherPlugins();
foreach($plugins as $dir)
{
$data[] = e_PLUGIN.$dir;
}
$newFile = eHelper::title2sef(SITENAME)."_".date("Y-m-d-H-i-s");
$zip = e107::getFile()->zip($data, e_BACKUP.$newFile.".zip");
echo "File backup complete! <small>(".$zip.")</small><br />";
echo "Starting database backup...<br />";
$dbfile = e107::getDb()->backup('*', $newFile.".sql", array('nologs'=>1, 'droptable'=>1));
echo "Database backup complete! <small>(".$dbfile.")</small>";
e107::getAdminLog()->addSuccess($zip." ".$dbfile, false)->save('Full site backup completed.');
}
exit;
}
require_once ("auth.php");
@ -124,7 +166,8 @@ class system_tools
'exportForm' => array('diz'=>DBLAN_58, 'label'=> DBLAN_58),
'sc_override_scan' => array('diz'=>DBLAN_55, 'label'=> DBLAN_56),
'convert_to_utf8' => array('diz'=>'Check Database Charset','label'=>'Check Charset'),
'correct_perms' => array('diz'=>'Correct File and Directory permissions','label'=>'Correct Perms')
'correct_perms' => array('diz'=>'Correct File and Directory permissions','label'=>'Correct Perms'),
'backup' => array('diz'=>'Backup Database, Files and Folders','label'=>'Backup Site')
);
if(vartrue($_SERVER['E_DEV']))
@ -158,6 +201,8 @@ class system_tools
return;
}
// if(isset($_POST['verify_sql_record']) || varset($_GET['mode'])=='verify_sql_record' || isset($_POST['check_verify_sql_record']) || isset($_POST['delete_verify_sql_record']))
// {
@ -230,6 +275,12 @@ class system_tools
$this->multiSite();
return;
}
if(varset($_GET['mode']) == 'backup')
{
$this->backup();
return;
}
if(!vartrue($_GET['mode']) && !isset($_POST['db_execute']))
{
@ -240,6 +291,26 @@ class system_tools
}
private function backup()
{
$mes = e107::getMessage();
$message = "This will create a database dump and a zipped backup of all non-core plugins, your site theme, your media files and system logs";
$message .= "<br /><a class='e-ajax btn btn-success' data-loading-text='Please wait...' href='#backupstatus' data-src='".e_SELF."?mode=backup' >".LAN_CREATE."</a>";
$mes->addInfo($message);
$text = "<div id='backupstatus' style='margin-top:20px'></div>";
e107::getRender()->tablerender(DBLAN_10.SEP."Backup", $mes->render().$text);
}
/**
* Correct Folder and File permissions.
*/

View File

@ -734,7 +734,7 @@ class e_file
/**
* File retrieval function. by Cam.
* @param $file actual path or {e_} path to file.
* @param $file actual path or {e_xxxx} path to file.
*
*/
function send($file)
@ -874,8 +874,39 @@ class e_file
}
/**
* Zip up folders and files
* @param array $filePaths
* @param string $newFile
*/
public function zip($filePaths=null, $newFile='')
{
if(empty($newFile))
{
$newFile = e_BACKUP.eHelper::title2sef(SITENAME)."_".date("Y-m-d-H-i-s").".zip";
}
if(is_null($filePaths))
{
return "No file-paths set!";
}
require_once(e_HANDLER.'pclzip.lib.php');
$archive = new PclZip($newFile);
if ($archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH,e_BASE) == 0)
{
$error = $archive->errorInfo(true);
e107::getAdminLog()->addError($error)->save('FILE',E_LOG_NOTICE);
return false;
}
else
{
return $newFile;
}
}

View File

@ -1826,6 +1826,22 @@ class e_db_mysql
$this->mySQLtableList = $this->db_mySQLtableList();
}
if($mode == 'nologs')
{
$ret = array();
foreach($this->mySQLtableList as $table)
{
if(substr($table,-4) != '_log' && $table != 'download_requests')
{
$ret[] = $table;
}
}
return $ret;
}
if($mode == 'all')
{
@ -1928,20 +1944,38 @@ class e_db_mysql
* @param $table string - name without the prefix or '*' for all
* @param $file string - optional file name. or leave blank to generate.
* @param $options - additional preferences.
* @return backup file path.
*/
function backup($table='*', $file='', $options=null)
{
$dbtable = $this->mySQLdefaultdb;
$fileName = ($table =='*') ? SITENAME : $table;
$fileName = ($table =='*') ? str_replace(" ","_",SITENAME) : $table;
$fileName = preg_replace('/[^\w]/i',"",$fileName);
$backupFile = ($file) ? e_BACKUP.$file : e_BACKUP.$this->mySQLPrefix.$fileName."_".date("Y-m-d-H-i-s").".sql";
$tableList = ($table=='*') ? $this->db_TableList() : array($table);
$backupFile = ($file) ? e_BACKUP.$file : e_BACKUP.$fileName."_".$this->mySQLPrefix.date("Y-m-d-H-i-s").".sql";
if($table=='*')
{
$nolog = vartrue($options['nologs']) ? 'nologs' : '';
$tableList = $this->db_TableList($nolog);
}
else
{
$tableList = explode(",",$table);
}
$header = "-- e107 Database Backup File \n";
$header .= "-- Host: ".$_SERVER['SERVER_NAME']."\n";
$header .= "-- Generation Time: ".date('r')."\n";
$header .= "-- Encoding: ANSI\n\n\n";
file_put_contents($backupFile,$header, FILE_APPEND);
foreach ($tableList as $table)
{
unset($text);
$text = "";
$text .= vartrue($options['droptable']) ? "DROP TABLE IF EXISTS `".$this->mySQLPrefix.$table."`;\n" : "";
$this->gen("SHOW CREATE TABLE `".$this->mySQLPrefix.$table."`");
$row2 = $this->fetch();
$text .= $row2['Create Table'];
@ -1977,7 +2011,8 @@ class e_db_mysql
unset($fields);
}
return $backupFile;
// file_put_contents('memory.log', 'memory used in line ' . __LINE__ . ' is: ' . memory_get_usage() . PHP_EOL, FILE_APPEND);
}

View File

@ -64,6 +64,19 @@ class e107plugin
'core'
);
protected $core_plugins = array(
"_blank","admin_menu","alt_auth","banner","blogcalendar_menu",
"calendar_menu","chatbox_menu", "clock_menu","comment_menu",
"contact", "download","faqs", "featurebox", "forum","gallery",
"gsitemap","import", "linkwords", "list_new", "log", "login_menu",
"metaweblog", "newforumposts_main", "news", "newsfeed",
"newsletter","online", "page", "pdf", "pm", "pm","poll",
"rss_menu","search_menu","siteinfo", "social", "tagwords", "tinymce",
"trackback","tree_menu","user"
);
// List of all plugin variables which need to be checked - install required if one or more set and non-empty
// Deprecated in 0.8 (used in plugin.php only). Probably delete in 0.9
var $all_eplug_install_variables = array(
@ -148,8 +161,27 @@ class e107plugin
}
return false;
}
/**
* Return a list of core plugins.
*/
public function getCorePlugins()
{
return $this->core_plugins;
}
/**
* Return a list of non-core plugins
*/
public function getOtherPlugins()
{
$allplugs = e107::getFile()->get_dirs(e_PLUGIN);
return array_diff($allplugs,$this->core_plugins);
}
/**
/**
* Returns an array containing details of all plugins in the plugin table - should normally use e107plugin::update_plugins_table() first to
* make sure the table is up to date. (Primarily called from plugin manager to get lists of installed and uninstalled plugins.
* @return array plugin details