Browse Source

Merge pull request #443 from emanuele45/remove_db_backup

Here we go: all happy the db backup is gone
Michael Eshom 11 năm trước cách đây
mục cha
commit
d272b1e03e

+ 0 - 231
Sources/DumpDatabase.php

@@ -1,231 +0,0 @@
-<?php
-
-/**
- * This file has a single job - database backup.
- *
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines http://www.simplemachines.org
- * @copyright 2013 Simple Machines and individual contributors
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-if (!defined('SMF'))
-	die('No direct access...');
-
-/**
- * Dumps the database.
- * It writes all of the database to standard output.
- * It uses gzip compression if compress is set in the URL/post data.
- * It may possibly time out, and mess up badly if you were relying on it. :P
- * The data dumped depends on whether "struct" and "data" are passed.
- * It requires an administrator and the session hash by post.
- * It is called from ManageMaintenance.php.
- */
-function DumpDatabase2()
-{
-	global $db_name, $scripturl, $modSettings, $crlf, $smcFunc, $db_prefix, $db_show_debug;
-
-	// Administrators only!
-	if (!allowedTo('admin_forum'))
-		fatal_lang_error('no_dump_database', 'critical');
-
-	// We don't need debug when dumping the database
-	$modSettings['disableQueryCheck'] = true;
-	$db_show_debug = false;
-
-	// You can't dump nothing!
-	if (!isset($_REQUEST['struct']) && !isset($_REQUEST['data']))
-		$_REQUEST['data'] = true;
-
-	checkSession('post');
-
-	// We will need this, badly!
-	db_extend();
-
-	// Attempt to stop from dying...
-	@set_time_limit(600);
-	$time_limit = ini_get('max_execution_time');
-	$start_time = time();
-
-	// @todo ... fail on not getting the requested memory?
-	setMemoryLimit('256M');
-	$memory_limit = memoryReturnBytes(ini_get('memory_limit')) / 4;
-	$current_used_memory = 0;
-	$db_backup = '';
-	$output_function = 'un_compressed';
-
-	@ob_end_clean();
-
-	// Start saving the output... (don't do it otherwise for memory reasons.)
-	if (isset($_REQUEST['compress']) && function_exists('gzencode'))
-	{
-		$output_function = 'gzencode';
-
-		// Send faked headers so it will just save the compressed output as a gzip.
-		header('Content-Type: application/x-gzip');
-		header('Accept-Ranges: bytes');
-		header('Content-Encoding: none');
-
-		// Gecko browsers... don't like this. (Mozilla, Firefox, etc.)
-		if (!isBrowser('gecko'))
-			header('Content-Transfer-Encoding: binary');
-
-		// The file extension will include .gz...
-		$extension = '.sql.gz';
-	}
-	else
-	{
-		// Get rid of the gzipping alreading being done.
-		if (!empty($modSettings['enableCompressedOutput']))
-			@ob_end_clean();
-		// If we can, clean anything already sent from the output buffer...
-		elseif (ob_get_length() != 0)
-			ob_clean();
-
-		// Tell the client to save this file, even though it's text.
-		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
-		header('Content-Encoding: none');
-
-		// This time the extension should just be .sql.
-		$extension = '.sql';
-	}
-
-	// This should turn off the session URL parser.
-	$scripturl = '';
-
-	// If this database is flat file and has a handler function pass it to that.
-	if (!empty($smcFunc['db_get_backup']))
-	{
-		$smcFunc['db_get_backup']();
-		exit;
-	}
-
-	// Send the proper headers to let them download this file.
-	header('Content-Disposition: attachment; filename="' . $db_name . '-' . (empty($_REQUEST['struct']) ? 'data' : (empty($_REQUEST['data']) ? 'structure' : 'complete')) . '_' . strftime('%Y-%m-%d') . $extension . '"');
-	header('Cache-Control: private');
-	header('Connection: close');
-
-	// This makes things simpler when using it so very very often.
-	$crlf = "\r\n";
-
-	// SQL Dump Header.
-	$db_chunks =
-		'-- ==========================================================' . $crlf .
-		'--' . $crlf .
-		'-- Database dump of tables in `' . $db_name . '`' . $crlf .
-		'-- ' . timeformat(time(), false) . $crlf .
-		'--' . $crlf .
-		'-- ==========================================================' . $crlf .
-		$crlf;
-
-	// Get all tables in the database....
-	if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0)
-	{
-		$db = strtr($match[1], array('`' => ''));
-		$dbp = str_replace('_', '\_', $match[2]);
-	}
-	else
-	{
-		$db = false;
-		$dbp = $db_prefix;
-	}
-
-	// Dump each table.
-	$tables = $smcFunc['db_list_tables'](false, $db_prefix . '%');
-	foreach ($tables as $tableName)
-	{
-		// Are we dumping the structures?
-		if (isset($_REQUEST['struct']))
-		{
-			$db_chunks .=
-				$crlf .
-				'--' . $crlf .
-				'-- Table structure for table `' . $tableName . '`' . $crlf .
-				'--' . $crlf .
-				$crlf .
-				$smcFunc['db_table_sql']($tableName) . ';' . $crlf;
-		}
-		else
-			// This is needed to speedup things later
-			$smcFunc['db_table_sql']($tableName);
-
-		// How about the data?
-		if (!isset($_REQUEST['data']) || substr($tableName, -10) == 'log_errors')
-			continue;
-
-		$first_round = true;
-		$close_table = false;
-
-		// Are there any rows in this table?
-		while ($get_rows = $smcFunc['db_insert_sql']($tableName, $first_round))
-		{
-			if (empty($get_rows))
-				break;
-
-			// Time is what we need here!
-			if (function_exists('apache_reset_timeout'))
-				@apache_reset_timeout();
-			elseif (!empty($time_limit) && ($start_time + $time_limit - 20 > time()))
-			{
-				$start_time = time();
-				@set_time_limit(150);
-			}
-
-			if ($first_round)
-			{
-				$db_chunks .=
-					$crlf .
-					'--' . $crlf .
-					'-- Dumping data in `' . $tableName . '`' . $crlf .
-					'--' . $crlf .
-					$crlf;
-				$first_round = false;
-			}
-			$db_chunks .=
-				$get_rows;
-			$current_used_memory += $smcFunc['strlen']($db_chunks);
-
-			$db_backup .= $db_chunks;
-			unset($db_chunks);
-			$db_chunks = '';
-			if ($current_used_memory > $memory_limit)
-			{
-				echo $output_function($db_backup);
-				$current_used_memory = 0;
-				// This is probably redundant
-				unset($db_backup);
-				$db_backup = '';
-			}
-			$close_table = true;
-		}
-
-		// No rows to get - skip it.
-		if ($close_table)
-			$db_backup .=
-			'-- --------------------------------------------------------' . $crlf;
-	}
-
-	$db_backup .=
-		$crlf .
-		'-- Done' . $crlf;
-
-	echo $output_function($db_backup);
-
-	exit;
-}
-
-/**
- * Dummy/helper function, it simply returns the string passed as argument
- * @param $string, a string
- * @return the string passed
- */
-function un_compressed($string = '')
-{
-	return $string;
-}
-
-?>

+ 0 - 66
Sources/ManageMaintenance.php

@@ -61,7 +61,6 @@ function ManageMaintenance()
 			'template' => 'maintain_database',
 			'activities' => array(
 				'optimize' => 'OptimizeTables',
-				'backup' => 'MaintainDownloadBackup',
 				'convertentities' => 'ConvertEntities',
 				'convertutf8' => 'ConvertUtf8',
 				'convertmsgbody' => 'ConvertMsgBody',
@@ -147,58 +146,6 @@ function MaintainDatabase()
 		$context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536);
 	}
 
-	// Check few things to give advices before make a backup
-	// If safe mod is enable the external tool is *always* the best (and probably the only) solution
-	$context['safe_mode_enable'] = @ini_get('safe_mode');
-	// This is just a...guess
-	$result = $smcFunc['db_query']('', '
-		SELECT COUNT(*)
-		FROM {db_prefix}messages',
-		array()
-	);
-	list($messages) = $smcFunc['db_fetch_row']($result);
-	$smcFunc['db_free_result']($result);
-
-	// 256 is what we use in the backup script
-	setMemoryLimit('256M');
-	$memory_limit = memoryReturnBytes(ini_get('memory_limit')) / (1024 * 1024);
-	// Zip limit is set to more or less 1/4th the size of the available memory * 1500
-	// 1500 is an estimate of the number of messages that generates a database of 1 MB (yeah I know IT'S AN ESTIMATION!!!)
-	// Why that? Because the only reliable zip package is the one sent out the first time,
-	// so when the backup takes 1/5th (just to stay on the safe side) of the memory available
-	$zip_limit = $memory_limit * 1500 / 5;
-	// Here is more tricky: it depends on many factors, but the main idea is that
-	// if it takes "too long" the backup is not reliable. So, I know that on my computer it take
-	// 20 minutes to backup 2.5 GB, of course my computer is not representative, so I'll multiply by 4 the time.
-	// I would consider "too long" 5 minutes (I know it can be a long time, but let's start with that):
-	// 80 minutes for a 2.5 GB and a 5 minutes limit means 160 MB approx
-	$plain_limit = 240000;
-	// Last thing: are we able to gain time?
-	$current_time_limit = ini_get('max_execution_time');
-	@set_time_limit(159); //something strange just to be sure
-	$new_time_limit = ini_get('max_execution_time');
-
-	$context['use_maintenance'] = 0;
-
-	// External tool if:
-	//  * safe_mode enable OR
-	//  * cannot change the execution time OR
-	//  * cannot reset timeout
-	if ($context['safe_mode_enable'] || empty($new_time_limit) || ($current_time_limit == $new_time_limit && !function_exists('apache_reset_timeout')))
-		$context['suggested_method'] = 'use_external_tool';
-	elseif ($zip_limit < $plain_limit && $messages < $zip_limit)
-		$context['suggested_method'] = 'zipped_file';
-	elseif ($zip_limit > $plain_limit || ($zip_limit < $plain_limit && $plain_limit < $messages))
-	{
-		$context['suggested_method'] = 'use_external_tool';
-		$context['use_maintenance'] = empty($maintenance) ? 2 : 0;
-	}
-	else
-	{
-		$context['use_maintenance'] = 1;
-		$context['suggested_method'] = 'plain_text';
-	}
-
 	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
 		$context['maintenance_finished'] = $txt['utf8_title'];
 	if (isset($_GET['done']) && $_GET['done'] == 'convertentities')
@@ -1772,19 +1719,6 @@ function MaintainReattributePosts()
 	$context['maintenance_finished'] = $txt['maintain_reattribute_posts'];
 }
 
-/**
- * Handling function for the backup stuff.
- */
-function MaintainDownloadBackup()
-{
-	global $sourcedir;
-
-	validateToken('admin-maint');
-
-	require_once($sourcedir . '/DumpDatabase.php');
-	DumpDatabase2();
-}
-
 /**
  * Removing old members. Done and out!
  * @todo refactor

+ 0 - 44
Themes/default/ManageMaintenance.template.php

@@ -36,50 +36,6 @@ function template_maintain_database()
 					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
 				</form>
 			</div>
-		</div>
-
-		<div class="cat_bar">
-			<h3 class="catbg">
-			<a href="', $scripturl, '?action=helpadmin;help=maintenance_backup" onclick="return reqOverlayDiv(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['maintain_backup'], '
-			</h3>
-		</div>
-
-		<div class="windowbg2">
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=backup" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_backup_info'], '</p>';
-
-	if ($db_type == 'sqlite')
-		echo '
-					<input type="submit" value="', $txt['maintain_backup_save'], '" id="submitDump" class="button_submit" />';
-	else
-	{
-		if ($context['safe_mode_enable'])
-			echo '
-					<div class="errorbox">', $txt['safe_mode_enabled'], '</div>';
-		else
-			echo '
-					<div class="', $context['suggested_method'] == 'use_external_tool' || $context['use_maintenance'] != 0 ? 'errorbox' : 'noticebox', '">
-						', $txt[$context['suggested_method']],
-						$context['use_maintenance'] != 0 ? '<br />' . $txt['enable_maintenance' . $context['use_maintenance']] : '',
-					'</div>';
-
-		echo '
-					<p>
-						<label for="struct"><input type="checkbox" name="struct" id="struct" onclick="document.getElementById(\'submitDump\').disabled = !document.getElementById(\'struct\').checked &amp;&amp; !document.getElementById(\'data\').checked;" class="input_check" checked="checked" /> ', $txt['maintain_backup_struct'], '</label><br />
-						<label for="data"><input type="checkbox" name="data" id="data" onclick="document.getElementById(\'submitDump\').disabled = !document.getElementById(\'struct\').checked &amp;&amp; !document.getElementById(\'data\').checked;" checked="checked" class="input_check" /> ', $txt['maintain_backup_data'], '</label><br />
-						<label for="compress"><input type="checkbox" name="compress" id="compress" value="gzip"', $context['suggested_method'] == 'zipped_file' ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['maintain_backup_gz'], '</label>
-					</p>
-					<p>
-						<input ', $context['use_maintenance'] == 2 ? 'disabled="disabled" ' : '', 'type="submit" value="', $txt['maintain_backup_save'], '" id="submitDump" onclick="return document.getElementById(\'struct\').checked || document.getElementById(\'data\').checked;" class="button_submit" />
-					</p>';
-	}
-
-	echo '
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
 		</div>';
 
 	// Show an option to convert the body column of the post table to MEDIUMTEXT or TEXT