forked from extern/egroupware
* not overwriting system configuration (eg. pathes) on restore, which break a running system and if called from within EGroupware update the restored backup, in case it is an older version
This commit is contained in:
parent
44c3c7eb9a
commit
10cf1b2b8e
@ -7,7 +7,7 @@
|
||||
* @package api
|
||||
* @subpackage db
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2003-8 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2003-10 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
@ -328,8 +328,26 @@ class db_backup
|
||||
$this->backup_mincount = $minCount;
|
||||
$this->backup_files = (bool)$backupFiles;
|
||||
// Update session cache
|
||||
$GLOBALS['egw']->invalidate_session_cache();
|
||||
if (is_a($GLOBALS['egw'],'egw')) $GLOBALS['egw']->invalidate_session_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Certain config settings NOT to restore (because they break a working system)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $system_config = array(
|
||||
'files_dir',
|
||||
'temp_dir',
|
||||
'backup_dir',
|
||||
'webserver_url',
|
||||
'aspell_path',
|
||||
'hostname',
|
||||
'httpproxy_server',
|
||||
'httpproxy_port',
|
||||
'httpproxy_server_username',
|
||||
'httpproxy_server_password',
|
||||
);
|
||||
|
||||
/**
|
||||
* Backup all data in the form of a (compressed) csv file
|
||||
@ -337,14 +355,26 @@ class db_backup
|
||||
* @param resource $f file opened with fopen for reading
|
||||
* @param boolean $convert_to_system_charset=false convert the restored data to the selected system-charset
|
||||
* @param string $filename='' gives the file name which is used in case of a zip archive.
|
||||
* @param boolean $protect_system_config=true should above system_config values be protected (NOT overwritten)
|
||||
*
|
||||
* @returns An empty string or an error message in case of failure.
|
||||
*/
|
||||
function restore($f,$convert_to_system_charset=false,$filename='')
|
||||
function restore($f,$convert_to_system_charset=false,$filename='',$protect_system_config=true)
|
||||
{
|
||||
@set_time_limit(0);
|
||||
ini_set('auto_detect_line_endings',true);
|
||||
|
||||
|
||||
if ($protect_system_config)
|
||||
{
|
||||
$system_config = array();
|
||||
foreach($this->db->select(self::TABLE,'*',array(
|
||||
'config_app' => 'phpgwapi',
|
||||
'config_name' => self::$system_config,
|
||||
),__LINE__,__FILE__) as $row)
|
||||
{
|
||||
$system_config[] = $row;
|
||||
}
|
||||
}
|
||||
$this->db->transaction_begin();
|
||||
|
||||
// drop all existing tables
|
||||
@ -468,8 +498,8 @@ class db_backup
|
||||
$import = true;
|
||||
$data = self::csv_split($line,$cols);
|
||||
if ($table == 'egw_async' && in_array('##last-check-run##',$data)) {
|
||||
echo '<p>'.lang("Line %1: '%2'<br><b>csv data does contain ##last-check-run## of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n";
|
||||
echo 'data=<pre>'.print_r($data,true)."</pre>\n";
|
||||
//echo '<p>'.lang("Line %1: '%2'<br><b>csv data does contain ##last-check-run## of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n";
|
||||
//echo 'data=<pre>'.print_r($data,true)."</pre>\n";
|
||||
$import = false;
|
||||
}
|
||||
if (in_array($table,$this->exclude_tables))
|
||||
@ -477,7 +507,8 @@ class db_backup
|
||||
echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n";
|
||||
$import = false; // dont restore data of excluded tables
|
||||
}
|
||||
if ($import) {
|
||||
if ($import)
|
||||
{
|
||||
if (count($data) == count($cols))
|
||||
{
|
||||
if ($convert_to_system_charset && !$this->db->capabilities['client_encoding'])
|
||||
@ -524,6 +555,16 @@ class db_backup
|
||||
unlink($name);
|
||||
rmdir($dir.'/database_backup');
|
||||
}
|
||||
if ($protect_system_config)
|
||||
{
|
||||
foreach($system_config as $row)
|
||||
{
|
||||
$this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array(
|
||||
'config_name' => $row['config_name'],
|
||||
'config_app' => $row['config_app'],
|
||||
),__LINE__,__FILE__);
|
||||
}
|
||||
}
|
||||
if (!$this->db->transaction_commit())
|
||||
{
|
||||
return lang('Restore failed');
|
||||
@ -738,12 +779,12 @@ class db_backup
|
||||
* gets a list of all files on $f
|
||||
*
|
||||
* @param string file $f
|
||||
* [@param int $cnt]
|
||||
* [@param string $path_name]
|
||||
* @param int $cnt=0
|
||||
* @param string $path_name=''
|
||||
*
|
||||
* @return array (list of files)
|
||||
*/
|
||||
function get_file_list($f, $cnt = 0, $path_name = "")
|
||||
function get_file_list($f, $cnt = 0, $path_name = '')
|
||||
{
|
||||
//chdir($f);
|
||||
//echo "Processing $f <br>";
|
||||
|
@ -37,8 +37,7 @@ if ($_POST['download'])
|
||||
list($file) = each($_POST['download']);
|
||||
$file = $db_backup->backup_dir.'/'.basename($file); // basename to now allow to change the dir
|
||||
ob_end_clean();
|
||||
$browser = CreateObject('phpgwapi.browser');
|
||||
$browser->content_header(basename($file));
|
||||
html::content_header(basename($file));
|
||||
$f = fopen($file,'rb');
|
||||
fpassthru($f);
|
||||
fclose($f);
|
||||
@ -68,8 +67,9 @@ else
|
||||
$setup_tpl->set_block('T_db_backup','setup_header');
|
||||
$setup_tpl->set_var('setup_header','');
|
||||
$GLOBALS['egw_info']['flags']['app_header'] = $stage_title;
|
||||
$GLOBALS['egw']->common->phpgw_header();
|
||||
common::egw_header();
|
||||
parse_navbar();
|
||||
$run_in_egw = true;
|
||||
}
|
||||
// save backup housekeeping settings
|
||||
if ($_POST['save_backup_settings'])
|
||||
@ -178,6 +178,14 @@ if ($_POST['restore'])
|
||||
echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
|
||||
$db_backup->restore($f, FALSE, $file);
|
||||
$setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file));
|
||||
if ($run_in_egw)
|
||||
{
|
||||
// updating the backup
|
||||
$cmd = new setup_cmd_update($GLOBALS['egw']->session->account_domain,
|
||||
$GLOBALS['egw_info']['server']['header_admin_user']='admin',
|
||||
$GLOBALS['egw_info']['server']['header_admin_password']=uniqid('pw',true),false,true);
|
||||
echo $cmd->run()."\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -271,7 +279,11 @@ $setup_tpl->set_var(array(
|
||||
$setup_tpl->set_var('self',$self);
|
||||
$setup_tpl->pparse('out','T_db_backup');
|
||||
|
||||
if (is_object($GLOBALS['egw_setup']->html))
|
||||
if ($run_in_egw)
|
||||
{
|
||||
common::egw_footer();
|
||||
}
|
||||
else
|
||||
{
|
||||
$GLOBALS['egw_setup']->html->show_footer();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user