- Store and Download is now takes advantage of on-the-fly stuff correctly

- Download and deletion of stored backups now allowed


git-svn-id: file:///svn/phpbb/trunk@5789 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
David M 2006-04-16 17:31:02 +00:00
parent b0aa0e6050
commit 8c2f02ca00
4 changed files with 84 additions and 40 deletions

View file

@ -16,7 +16,8 @@
</fieldset> </fieldset>
<fieldset class="submit-buttons"> <fieldset class="submit-buttons">
<input class="button1" type="submit" id="submit" name="submit" value="{L_START_RESTORE}" />&nbsp; <input class="button1" type="submit" id="submit" name="submit" value="{L_START_RESTORE}" />&nbsp;
<input class="button2" type="reset" id="reset" name="reset" value="{L_RESET}" /> <input class="button2" type="submit" id="delete" name="delete" value="{L_DELETE_BACKUP}" />&nbsp;
<input class="button2" type="submit" id="download" name="download" value="{L_DOWNLOAD_BACKUP}" />
</fieldset> </fieldset>
</form> </form>
<!-- ELSE --> <!-- ELSE -->

View file

@ -44,10 +44,21 @@ class acp_database
$format = request_var('method', ''); $format = request_var('method', '');
$where = request_var('where', ''); $where = request_var('where', '');
$store = $download = false;
if ($where == 'store_and_download' || $where == 'store')
{
$store = true;
}
if ($where == 'store_and_download' || $where == 'download')
{
$download = true;
}
@set_time_limit(1200); @set_time_limit(1200);
$filename = time(); $filename = time();
//$time_start = microtime(true);
// We set up the info needed for our on-the-fly creation :D // We set up the info needed for our on-the-fly creation :D
switch ($format) switch ($format)
@ -82,7 +93,7 @@ class acp_database
// memory. The server process can be easily killed by storing too much data at once. // memory. The server process can be easily killed by storing too much data at once.
if ($where == 'store') if ($store == true)
{ {
$file = $phpbb_root_path . 'store/' . $filename . $ext; $file = $phpbb_root_path . 'store/' . $filename . $ext;
@ -93,7 +104,8 @@ class acp_database
trigger_error('Unable to write temporary file to storage folder'); trigger_error('Unable to write temporary file to storage folder');
} }
} }
else
if ($download == true)
{ {
$name = $filename . $ext; $name = $filename . $ext;
header('Pragma: no-cache'); header('Pragma: no-cache');
@ -107,7 +119,6 @@ class acp_database
$sql_data .= "# phpBB Backup Script\n"; $sql_data .= "# phpBB Backup Script\n";
$sql_data .= "# Dump of tables for $table_prefix\n"; $sql_data .= "# Dump of tables for $table_prefix\n";
$sql_data .= "# DATE : " . gmdate("d-m-Y H:i:s", $filename) . " GMT\n"; $sql_data .= "# DATE : " . gmdate("d-m-Y H:i:s", $filename) . " GMT\n";
//$sql_data .= "# START : $time_start\n";
$sql_data .= "#\n"; $sql_data .= "#\n";
switch (SQL_LAYER) switch (SQL_LAYER)
@ -144,11 +155,12 @@ class acp_database
$sql_data .= $this->get_table_structure($table_name); $sql_data .= $this->get_table_structure($table_name);
} }
// Now write the data for the first time. :) // Now write the data for the first time. :)
if ($where !== 'download') if ($store == true)
{ {
$write($fp, $sql_data); $write($fp, $sql_data);
} }
else
if ($download == true)
{ {
if (!empty($oper)) if (!empty($oper))
{ {
@ -209,11 +221,12 @@ class acp_database
} }
$sql_data .= $schema_insert . implode(', ', $values) . ");\n"; $sql_data .= $schema_insert . implode(', ', $values) . ");\n";
if ($where !== 'download') if ($store == true)
{ {
$write($fp, $sql_data); $write($fp, $sql_data);
} }
else
if ($download == true)
{ {
if (!empty($oper)) if (!empty($oper))
{ {
@ -226,6 +239,7 @@ class acp_database
} }
$sql_data = ''; $sql_data = '';
$values = array();
} }
mysqli_free_result($result); mysqli_free_result($result);
} }
@ -254,12 +268,15 @@ class acp_database
$field_set[$j] = $field[$j]->name; $field_set[$j] = $field[$j]->name;
} }
$search = array('\\', "'", "\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
$replace = array('\\\\\\\\', "''", '\0', '\n', '\r', '\Z');
$fields = implode(', ', $field_set); $fields = implode(', ', $field_set);
$values = array();
$schema_insert = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES ('; $schema_insert = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES (';
while ($row = mysql_fetch_row($result)) while ($row = mysql_fetch_row($result))
{ {
$values = array();
for ($j = 0; $j < $fields_cnt; $j++) for ($j = 0; $j < $fields_cnt; $j++)
{ {
if (!isset($row[$j]) || is_null($row[$j])) if (!isset($row[$j]) || is_null($row[$j]))
@ -272,16 +289,17 @@ class acp_database
} }
else else
{ {
$values[] = "'" . $row[$j] . "'"; $values[] = "'" . str_replace($search, $replace, $row[$j]) . "'";
} }
} }
$sql_data .= $schema_insert . implode(', ', $values) . ");\n"; $sql_data .= $schema_insert . implode(', ', $values) . ");\n";
if ($where !== 'download') if ($store == true)
{ {
$write($fp, $sql_data); $write($fp, $sql_data);
} }
else
if ($download == true)
{ {
if (!empty($oper)) if (!empty($oper))
{ {
@ -293,8 +311,6 @@ class acp_database
} }
} }
$sql_data = ''; $sql_data = '';
$values = array();
} }
mysql_free_result($result); mysql_free_result($result);
} }
@ -331,11 +347,12 @@ class acp_database
} }
$sql_data .= 'INSERT INTO ' . $table_name . ' (' . implode(', ', $names) . ') VALUES ('. implode(', ', $data) .");\n"; $sql_data .= 'INSERT INTO ' . $table_name . ' (' . implode(', ', $names) . ') VALUES ('. implode(', ', $data) .");\n";
if ($where !== 'download') if ($store == true)
{ {
$write($fp, $sql_data); $write($fp, $sql_data);
} }
else
if ($download == true)
{ {
if (!empty($oper)) if (!empty($oper))
{ {
@ -413,11 +430,12 @@ class acp_database
// into a valid sql statement to recreate that field in the data. // into a valid sql statement to recreate that field in the data.
$sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n"; $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n";
if ($where !== 'download') if ($store == true)
{ {
$write($fp, $sql_data); $write($fp, $sql_data);
} }
else
if ($download == true)
{ {
if (!empty($oper)) if (!empty($oper))
{ {
@ -428,6 +446,7 @@ class acp_database
echo $sql_data; echo $sql_data;
} }
} }
$sql_data = ''; $sql_data = '';
} }
@ -447,16 +466,13 @@ class acp_database
break; break;
} }
/*$time_stop = microtime(true); if ($store == true)
$sql_data .= "# END : $time_stop\n";
$sql_data .= "# DIFF : ".($time_stop-$time_start);*/
if ($where !== 'download')
{ {
$write($fp, $sql_data); $write($fp, $sql_data);
$close($fp); $close($fp);
} }
else
if ($download == true)
{ {
if (!empty($oper)) if (!empty($oper))
{ {
@ -471,18 +487,6 @@ class acp_database
unset($sql_data); unset($sql_data);
if ($where == 'store_and_download')
{
$name = $filename . $ext;
$fp = fopen("{$phpbb_root_path}store/$name", 'rb');
while ($buffer = fread($fp, 1024))
{
echo $buffer;
}
fclose($fp);
exit;
}
add_log('admin', 'LOG_DB_BACKUP'); add_log('admin', 'LOG_DB_BACKUP');
trigger_error($user->lang['BACKUP_SUCCESS']); trigger_error($user->lang['BACKUP_SUCCESS']);
break; break;
@ -570,6 +574,15 @@ class acp_database
switch ($action) switch ($action)
{ {
case 'submit': case 'submit':
$delete = request_var('delete', '');
if ($delete)
{
$file = request_var('file', '');
unlink($phpbb_root_path . 'store/' . $file);
trigger_error($user->lang['BACKUP_SUCCESS']);
}
$file = request_var('file', ''); $file = request_var('file', '');
$data = ''; $data = '';
@ -588,6 +601,32 @@ class acp_database
break; break;
} }
$download = request_var('download', '');
if ($download)
{
$name = $matches[0];
switch ($matches[2])
{
case 'sql':
$mimetype = 'text/x-sql';
break;
case 'sql.bz2':
$mimetype = 'application/x-bzip2';
break;
case 'sql.gz':
$mimetype = 'application/x-gzip';
break;
}
header('Pragma: no-cache');
header("Content-Type: $mimetype; name=\"$name\"");
header("Content-disposition: attachment; filename=$name");
echo $data;
die;
}
if (!empty($data)) if (!empty($data))
{ {
// Strip out sql comments... // Strip out sql comments...

View file

@ -252,7 +252,7 @@ $lang = array_merge($lang, array(
'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can autologin when they visit the board.', 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can autologin when they visit the board.',
'AUTOLOGIN_LENGTH' => 'Persistent login key expiry days', 'AUTOLOGIN_LENGTH' => 'Persistent login key expiry days',
'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which persistent login keys are removed or zero to disable.', 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which persistent login keys are removed or zero to disable.',
'VISUAL_CONFIRM_REG' => 'Enable visual confirmation', 'VISUAL_CONFIRM_REG' => 'Enable visual confirmation for registrations',
'VISUAL_CONFIRM_REG_EXPLAIN'=> 'Requires new users to enter a random code matching an image to help prevent mass registrations.', 'VISUAL_CONFIRM_REG_EXPLAIN'=> 'Requires new users to enter a random code matching an image to help prevent mass registrations.',
'VISUAL_CONFIRM_POST' => 'Enable visual confirmation for guest postings', 'VISUAL_CONFIRM_POST' => 'Enable visual confirmation for guest postings',
'VISUAL_CONFIRM_POST_EXPLAIN'=> 'Requires anonymous users to enter a random code matching an image to help prevent mass postings.', 'VISUAL_CONFIRM_POST_EXPLAIN'=> 'Requires anonymous users to enter a random code matching an image to help prevent mass postings.',

View file

@ -47,10 +47,14 @@ $lang = array_merge($lang, array(
'STORE_AND_DOWNLOAD' => 'Store and Download', 'STORE_AND_DOWNLOAD' => 'Store and Download',
'ACP_RESTORE' => 'Restore', 'ACP_RESTORE' => 'Restore',
'ACP_RESTORE_EXPLAIN' => 'This will perform a full restore of all phpBB tables from a saved file. You can <u>either</u> upload the backup file via this form or upload it manually to a location on the server. If your server supports it you may use a gzip compressed text file and it will automatically be decompressed. <b>WARNING</b> This will overwrite any existing data. The restore may take a long time to process please do not move from this page till it is complete.', 'ACP_RESTORE_EXPLAIN' => 'This will perform a full restore of all phpBB tables from a saved file. You can <u>either</u> upload the backup file via this form or upload it manually to a location on the server. If your server supports it you may use a gzip or bzip2 compressed text file and it will automatically be decompressed. <b>WARNING</b> This will overwrite any existing data. The restore may take a long time to process please do not move from this page till it is complete.',
'SELECT_FILE' => 'Select a file', 'SELECT_FILE' => 'Select a file',
'RESTORE_OPTIONS' => 'Restore options',
'START_RESTORE' => 'Start Restore', 'START_RESTORE' => 'Start Restore',
'DELETE_BACKUP' => 'Delete Backup',
'DOWNLOAD_BACKUP' => 'Download Backup',
'RESTORE_SUCCESS' => 'The Database has been successfully restored.<br /><br />Your board should be back to the state it was when the backup was made.', 'RESTORE_SUCCESS' => 'The Database has been successfully restored.<br /><br />Your board should be back to the state it was when the backup was made.',
'BACKUP_SUCCESS' => 'The backup has been successfully deleted.',
)); ));
?> ?>