📄 bigdump.php
字号:
<?php// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );//TODO: Rewrite this so its cleaner// BigDump ver. 0.28b from 2007-06-08// Staggered import of an large MySQL Dump (like phpMyAdmin 2.x Dump)// Even through the webservers with hard runtime limit and those in safe mode// Works fine with Internet Explorer 7.0 and Firefox 2.x// Author: Alexey Ozerov (alexey at ozerov dot de)// AJAX & CSV functionalities: Krzysiek Herod (kr81uni at wp dot pl)// Copyright: GPL (C) 2003-2007// More Infos: http://www.ozerov.de/bigdump.php// This program is free software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the Free Software Foundation;// either version 2 of the License, or (at your option) any later version.// THIS SCRIPT IS PROVIDED AS IS, WITHOUT ANY WARRANTY OR GUARANTEE OF ANY KIND// USAGE// 1. Adjust the database configuration in this file// 2. Drop the old tables on the target database if your dump doesn't contain "DROP TABLE"// 3. Create the working directory (e.g. dump) on your web-server// 4. Upload bigdump.php and your dump files (.sql, .gz) via FTP to the working directory// 5. Run the bigdump.php from your browser via URL like http://www.yourdomain.com/dump/bigdump.php// 6. BigDump can start the next import session automatically if you enable the JavaScript// 7. Wait for the script to finish, do not close the browser window// 8. IMPORTANT: Remove bigdump.php and your dump files from the web-server// If Timeout errors still occure you may need to adjust the $linepersession setting in this file// LAST CHANGES// *** Improved error message for file open errors// *** Handle CSV files (you have to specify $csv_insert_table)// *** Restart script in the background using AJAX/** * Big Dump Handler for Migration and Import * Rewritten by Sam Moffatt from original work by Alexey Ozerov) for Joomla! 1.5 *///defined('_JEXEC') or die('Access Denied');// Database configuration$db_server = '';$db_name = '';$db_username = '';$db_password = '';?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title><?php JText::_('Migration load script') ?></title><script type="text/javascript" src="includes/js/installation.js"></script></head><body><?php// Other Settings$csv_insert_table = ''; // Destination table for CSV files$ajax = false; // AJAX mode: import will be done without refreshing the website//$filename = ''; // Specify the dump filename to suppress the file selection dialog$linespersession = 3000; // Lines to be executed per one import session$delaypersession = 0; // You can specify a sleep time in milliseconds after each session// Works only if JavaScript is activated. Use to reduce server overrun// Allowed comment delimiters: lines starting with these strings will be dropped by BigDump$comment[] = '#'; // Standard comment lines are dropped by default$comment[] = '-- ';// $comment[]='---'; // Uncomment this line if using proprietary dump created by outdated mysqldump// $comment[]='/*!'; // Or add your own string to leave out other proprietary things// Connection character set should be the same as the dump file character set (utf8, latin1, cp1251, koi8r etc.)// See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for the full list$db_connection_charset = '';// *******************************************************************************************// If not familiar with PHP please don't change anything below this line// *******************************************************************************************ob_start();define('VERSION', '0.28b');define('DATA_CHUNK_LENGTH', 16384); // How many chars are read per timedefine('MAX_QUERY_LINES', 300); // How many lines may be considered to be one query (except text lines)define('TESTMODE', false); // Set to true to process the file without actually accessing the databaseheader("Expires: Mon, 1 Dec 2003 01:00:00 GMT");header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");header("Cache-Control: no-store, no-cache, must-revalidate");header("Cache-Control: post-check=0, pre-check=0", false);header("Pragma: no-cache");//@ini_set('auto_detect_line_endings', true);//@set_time_limit(0);// Clean and strip anything we don't want from user's input [0.27b]foreach ($_REQUEST as $key => $val) { $val = preg_replace("/[^_A-Za-z0-9-\.&=]/i", '', $val); $_REQUEST[$key] = $val;}// Determine filename to execute for loading...$filename = JPATH_BASE . DS . 'sql' . DS . 'migration' . DS . 'migrate.sql';$_REQUEST['fn'] = $filename;$error = false;$file = false;// Single file modeif (!$error && !isset ($_REQUEST["fn"]) && $filename != "") { echo ("<p><a href=\"" . $_SERVER["PHP_SELF"] . "?start=1&fn=$filename&foffset=0&totalqueries=0\">Start Import</a> from $filename into $db_name at $db_server</p>\n");}// Open the fileif (!$error && isset ($_REQUEST["fn"])) { // Recognize GZip filename if (eregi("\.gz$", $_REQUEST["fn"])) $gzipmode = true; else $gzipmode = false; if ((!$gzipmode && !$file = fopen($_REQUEST["fn"], "rt")) || ($gzipmode && !$file = gzopen($_REQUEST["fn"], "rt"))) { echo ("<p class=\"error\">". JText::sprintf("Cant open file for import", $_REQUEST["fn"]) ."</p>\n"); echo ("<p>". JText::_('CHECKDUMPFILE') . " .<br />". JText::_('NEEDTOUPLOADFILE')."</p>\n"); $error = true; } // Get the file size (can't do it fast on gzipped files, no idea how) else if ((!$gzipmode && fseek($file, 0, SEEK_END) == 0) || ($gzipmode && gzseek($file, 0) == 0)) { if (!$gzipmode) $filesize = ftell($file); else $filesize = gztell($file); // Always zero, ignore } else { echo ("<p class=\"error\">". JText::_('FILESIZEUNKNOWN') . $_REQUEST["fn"] . "</p>\n"); $error = true; }}// *******************************************************************************************// START IMPORT SESSION HERE// *******************************************************************************************if (!$error && isset ($_REQUEST["start"]) && isset ($_REQUEST["foffset"]) && eregi("(\.(sql|gz|csv))$", $_REQUEST["fn"])) { // Check start and foffset are numeric values if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"])) { echo ("<p class=\"error\">". JText::_('NONNUMERICOFFSET') ."</p>\n"); $error = true; } if (!$error) { $_REQUEST["start"] = floor($_REQUEST["start"]); $_REQUEST["foffset"] = floor($_REQUEST["foffset"]); } // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files) if (!$error && !$gzipmode && $_REQUEST["foffset"] > $filesize) { echo ("<p class=\"error\">".JText::_('POINTEREOF')."</p>\n"); $error = true; } // Set file pointer to $_REQUEST["foffset"] if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"]) != 0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"]) != 0))) { echo ("<p class=\"error\">". JText::_('UNABLETOSETOFFSET') . $_REQUEST["foffset"] . "</p>\n"); $error = true; } // Start processing queries from $file if (!$error) { $query = ""; $queries = 0; $totalqueries = $_REQUEST["totalqueries"]; $linenumber = $_REQUEST["start"]; $querylines = 0; $inparents = false; // Stay processing as long as the $linespersession is not reached or the query is still incomplete while ($linenumber < $_REQUEST["start"] + $linespersession || $query != "") { // Read the whole next line $dumpline = ""; while (!feof($file) && substr($dumpline, -1) != "\n") { if (!$gzipmode) $dumpline .= fgets($file, DATA_CHUNK_LENGTH); else $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); } if ($dumpline === "") break; // Handle DOS and Mac encoded linebreaks (I don't know if it will work on Win32 or Mac Servers) $dumpline = str_replace("\r\n", "\n", $dumpline); $dumpline = str_replace("\r", "\n", $dumpline); // DIAGNOSTIC // echo ("<p>Line $linenumber: $dumpline</p>\n"); // Skip comments and blank lines only if NOT in parents if (!$inparents) { $skipline = false; reset($comment); foreach ($comment as $comment_value) { if (!$inparents && (trim($dumpline) == "" || strpos($dumpline, $comment_value) === 0)) { $skipline = true; break; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -