[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path Zen Cart 源代码 backup_mysql.php
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | license@zen-cart.com so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: backup_mysql.php revised 2012-07-07 $
//
// check to see if open_basedir restrictions in effect -- if so, likely won't be able to use this tool.
$flag_basedir = false;
$open_basedir=@ini_get('open_basedir');
if ($open_basedir !='') {
$basedir_check_array = explode(':',$open_basedir);
foreach($basedir_check_array as $basedir_check) {
if (!strstr(DIR_FS_ADMIN,$basedir_check)) $flag_basedir=true;
}
if ($flag_basedir) $messageStack->add(ERROR_CANT_BACKUP_IN_SAFE_MODE, 'error');
}
// check to see if "exec()" is disabled in PHP -- if so, won't be able to use this tool.
$exec_disabled = false;
$php_disabled_functions = @ini_get("disable_functions");
if ($php_disabled_functions != '') {
if ($debug=='ON') $messageStack->add('PHP-Disabled-functions: ' . $php_disabled_functions,'error');
if (in_array('exec', preg_split('/,/', str_replace(' ', '', $php_disabled_functions)))) {
$messageStack->add(ERROR_EXEC_DISABLED, 'error');
$exec_disabled = true;
}
}
// Note that LOCAL_EXE_MYSQL and LOCAL_EXE_MYSQL_DUMP are defined in the /admin/includes/languages/backup_mysql.php file
// These can occasionally be overridden in the URL by specifying &tool=/path/to/foo/bar/plus/utilname, depending on server support
// Do not change them here ... edit the LANGUAGES file instead.
// the following lines check to be sure that they've been entered correctly in the language file
$pathsearch=array(str_replace('mysql','',LOCAL_EXE_MYSQL).'/',str_replace('mysql.exe','',LOCAL_EXE_MYSQL).'/','/usr/bin/','/usr/local/bin/','/usr/local/mysql/bin/','c:/mysql/bin/','d:/mysql/bin/','e:/mysql/bin/', 'c:/apache2triad/mysql/bin/', 'd:/apache2triad/mysql/bin/', 'e:/apache2triad/mysql/bin/', 'c:/server/mysql/bin/', '\'c:/Program Files/MySQL/MySQL Server 5.0/bin/\'', '\'d:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\\'', '\'c:/Program Files/MySQL/MySQL Server 4.1/bin/\'');
$pathsearch=array_merge($pathsearch,explode(':',$open_basedir));
$mysql_exe = 'unknown';
$mysqldump_exe = 'unknown';
foreach($pathsearch as $path){
// $path = str_replace('\\','/',$path); // convert backslashes
$path = str_replace('//','/',$path); // convert double slashes to singles
$path = str_replace("'","",$path); // remove ' marks if any
$path = (substr($path,-1)!='/' && substr($path,-1)!='\\') ? $path . '/' : $path; // add a '/' to the end if missing
if ($mysql_exe == 'unknown') {
if (@file_exists($path.'mysql')) $mysql_exe = $path.'mysql';
if (@file_exists($path.'mysql.exe')) $mysql_exe = $path.'mysql.exe';
}
if ($mysqldump_exe == 'unknown') {
if (@file_exists($path.'mysqldump')) $mysqldump_exe = $path.'mysqldump';
if (@file_exists($path.'mysqldump.exe')) $mysqldump_exe = $path.'mysqldump.exe';
}
if ($debug=='ON') $messageStack->add_session('Checking Path: '.$path.'<br />','caution');
if ($mysql_exe != 'unknown' && $mysqldump_exe != 'unknown') break;
}
if (zen_not_null($action)) {
switch ($action) {
case 'forget':
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key = 'DB_LAST_RESTORE'");
$messageStack->add_session(SUCCESS_LAST_RESTORE_CLEARED, 'success');
zen_redirect(zen_href_link(FILENAME_BACKUP_MYSQL));
break;
case 'backupnow':
zen_set_time_limit(250); // not sure if this is needed anymore?
$dump_params .= ' "--host=' . DB_SERVER . '"';
$dump_params .= ' "--user=' . DB_SERVER_USERNAME . '"';
$dump_params .= ' "--password=' . DB_SERVER_PASSWORD . '"';
$dump_params .= ' --opt'; //"optimized" -- turns on all "fast" and optimized export methods
$dump_params .= ' --complete-insert'; // undo optimization slightly and do "complete inserts"--lists all column names for benefit of restore of diff systems
if ($skip_locks_requested) {
$dump_params .= ' --skip-lock-tables --skip-add-locks'; //use this if your host prevents you from locking tables for backup
}
// $dump_params .= ' --skip-comments'; // mysqldump inserts '--' as comment delimiters, which is invalid on import (only for mysql v4.01+)
// $dump_params .= ' --skip-quote-names';
// $dump_params .= ' --force'; // ignore SQL errors if they occur
// $dump_params .= ' --compatible=postgresql'; // other options are: ,mysql323, mysql40
$dump_params .= ' "--result-file=' . DIR_FS_BACKUP . $backup_file . '"';
$dump_params .= ' ' . DB_DATABASE;
// if using the "--tables" parameter, this should be the last parameter, and tables should be space-delimited
// fill $tables_to_export with list of tables, separated by spaces, if wanna just export certain tables
$dump_params .= (($tables_to_export=='') ? '' : ' --tables ' . $tables_to_export);
$dump_params .= " 2>&1";
// remove " marks in parameters for friendlier IIS support
//REQUIRES TESTING: if (strstr($toolfilename,'.exe')) $dump_params = str_replace('"','',$dump_params);
if ($debug=='ON') $messageStack->add_session('COMMAND: '.OS_DELIM.$toolfilename . ' ' . $dump_params.OS_DELIM, 'caution');
$resultcodes = @exec(OS_DELIM . $toolfilename . $dump_params . OS_DELIM, $output, $dump_results );
@exec("exit(0)");
if ($dump_results == -1) $messageStack->add_session(FAILURE_BACKUP_FAILED_CHECK_PERMISSIONS . '<br />The command being run is: ' . $toolfilename . str_replace('--password='.DB_SERVER_PASSWORD,'--password=*****', str_replace('2>&1','',$dump_params)), 'error');
if ($debug=='ON' || (zen_not_null($dump_results) && $dump_results!='0')) $messageStack->add_session('Result code: '.$dump_results, 'caution');
#parse the value that comes back from the script
if (zen_not_null($resultcodes)) list($strA, $strB) = preg_split ('/[|]/', $resultcodes);
if ($debug=='ON') $messageStack->add_session("valueA: " . $strA,'error');
if ($debug=='ON') $messageStack->add_session("valueB: " . $strB,'error');
//$output contains response strings from execution. This displays if needed.
foreach($output as $key=>$value) {$messageStack->add_session("$key => $value<br />",'caution'); }
// remove " marks in parameters for friendlier IIS support
//REQUIRES TESTING: if (strstr($toolfilename,'.exe')) $load_params = str_replace('"','',$load_params);
if ($debug=='ON') $messageStack->add_session('COMMAND: '.OS_DELIM.$toolfilename . ' ' . $load_params.OS_DELIM, 'caution');
$resultcodes=exec(OS_DELIM . $toolfilename . $load_params . OS_DELIM, $output, $load_results );
exec("exit(0)");
#parse the value that comes back from the script
list($strA, $strB) = preg_split ('/[|]/', $resultcodes);
if ($debug=='ON') $messageStack->add_session("valueA: " . $strA,'error');
if ($debug=='ON') $messageStack->add_session("valueB: " . $strB,'error');
if ($debug=='ON' || (zen_not_null($load_results) && $load_results!='0')) $messageStack->add_session('Result code: '.$load_results, 'caution');