Esempio n. 1
0
 function backup()
 {
     if (!isset($_POST)) {
         $this->main();
     }
     set_error_handler("SXD_errorHandler");
     $buttons = "<A ID=save HREF='' STYLE='display: none;'>Download File</A> &nbsp; <INPUT ID=back TYPE=button VALUE='Tr&#7903; V&#7873;' DISABLED onClick=\"history.back();\">";
     echo tpl_page(tpl_process("Xin vui l&ograve;ng ch&#7901; &#273;&#7907;i trong gi&acirc;y l&aacute;t... "), $buttons);
     $this->SET['last_action'] = 0;
     $this->SET['last_db_backup'] = isset($_POST['db_backup']) ? $_POST['db_backup'] : '';
     $this->SET['tables_exclude'] = !empty($_POST['tables']) && $_POST['tables'][0] == '^' ? 1 : 0;
     $this->SET['tables'] = isset($_POST['tables']) ? $_POST['tables'] : '';
     $this->SET['comp_method'] = isset($_POST['comp_method']) ? intval($_POST['comp_method']) : 0;
     $this->SET['comp_level'] = isset($_POST['comp_level']) ? intval($_POST['comp_level']) : 0;
     $this->fn_save();
     $this->SET['tables'] = explode(",", $this->SET['tables']);
     if (!empty($_POST['tables'])) {
         foreach ($this->SET['tables'] as $table) {
             $table = preg_replace("/[^\\w*?^]/", "", $table);
             $pattern = array("/\\?/", "/\\*/");
             $replace = array(".", ".*?");
             $tbls[] = preg_replace($pattern, $replace, $table);
         }
     } else {
         $this->SET['tables_exclude'] = 1;
     }
     if ($this->SET['comp_level'] == 0) {
         $this->SET['comp_method'] = 0;
     }
     $db = $this->SET['last_db_backup'];
     if (!$db) {
         echo tpl_l("ERROR! No database!", C_ERROR);
         echo tpl_enableBack();
         exit;
     }
     echo tpl_l("&#272;ang k&#7871;t n&#7889;i c&#417; s&#7903; d&#7919; li&#7879;u.");
     mysql_select_db($db) or trigger_error("Unable to select database.<BR>" . mysql_error(), E_USER_ERROR);
     $tables = array();
     $result = mysql_query("SHOW TABLES");
     $all = 0;
     while ($row = mysql_fetch_array($result)) {
         $status = 0;
         if (!empty($tbls)) {
             foreach ($tbls as $table) {
                 $exclude = preg_match("/^\\^/", $table) ? true : false;
                 if (!$exclude) {
                     if (preg_match("/^{$table}\$/i", $row[0])) {
                         $status = 1;
                     }
                     $all = 1;
                 }
                 if ($exclude && preg_match("/{$table}\$/i", $row[0])) {
                     $status = -1;
                 }
             }
         } else {
             $status = 1;
         }
         if ($status >= $all) {
             $tables[] = $row[0];
         }
     }
     $tabs = count($tables);
     // Determination of tables
     $result = mysql_query("SHOW TABLE STATUS");
     $tabinfo = array();
     $tab_charset = array();
     $tab_type = array();
     $tabinfo[0] = 0;
     $info = '';
     while ($item = mysql_fetch_assoc($result)) {
         //print_r($item);
         if (in_array($item['Name'], $tables)) {
             $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows'];
             $tabinfo[0] += $item['Rows'];
             $tabinfo[$item['Name']] = $item['Rows'];
             $this->size += $item['Data_length'];
             $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1));
             if ($item['Rows']) {
                 $info .= "|" . $item['Rows'];
             }
             if (!empty($item['Collation']) && preg_match("/^([a-z0-9]+)_/i", $item['Collation'], $m)) {
                 $tab_charset[$item['Name']] = $m[1];
             }
             $tab_type[$item['Name']] = isset($item['Engine']) ? $item['Engine'] : $item['Type'];
         }
     }
     $show = 10 + $tabinfo[0] / 50;
     $info = $tabinfo[0] . $info;
     $name = $db . '_' . date("Y-m-d_H-i");
     $fp = $this->fn_open($name, "w");
     echo tpl_l("B&#7855;t &#273;&#7847;u t&#7841;o t&ecirc;n c&#417; s&#7903; d&#7919; li&#7879;u :<BR>\\n  -  {$this->filename}");
     $this->fn_write($fp, "#SKD101|{$db}|{$tabs}|" . date("Y.m.d H:i:s") . "|{$info}\n\n");
     $t = 0;
     echo tpl_l(str_repeat("-", 60));
     $result = mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
     // Encoding connections by default
     if ($this->mysql_version > 40101 && CHARSET != 'auto') {
         mysql_query("SET NAMES '" . CHARSET . "'") or trigger_error("Cannot set the encoding for the connection.<BR>" . mysql_error(), E_USER_ERROR);
         $last_charset = CHARSET;
     } else {
         $last_charset = '';
     }
     foreach ($tables as $table) {
         // Bill encoding connecting the encoding tables
         if ($this->mysql_version > 40101 && $tab_charset[$table] != $last_charset) {
             if (CHARSET == 'auto') {
                 mysql_query("SET NAMES '" . $tab_charset[$table] . "'") or trigger_error("Cannot set the encoding for the connection.<BR>" . mysql_error(), E_USER_ERROR);
                 echo tpl_l("Using encoding `" . $tab_charset[$table] . "`.", C_WARNING);
                 $last_charset = $tab_charset[$table];
             } else {
                 echo tpl_l('Encoding connections, and the table does not match:', C_ERROR);
                 echo tpl_l('Table  `' . $table . '` -> ' . $tab_charset[$table] . ' (Connection  ' . CHARSET . ')', C_ERROR);
             }
         }
         echo tpl_l("Processing Table`{$table}` [" . fn_int($tabinfo[$table]) . "].");
         // Creating tables
         $result = mysql_query("SHOW CREATE TABLE `{$table}`");
         $tab = mysql_fetch_array($result);
         $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab);
         $this->fn_write($fp, "DROP TABLE IF EXISTS `{$table}`;\n{$tab[1]};\n\n");
         // Checking whether dampit data
         if (in_array($tab_type[$table], $this->only_create)) {
             continue;
         }
         // Oprededelyaem types of columns
         $NumericColumn = array();
         $result = mysql_query("SHOW COLUMNS FROM `{$table}`");
         $field = 0;
         while ($col = mysql_fetch_row($result)) {
             $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0;
         }
         $fields = $field;
         $from = 0;
         $limit = $tabsize[$table];
         $limit2 = round($limit / 3);
         if ($tabinfo[$table] > 0) {
             if ($tabinfo[$table] > $limit2) {
                 echo tpl_s(0, $t / $tabinfo[0]);
             }
             $i = 0;
             $this->fn_write($fp, "INSERT INTO `{$table}` VALUES");
             while (($result = mysql_query("SELECT * FROM `{$table}` LIMIT {$from}, {$limit}")) && ($total = mysql_num_rows($result))) {
                 while ($row = mysql_fetch_row($result)) {
                     $i++;
                     $t++;
                     for ($k = 0; $k < $fields; $k++) {
                         if ($NumericColumn[$k]) {
                             $row[$k] = isset($row[$k]) ? $row[$k] : "NULL";
                         } else {
                             $row[$k] = isset($row[$k]) ? "'" . mysql_escape_string($row[$k]) . "'" : "NULL";
                         }
                     }
                     $this->fn_write($fp, ($i == 1 ? "" : ",") . "\n(" . implode(", ", $row) . ")");
                     if ($i % $limit2 == 0) {
                         echo tpl_s($i / $tabinfo[$table], $t / $tabinfo[0]);
                     }
                 }
                 mysql_free_result($result);
                 if ($total < $limit) {
                     break;
                 }
                 $from += $limit;
             }
             $this->fn_write($fp, ";\n\n");
             echo tpl_s(1, $t / $tabinfo[0]);
         }
     }
     $this->tabs = $tabs;
     $this->records = $tabinfo[0];
     $this->comp = $this->SET['comp_method'] * 10 + $this->SET['comp_level'];
     echo tpl_s(1, 1);
     echo tpl_l(str_repeat("-", 60));
     $this->fn_close($fp);
     echo tpl_l("<b>Qu&aacute; tr&igrave;nh x&#7917; l&yacute; c&#417; s&#7903; d&#7919; li&#7879;u `{$db}` &#273;&atilde; th&agrave;nh c&ocirc;ng.</b>", C_RESULT);
     echo tpl_l("Size of DB : " . round($this->size / 1048576, 2) . ".", C_RESULT);
     $filesize = round(filesize(PATH . $this->filename) / 1048576, 2) . ".";
     echo tpl_l("Size of file : {$filesize}", C_RESULT);
     echo tpl_l("Tables processed : {$tabs}", C_RESULT);
     echo tpl_l("Lines processed :   " . fn_int($tabinfo[0]), C_RESULT);
     echo "<SCRIPT>with (document.getElementById('save')) {style.display = ''; innerHTML = '<font color=red>T&#7843;i c&#417; s&#7903; d&#7919; li&#7879;u v&#7873; m&aacute;y</font> ({$filesize})'; href = '" . URL . $this->filename . "'; }document.getElementById('back').disabled = 0;</SCRIPT>";
     // Data Transfer for global statistics
     if (GS) {
         echo "<SCRIPT>document.getElementById('GS').src = 'http://sypex.net/gs.php?b={$this->tabs},{$this->records},{$this->size},{$this->comp},108';</SCRIPT>";
     }
 }
Esempio n. 2
0
 function backup()
 {
     global $lang;
     if (!isset($_POST['comp_method'])) {
         $_POST['comp_method'] = $_GET['comp_method'];
     }
     @set_error_handler("SXD_errorHandler", E_ALL ^ E_NOTICE);
     $buttons = "<span ID=save STYLE='display: none;'>{$lang['dumper_1']}</span>";
     echo tpl_page(tpl_process($lang['dumper_2']), $buttons);
     $this->SET['last_action'] = 0;
     $this->SET['last_db_backup'] = DBNAMES;
     $this->SET['tables_exclude'] = 0;
     $this->SET['tables'] = DBPREFIX . '*';
     $this->SET['comp_method'] = isset($_POST['comp_method']) ? intval($_POST['comp_method']) : 0;
     $this->SET['comp_level'] = 5;
     $this->SET['tables'] = explode(",", $this->SET['tables']);
     foreach ($this->SET['tables'] as $table) {
         $table = preg_replace("/[^\\w*?^]/", "", $table);
         $pattern = array("/\\?/", "/\\*/");
         $replace = array(".", ".*?");
         $tbls[] = preg_replace($pattern, $replace, $table);
     }
     if ($this->SET['comp_level'] == 0) {
         $this->SET['comp_method'] = 0;
     }
     $db = $this->SET['last_db_backup'];
     if (!$db) {
         echo tpl_l($lang['dumper_3'], C_ERROR);
         exit;
     }
     echo tpl_l("{$lang['dumper_20']} `{$db}`.");
     mysql_select_db($db) or trigger_error($lang['dumper_4'] . mysql_error(), E_USER_ERROR);
     $tables = array();
     $result = mysql_query("SHOW TABLES");
     $all = 0;
     while ($row = mysql_fetch_array($result)) {
         $status = 0;
         if (!empty($tbls)) {
             foreach ($tbls as $table) {
                 $exclude = preg_match("/^\\^/", $table) ? true : false;
                 if (!$exclude) {
                     if (preg_match("/^{$table}\$/i", $row[0])) {
                         $status = 1;
                     }
                     $all = 1;
                 }
                 if ($exclude && preg_match("/{$table}\$/i", $row[0])) {
                     $status = -1;
                 }
             }
         } else {
             $status = 1;
         }
         if ($status >= $all) {
             $tables[] = $row[0];
         }
     }
     $tabs = count($tables);
     // Определение размеров таблиц
     $result = mysql_query("SHOW TABLE STATUS");
     $tabinfo = array();
     $tab_charset = array();
     $tab_type = array();
     $tabinfo[0] = 0;
     $info = '';
     while ($item = mysql_fetch_assoc($result)) {
         //print_r($item);
         if (in_array($item['Name'], $tables)) {
             $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows'];
             $tabinfo[0] += $item['Rows'];
             $tabinfo[$item['Name']] = $item['Rows'];
             $this->size += $item['Data_length'];
             $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1));
             if ($item['Rows']) {
                 $info .= "|" . $item['Rows'];
             }
             if (!empty($item['Collation']) && preg_match("/^([a-z0-9]+)_/i", $item['Collation'], $m)) {
                 $tab_charset[$item['Name']] = $m[1];
             }
             $tab_type[$item['Name']] = isset($item['Engine']) ? $item['Engine'] : $item['Type'];
         }
     }
     $show = 10 + $tabinfo[0] / 50;
     $info = $tabinfo[0] . $info;
     $salt = "abchefghjkmnpqrstuvwxyz0123456789";
     // srand((double)microtime()*1000000);
     $rand = "";
     for ($i = 0; $i < 9; $i++) {
         $rand .= $salt[rand(0, 33)];
     }
     if (!defined('AUTOMODE')) {
         $name = $db . '_' . date("Y-m-d_H-i") . '_' . substr(md5(date("Y-m-d_H-i") . DBHOST . DBNAME), 0, 5);
     } else {
         $name = date("Y-m-d_H-i") . '_' . $db . '_' . md5($rand);
     }
     $fp = $this->fn_open($name, "w");
     echo tpl_l($lang['dumper_5']);
     $this->fn_write($fp, "#SKD101|{$db}|{$tabs}|" . date("Y.m.d H:i:s") . "|{$info}\n\n");
     $t = 0;
     echo tpl_l(str_repeat("-", 60));
     $result = mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
     // Кодировка соединения по умолчанию
     if ($this->mysql_version > 40101 && CHARSET != 'auto') {
         mysql_query("SET NAMES '" . CHARSET . "'") or trigger_error($lang['dumper_6'] . mysql_error(), E_USER_ERROR);
         $last_charset = CHARSET;
     } else {
         $last_charset = '';
     }
     foreach ($tables as $table) {
         // Выставляем кодировку соединения соответствующую кодировке таблицы
         if ($this->mysql_version > 40101 && $tab_charset[$table] != $last_charset) {
             if (CHARSET == 'auto') {
                 mysql_query("SET NAMES '" . $tab_charset[$table] . "'") or trigger_error($lang['dumper_6'] . mysql_error(), E_USER_ERROR);
                 echo tpl_l("{$lang['dumper_7']} `" . $tab_charset[$table] . "`.", C_WARNING);
                 $last_charset = $tab_charset[$table];
             } else {
                 echo tpl_l($lang['dumper_8'], C_ERROR);
                 echo tpl_l($lang['dumper_9'] . ' `' . $table . '` -> ' . $tab_charset[$table] . ' (' . $lang['dumper_10'] . ' ' . CHARSET . ')', C_ERROR);
             }
         }
         echo tpl_l("{$lang['dumper_11']} `{$table}` [" . fn_int($tabinfo[$table]) . "].");
         // Создание таблицы
         $result = mysql_query("SHOW CREATE TABLE `{$table}`");
         $tab = mysql_fetch_array($result);
         $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab);
         $this->fn_write($fp, "DROP TABLE IF EXISTS `{$table}`;\n{$tab[1]};\n\n");
         // Проверяем нужно ли дампить данные
         if (in_array($tab_type[$table], $this->only_create)) {
             continue;
         }
         // Опредеделяем типы столбцов
         $NumericColumn = array();
         $result = mysql_query("SHOW COLUMNS FROM `{$table}`");
         $field = 0;
         while ($col = mysql_fetch_row($result)) {
             $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0;
         }
         $fields = $field;
         $from = 0;
         $limit = $tabsize[$table];
         $limit2 = round($limit / 3);
         if ($tabinfo[$table] > 0) {
             if ($tabinfo[$table] > $limit2) {
                 echo tpl_s(0, $t / $tabinfo[0]);
             }
             $i = 0;
             $this->fn_write($fp, "INSERT INTO `{$table}` VALUES");
             while (($result = mysql_query("SELECT * FROM `{$table}` LIMIT {$from}, {$limit}")) && ($total = mysql_num_rows($result))) {
                 while ($row = mysql_fetch_row($result)) {
                     $i++;
                     $t++;
                     for ($k = 0; $k < $fields; $k++) {
                         if ($NumericColumn[$k]) {
                             $row[$k] = isset($row[$k]) ? $row[$k] : "NULL";
                         } else {
                             $row[$k] = isset($row[$k]) ? "'" . mysql_escape_string($row[$k]) . "'" : "NULL";
                         }
                     }
                     $this->fn_write($fp, ($i == 1 ? "" : ",") . "\n(" . implode(", ", $row) . ")");
                     if ($i % $limit2 == 0) {
                         echo tpl_s($i / $tabinfo[$table], $t / $tabinfo[0]);
                     }
                 }
                 mysql_free_result($result);
                 if ($total < $limit) {
                     break;
                 }
                 $from += $limit;
             }
             $this->fn_write($fp, ";\n\n");
             echo tpl_s(1, $t / $tabinfo[0]);
         }
     }
     $this->tabs = $tabs;
     $this->records = $tabinfo[0];
     $this->comp = $this->SET['comp_method'] * 10 + $this->SET['comp_level'];
     echo tpl_s(1, 1);
     echo tpl_l(str_repeat("-", 60));
     $this->fn_close($fp);
     echo tpl_l("{$lang['dumper_12']} `{$db}` {$lang['dumper_13']}", C_RESULT);
     echo tpl_l("{$lang['dumper_14']}       " . round($this->size / 1048576, 2) . " MB", C_RESULT);
     $filesize = round(filesize(PATH . $this->filename) / 1048576, 2) . " MB";
     echo tpl_l("{$lang['dumper_15']} {$filesize}", C_RESULT);
     echo tpl_l("{$lang['dumper_16']} {$tabs}", C_RESULT);
     echo tpl_l("{$lang['dumper_17']}   " . fn_int($tabinfo[0]), C_RESULT);
     if (!defined('AUTOMODE')) {
         echo "<SCRIPT>if (document.getElementById('save')) {document.getElementById('save').style.display = ''; }</SCRIPT>";
     }
 }
Esempio n. 3
0
File: dumper.php Progetto: skotin/EW
 function backup()
 {
     if (!isset($_POST)) {
         $this->main();
     }
     set_error_handler("SXD_errorHandler");
     $buttons = "<A ID=save HREF='' STYLE='display: none;'>Скачать файл</A> &nbsp; <INPUT ID=back TYPE=button VALUE='Вернуться' DISABLED onClick=\"history.back();\">";
     echo tpl_page(tpl_process("Создается резервная копия БД"), $buttons);
     $this->SET['last_action'] = 0;
     $this->SET['last_db_backup'] = isset($_POST['db_backup']) ? $_POST['db_backup'] : '';
     $this->SET['tables_exclude'] = !empty($_POST['tables']) && $_POST['tables'][0] == '^' ? 1 : 0;
     $this->SET['tables'] = isset($_POST['tables']) ? $_POST['tables'] : '';
     $this->SET['comp_method'] = isset($_POST['comp_method']) ? intval($_POST['comp_method']) : 0;
     $this->SET['comp_level'] = isset($_POST['comp_level']) ? intval($_POST['comp_level']) : 0;
     $this->fn_save();
     $this->SET['tables'] = explode(",", $this->SET['tables']);
     if (!empty($_POST['tables'])) {
         foreach ($this->SET['tables'] as $table) {
             $table = preg_replace("/[^\\w*?^]/", "", $table);
             $pattern = array("/\\?/", "/\\*/");
             $replace = array(".", ".*?");
             $tbls[] = preg_replace($pattern, $replace, $table);
         }
     } else {
         $this->SET['tables_exclude'] = 1;
     }
     if ($this->SET['comp_level'] == 0) {
         $this->SET['comp_method'] = 0;
     }
     $db = $this->SET['last_db_backup'];
     if (!$db) {
         echo tpl_l("ОШИБКА! Не указана база данных!", C_ERROR);
         echo tpl_enableBack();
         exit;
     }
     echo tpl_l("Подключение к БД `{$db}`.");
     mysql_select_db($db) or trigger_error("Не удается выбрать базу данных.<BR>" . mysql_error(), E_USER_ERROR);
     $tables = array();
     $result = mysql_query("SHOW TABLES");
     $all = 0;
     while ($row = mysql_fetch_array($result)) {
         $status = 0;
         if (!empty($tbls)) {
             foreach ($tbls as $table) {
                 $exclude = preg_match("/^\\^/", $table) ? true : false;
                 if (!$exclude) {
                     if (preg_match("/^{$table}\$/i", $row[0])) {
                         $status = 1;
                     }
                     $all = 1;
                 }
                 if ($exclude && preg_match("/{$table}\$/i", $row[0])) {
                     $status = -1;
                 }
             }
         } else {
             $status = 1;
         }
         if ($status >= $all) {
             $tables[] = $row[0];
         }
     }
     $tabs = count($tables);
     // Определение размеров таблиц
     $result = mysql_query("SHOW TABLE STATUS");
     $tabinfo = array();
     $tab_charset = array();
     $tab_type = array();
     $tabinfo[0] = 0;
     $info = '';
     while ($item = mysql_fetch_assoc($result)) {
         //print_r($item);
         if (in_array($item['Name'], $tables)) {
             $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows'];
             $tabinfo[0] += $item['Rows'];
             $tabinfo[$item['Name']] = $item['Rows'];
             $this->size += $item['Data_length'];
             $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1));
             if ($item['Rows']) {
                 $info .= "|" . $item['Rows'];
             }
             if (!empty($item['Collation']) && preg_match("/^([a-z0-9]+)_/i", $item['Collation'], $m)) {
                 $tab_charset[$item['Name']] = $m[1];
             }
             $tab_type[$item['Name']] = isset($item['Engine']) ? $item['Engine'] : $item['Type'];
         }
     }
     $show = 10 + $tabinfo[0] / 50;
     $info = $tabinfo[0] . $info;
     $name = $db . '_' . date("Y-m-d_H-i");
     $fp = $this->fn_open($name, "w");
     echo tpl_l("Создание файла с резервной копией БД:<BR>\\n  -  {$this->filename}");
     $this->fn_write($fp, "#SKD101|{$db}|{$tabs}|" . date("Y.m.d H:i:s") . "|{$info}\n\n");
     $t = 0;
     echo tpl_l(str_repeat("-", 60));
     $result = mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
     // Кодировка соединения по умолчанию
     if ($this->mysql_version > 40101 && CHARSET != 'auto') {
         mysql_query("SET NAMES '" . CHARSET . "'") or trigger_error("Неудается изменить кодировку соединения.<BR>" . mysql_error(), E_USER_ERROR);
         $last_charset = CHARSET;
     } else {
         $last_charset = '';
     }
     foreach ($tables as $table) {
         // Выставляем кодировку соединения соответствующую кодировке таблицы
         if ($this->mysql_version > 40101 && $tab_charset[$table] != $last_charset) {
             if (CHARSET == 'auto') {
                 mysql_query("SET NAMES '" . $tab_charset[$table] . "'") or trigger_error("Неудается изменить кодировку соединения.<BR>" . mysql_error(), E_USER_ERROR);
                 echo tpl_l("Установлена кодировка соединения `" . $tab_charset[$table] . "`.", C_WARNING);
                 $last_charset = $tab_charset[$table];
             } else {
                 echo tpl_l('Кодировка соединения и таблицы не совпадает:', C_ERROR);
                 echo tpl_l('Таблица `' . $table . '` -> ' . $tab_charset[$table] . ' (соединение ' . CHARSET . ')', C_ERROR);
             }
         }
         echo tpl_l("Обработка таблицы `{$table}` [" . fn_int($tabinfo[$table]) . "].");
         // Создание таблицы
         $result = mysql_query("SHOW CREATE TABLE `{$table}`");
         $tab = mysql_fetch_array($result);
         $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab);
         $this->fn_write($fp, "DROP TABLE IF EXISTS `{$table}`;\n{$tab[1]};\n\n");
         // Проверяем нужно ли дампить данные
         if (in_array($tab_type[$table], $this->only_create)) {
             continue;
         }
         // Опредеделяем типы столбцов
         $NumericColumn = array();
         $result = mysql_query("SHOW COLUMNS FROM `{$table}`");
         $field = 0;
         while ($col = mysql_fetch_row($result)) {
             $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0;
         }
         $fields = $field;
         $from = 0;
         $limit = $tabsize[$table];
         $limit2 = round($limit / 3);
         if ($tabinfo[$table] > 0) {
             if ($tabinfo[$table] > $limit2) {
                 echo tpl_s(0, $t / $tabinfo[0]);
             }
             $i = 0;
             $this->fn_write($fp, "INSERT INTO `{$table}` VALUES");
             while (($result = mysql_query("SELECT * FROM `{$table}` LIMIT {$from}, {$limit}")) && ($total = mysql_num_rows($result))) {
                 while ($row = mysql_fetch_row($result)) {
                     $i++;
                     $t++;
                     for ($k = 0; $k < $fields; $k++) {
                         if ($NumericColumn[$k]) {
                             $row[$k] = isset($row[$k]) ? $row[$k] : "NULL";
                         } else {
                             $row[$k] = isset($row[$k]) ? "'" . mysql_escape_string($row[$k]) . "'" : "NULL";
                         }
                     }
                     $this->fn_write($fp, ($i == 1 ? "" : ",") . "\n(" . implode(", ", $row) . ")");
                     if ($i % $limit2 == 0) {
                         echo tpl_s($i / $tabinfo[$table], $t / $tabinfo[0]);
                     }
                 }
                 mysql_free_result($result);
                 if ($total < $limit) {
                     break;
                 }
                 $from += $limit;
             }
             $this->fn_write($fp, ";\n\n");
             echo tpl_s(1, $t / $tabinfo[0]);
         }
     }
     $this->tabs = $tabs;
     $this->records = $tabinfo[0];
     $this->comp = $this->SET['comp_method'] * 10 + $this->SET['comp_level'];
     echo tpl_s(1, 1);
     echo tpl_l(str_repeat("-", 60));
     $this->fn_close($fp);
     echo tpl_l("Резервная копия БД `{$db}` создана.", C_RESULT);
     echo tpl_l("Размер БД:       " . round($this->size / 1048576, 2) . " МБ", C_RESULT);
     $filesize = round(filesize(PATH . $this->filename) / 1048576, 2) . " МБ";
     echo tpl_l("Размер файла: {$filesize}", C_RESULT);
     echo tpl_l("Таблиц обработано: {$tabs}", C_RESULT);
     echo tpl_l("Строк обработано:   " . fn_int($tabinfo[0]), C_RESULT);
     echo "<SCRIPT>with (document.getElementById('save')) {style.display = ''; innerHTML = 'Скачать файл ({$filesize})'; href = '" . URL . $this->filename . "'; }document.getElementById('back').disabled = 0;</SCRIPT>";
     // Передача данных для глобальной статистики
     if (GS) {
         echo "<SCRIPT>document.getElementById('GS').src = 'http://sypex.net/gs.php?b={$this->tabs},{$this->records},{$this->size},{$this->comp},108';</SCRIPT>";
     }
 }
Esempio n. 4
0
 function backup()
 {
     $this->SET['tables'] = explode(",", $this->SET['tables']);
     if (!empty($_POST['tables'])) {
         foreach ($this->SET['tables'] as $table) {
             $table = preg_replace("/[^\\w*?^]/", "", $table);
             $pattern = array("/\\?/", "/\\*/");
             $replace = array(".", ".*?");
             $tbls[] = preg_replace($pattern, $replace, $table);
         }
     } else {
         $this->SET['tables_exclude'] = 1;
     }
     if ($this->SET['comp_level'] == 0) {
         $this->SET['comp_method'] = 0;
     }
     $db = DB_NAME;
     if (!$db) {
         echo tpl_l("ОШИБКА! Не указана база данных!", C_ERROR);
         echo tpl_enableBack();
         exit;
     }
     echo tpl_l("Подключение к БД `{$db}`.");
     mysql_select_db($db) or trigger_error("Не удается выбрать базу данных.<BR>" . mysql_error(), E_USER_ERROR);
     $tables = array();
     $result = mysql_query("SHOW TABLES");
     $all = 0;
     while ($row = mysql_fetch_array($result)) {
         $status = 0;
         if (!empty($tbls)) {
             foreach ($tbls as $table) {
                 $exclude = preg_match("/^\\^/", $table) ? true : false;
                 if (!$exclude) {
                     if (preg_match("/^{$table}\$/i", $row[0])) {
                         $status = 1;
                     }
                     $all = 1;
                 }
                 if ($exclude && preg_match("/{$table}\$/i", $row[0])) {
                     $status = -1;
                 }
             }
         } else {
             $status = 1;
         }
         if ($status >= $all) {
             $tables[] = $row[0];
         }
     }
     $tabs = count($tables);
     // Определение размеров таблиц
     $result = mysql_query("SHOW TABLE STATUS");
     $tabinfo = array();
     $tabinfo[0] = 0;
     $info = '';
     while ($item = mysql_fetch_assoc($result)) {
         if (in_array($item['Name'], $tables)) {
             $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows'];
             $tabinfo[0] += $item['Rows'];
             $tabinfo[$item['Name']] = $item['Rows'];
             $this->size += $item['Data_length'];
             $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1));
             if ($item['Rows']) {
                 $info .= "|" . $item['Rows'];
             }
         }
     }
     $show = 10 + $tabinfo[0] / 50;
     $info = $tabinfo[0] . $info;
     $name = $db . '_' . date("Y-m-d_H-i");
     $fp = $this->fn_open($name, "w");
     echo tpl_l("Создание файла с резервной копией БД:<BR>\\n  -  {$this->filename}");
     $this->fn_write($fp, "#SKD101|{$db}|{$tabs}|" . date("Y.m.d H:i:s") . "|{$info}\n\n");
     $t = 0;
     echo tpl_l(str_repeat("-", 60));
     $result = mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
     foreach ($tables as $table) {
         echo tpl_l("Обработка таблицы `{$table}` [" . fn_int($tabinfo[$table]) . "].");
         // Создание таблицы
         $result = mysql_query("SHOW CREATE TABLE {$table}");
         $tab = mysql_fetch_array($result);
         $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab);
         $this->fn_write($fp, "DROP TABLE IF EXISTS {$table};\n{$tab[1]};\n\n");
         // Опредеделяем типы столбцов
         $NumericColumn = array();
         $result = mysql_query("SHOW COLUMNS FROM {$table}");
         $field = 0;
         while ($col = mysql_fetch_row($result)) {
             $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0;
         }
         $fields = $field;
         $from = 0;
         $limit = $tabsize[$table];
         $limit2 = round($limit / 3);
         if ($tabinfo[$table] > 0) {
             if ($tabinfo[$table] > $limit2) {
                 echo tpl_s(0, $t / $tabinfo[0]);
             }
             $i = 0;
             $this->fn_write($fp, "INSERT INTO `{$table}` VALUES");
             while (($result = mysql_query("SELECT * FROM {$table} LIMIT {$from}, {$limit}")) && ($total = mysql_num_rows($result))) {
                 while ($row = mysql_fetch_row($result)) {
                     $i++;
                     $t++;
                     for ($k = 0; $k < $fields; $k++) {
                         if ($NumericColumn[$k]) {
                             $row[$k] = isset($row[$k]) ? $row[$k] : "NULL";
                         } else {
                             $row[$k] = isset($row[$k]) ? "'" . mysql_escape_string($row[$k]) . "'" : "NULL";
                         }
                     }
                     $this->fn_write($fp, ($i == 1 ? "" : ",") . "\n(" . implode(", ", $row) . ")");
                     if ($i % $limit2 == 0) {
                         echo tpl_s($i / $tabinfo[$table], $t / $tabinfo[0]);
                     }
                 }
                 mysql_free_result($result);
                 if ($total < $limit) {
                     break;
                 }
                 $from += $limit;
             }
             $this->fn_write($fp, ";\n\n");
             echo tpl_s(1, $t / $tabinfo[0]);
         }
     }
     $this->tabs = $tabs;
     $this->records = $tabinfo[0];
     $this->comp = $this->SET['comp_method'] * 10 + $this->SET['comp_level'];
     echo tpl_s(1, 1);
     echo tpl_l(str_repeat("-", 60));
     $this->fn_close($fp);
     echo tpl_l("Резервная копия БД `{$db}` создана.", C_RESULT);
     echo tpl_l("Размер БД:       " . round($this->size / 1048576, 2) . " МБ", C_RESULT);
     $filesize = round(filesize(PATH . $this->filename) / 1048576, 2) . " МБ";
     echo tpl_l("Размер файла: {$filesize}", C_RESULT);
     echo tpl_l("Таблиц обработано: {$tabs}", C_RESULT);
     echo tpl_l("Строк обработано:   " . fn_int($tabinfo[0]), C_RESULT);
     echo "<SCRIPT>with (document.getElementById('save')) {style.display = ''; innerHTML = 'Скачать файл ({$filesize})'; href = '" . URL . $this->filename . "'; }document.getElementById('back').disabled = 0;</SCRIPT>";
     // Передача данных для глобальной статистики
     if (GS) {
         echo "<SCRIPT>document.getElementById('GS').src = 'http://sypex.net/gs.php?b={$this->tabs},{$this->records},{$this->size},{$this->comp},107';</SCRIPT>";
     }
 }
Esempio n. 5
0
 function backup($filter, $pack, $pack_rate)
 {
     $this->SET['tables_exclude'] = isset($filter) ? $filter : '';
     $this->SET['comp_method'] = isset($pack) ? intval($pack) : 0;
     $this->SET['comp_level'] = isset($pack_rate) ? intval($pack_rate) : 0;
     $db = DB_NAME;
     $tables = array();
     $result = mysql_query("SHOW TABLES");
     $all = 0;
     while ($row = mysql_fetch_array($result)) {
         $status = 0;
         if (!empty($tbls)) {
             foreach ($tbls as $table) {
                 $exclude = preg_match("/^\\^/", $table) ? true : false;
                 if (!$exclude) {
                     if (preg_match("/^{$table}\$/i", $row[0])) {
                         $status = 1;
                     }
                     $all = 1;
                 }
                 if ($exclude && preg_match("/{$table}\$/i", $row[0])) {
                     $status = -1;
                 }
             }
         } else {
             $status = 1;
         }
         if ($status >= $all) {
             $tables[] = $row[0];
         }
     }
     $tabs = count($tables);
     // Определение размеров таблиц
     $result = mysql_query("SHOW TABLE STATUS");
     $tabinfo = array();
     $tabinfo[0] = 0;
     $info = '';
     while ($item = mysql_fetch_assoc($result)) {
         if (in_array($item['Name'], $tables)) {
             $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows'];
             $tabinfo[0] += $item['Rows'];
             $tabinfo[$item['Name']] = $item['Rows'];
             $this->size += $item['Data_length'];
             $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1));
             if ($item['Rows']) {
                 $info .= "|" . $item['Rows'];
             }
         }
     }
     $show = 10 + $tabinfo[0] / 50;
     $info = $tabinfo[0] . $info;
     $name = $db . '_' . date("Y-m-d_H-i");
     $fp = $this->fn_open($name, "w");
     $this->fn_write($fp, "#SKD101|{$db}|{$tabs}|" . date("Y.m.d H:i:s") . "|{$info}\n\n");
     $t = 0;
     $result = mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
     foreach ($tables as $table) {
         $this->tables_list[] = $table . "[" . fn_int($tabinfo[$table]) . "]";
         // Создание таблицы
         $result = mysql_query("SHOW CREATE TABLE {$table}");
         $tab = mysql_fetch_array($result);
         $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab);
         $this->fn_write($fp, "DROP TABLE IF EXISTS {$table};\n{$tab[1]};\n\n");
         // Опредеделяем типы столбцов
         $NumericColumn = array();
         $result = mysql_query("SHOW COLUMNS FROM {$table}");
         $field = 0;
         while ($col = mysql_fetch_row($result)) {
             $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0;
         }
         $fields = $field;
         $from = 0;
         $limit = $tabsize[$table];
         $limit2 = round($limit / 3);
         if ($tabinfo[$table] > 0) {
             if ($tabinfo[$table] > $limit2) {
                 echo tpl_s(0, $t / $tabinfo[0]);
             }
             $i = 0;
             $this->fn_write($fp, "INSERT INTO `{$table}` VALUES");
             while (($result = mysql_query("SELECT * FROM {$table} LIMIT {$from}, {$limit}")) && ($total = mysql_num_rows($result))) {
                 while ($row = mysql_fetch_row($result)) {
                     $i++;
                     $t++;
                     for ($k = 0; $k < $fields; $k++) {
                         if ($NumericColumn[$k]) {
                             $row[$k] = isset($row[$k]) ? $row[$k] : "NULL";
                         } else {
                             $row[$k] = isset($row[$k]) ? "'" . mysql_escape_string($row[$k]) . "'" : "NULL";
                         }
                     }
                     $this->fn_write($fp, ($i == 1 ? "" : ",") . "\n(" . implode(", ", $row) . ")");
                     if ($i % $limit2 == 0) {
                         echo tpl_s($i / $tabinfo[$table], $t / $tabinfo[0]);
                     }
                 }
                 mysql_free_result($result);
                 if ($total < $limit) {
                     break;
                 }
                 $from += $limit;
             }
             $this->fn_write($fp, ";\n\n");
         }
     }
     $this->tabs = $tabs;
     $this->records = $tabinfo[0];
     $this->comp = $this->SET['comp_method'] * 10 + $this->SET['comp_level'];
     $this->fn_close($fp);
     $this->table_size = round($this->size / 1048576, 2);
     $this->file_size = round(filesize(PATH . $this->filename) / 1048576, 2);
     $this->tables_count = $tabs;
     $this->rows_count = fn_int($tabinfo[0]);
 }
Esempio n. 6
0
 function backup()
 {
     $this->SET['last_action'] = 0;
     $this->SET['last_db_backup'] = DB_NAME;
     $this->SET['tables'] = TABLE_PREFIX;
     $this->SET['comp_method'] = 1;
     $this->SET['comp_level'] = 9;
     $this->SET['tables_exclude'] = 0;
     $this->SET['tables'] = explode(",", $this->SET['tables']);
     if (!empty($this->SET['tables'])) {
         foreach ($this->SET['tables'] as $table) {
             $table = preg_replace("/[^\\w*?^]/", "", $table);
             $pattern = array("/\\?/", "/\\*/");
             $replace = array(".", ".*?");
             $tbls[] = preg_replace($pattern, $replace, $table);
         }
     } else {
         $this->SET['tables_exclude'] = 1;
     }
     if ($this->SET['comp_level'] == 0) {
         $this->SET['comp_method'] = 0;
     }
     $db = $this->SET['last_db_backup'];
     $tables = array();
     $result = mysql_query("SHOW TABLES");
     $all = 0;
     while ($row = mysql_fetch_array($result)) {
         $status = 0;
         if (!empty($tbls)) {
             foreach ($tbls as $table) {
                 $exclude = preg_match("/^\\^/", $table) ? true : false;
                 if (!$exclude) {
                     if (preg_match("/^{$table}\$/i", $row[0])) {
                         $status = 1;
                     }
                     $all = 1;
                 }
                 if ($exclude && preg_match("/{$table}\$/i", $row[0])) {
                     $status = -1;
                 }
             }
         } else {
             $status = 1;
         }
         if ($status >= $all) {
             $tables[] = $row[0];
         }
     }
     $tabs = count($tables);
     // ����������� �������� ������
     $result = mysql_query("SHOW TABLE STATUS");
     $tabinfo = array();
     $tab_charset = array();
     $tab_type = array();
     $tabinfo[0] = 0;
     $info = '';
     while ($item = mysql_fetch_assoc($result)) {
         //print_r($item);
         if (in_array($item['Name'], $tables)) {
             $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows'];
             $tabinfo[0] += $item['Rows'];
             $tabinfo[$item['Name']] = $item['Rows'];
             $this->size += $item['Data_length'];
             $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1));
             if ($item['Rows']) {
                 $info .= "|" . $item['Rows'];
             }
             if (!empty($item['Collation']) && preg_match("/^([a-z0-9]+)_/i", $item['Collation'], $m)) {
                 $tab_charset[$item['Name']] = $m[1];
             }
             $tab_type[$item['Name']] = isset($item['Engine']) ? $item['Engine'] : $item['Type'];
         }
     }
     $show = 10 + $tabinfo[0] / 50;
     $info = $tabinfo[0] . $info;
     if (isset($this->SET['masterfef'])) {
         $name = "fulldump";
     } else {
         $name = "dump" . '_' . date("Y-m-d_H-i");
     }
     $fp = $this->fn_open($name, "w");
     $this->fn_write($fp, "#SKD101|{$db}|{$tabs}|" . date("Y.m.d H:i:s") . "|{$info}\n\n");
     $t = 0;
     $result = mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
     if ($this->mysql_version > 40101 && CHARSET != 'auto') {
         $last_charset = CHARSET;
     } else {
         $last_charset = '';
     }
     foreach ($tables as $table) {
         if ($this->mysql_version > 40101 && $tab_charset[$table] != $last_charset) {
             if (CHARSET == 'auto') {
                 $last_charset = $tab_charset[$table];
             }
         }
         fn_int($tabinfo[$table]);
         // �������� �������
         $result = mysql_query("SHOW CREATE TABLE `{$table}`");
         $tab = mysql_fetch_array($result);
         $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab);
         $this->fn_write($fp, "DROP TABLE IF EXISTS `{$table}`;\n{$tab[1]};\n\n");
         // ��������� ����� �� ������� ������
         if (in_array($tab_type[$table], $this->only_create)) {
             continue;
         }
         // ������������ ���� ��������
         $NumericColumn = array();
         $result = mysql_query("SHOW COLUMNS FROM `{$table}`");
         $field = 0;
         while ($col = mysql_fetch_row($result)) {
             $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0;
         }
         $fields = $field;
         $from = 0;
         $limit = $tabsize[$table];
         $limit2 = round($limit / 3);
         if ($tabinfo[$table] > 0) {
             $i = 0;
             while (($result = mysql_query("select * FROM `{$table}` LIMIT {$from}, {$limit}")) && ($total = mysql_num_rows($result))) {
                 while ($row = mysql_fetch_row($result)) {
                     $i++;
                     $t++;
                     for ($k = 0; $k < $fields; $k++) {
                         if ($NumericColumn[$k]) {
                             $row[$k] = isset($row[$k]) ? $row[$k] : "NULL";
                         } else {
                             $row[$k] = isset($row[$k]) ? "'" . mysql_escape_string($row[$k]) . "'" : "NULL";
                         }
                     }
                     $this->fn_write($fp, "INSERT INTO `{$table}` VALUES (" . implode(", ", $row) . ");\n");
                 }
                 mysql_free_result($result);
                 if ($total < $limit) {
                     break;
                 }
                 $from += $limit;
             }
             $this->fn_write($fp, "\n");
         }
     }
     $this->tabs = $tabs;
     $this->records = $tabinfo[0];
     $this->comp = $this->SET['comp_method'] * 10 + $this->SET['comp_level'];
     $this->fn_close($fp);
 }
Esempio n. 7
0
 function backup()
 {
     $TEXT_DUMPER_SUBMIT = TEXT_DUMPER_SUBMIT;
     $TEXT_DUMPER_SEC = TEXT_DUMPER_SEC;
     $TEXT_DUMPER_DIR_ERROR = TEXT_DUMPER_DIR_ERROR;
     $TEXT_DUMPER_DOWNLOAD = TEXT_DUMPER_DOWNLOAD;
     $TEXT_DUMPER_BACK = TEXT_DUMPER_BACK;
     $TEXT_DUMPER_CREATE = TEXT_DUMPER_CREATE;
     $TEXT_DUMPER_NAME_ERROR = TEXT_DUMPER_NAME_ERROR;
     $TEXT_DUMPER_CONNECT = TEXT_DUMPER_CONNECT;
     $TEXT_DUMPER_CONNECT_ERROR = TEXT_DUMPER_CONNECT_ERROR;
     $TEXT_DUMPER_CREATE_FILE = TEXT_DUMPER_CREATE_FILE;
     $TEXT_DUMPER_CHARSET_ERROR = TEXT_DUMPER_CHARSET_ERROR;
     $TEXT_DUMPER_CHARSET = TEXT_DUMPER_CHARSET;
     $TEXT_DUMPER_CHARSET_COLLATION = TEXT_DUMPER_CHARSET_COLLATION;
     $TEXT_DUMPER_TABLE = TEXT_DUMPER_TABLE;
     $TEXT_DUMPER_CONNECT1 = TEXT_DUMPER_CONNECT1;
     $TEXT_DUMPER_PROCESS = TEXT_DUMPER_PROCESS;
     $TEXT_DUMPER_TABLES_COUNT = TEXT_DUMPER_TABLES_COUNT;
     $TEXT_DUMPER_STRING_COUNT = TEXT_DUMPER_STRING_COUNT;
     $TEXT_DUMPER_MAKE = TEXT_DUMPER_MAKE;
     $TEXT_DUMPER_MAKE1 = TEXT_DUMPER_MAKE1;
     $TEXT_DUMPER_SIZE = TEXT_DUMPER_SIZE;
     $TEXT_DUMPER_MB = TEXT_DUMPER_MB;
     $TEXT_DUMPER_FILE_SIZE = TEXT_DUMPER_FILE_SIZE;
     $TEXT_DUMPER_STRING_COUNT = TEXT_DUMPER_STRING_COUNT;
     $TEXT_DUMPER_STRING_COUNT = TEXT_DUMPER_STRING_COUNT;
     if (!isset($_REQUEST)) {
         $this->main();
     }
     set_error_handler("SXD_errorHandler");
     $buttons = "<a class=\"button\" href=\"\" onclick=\"history.back();\"><span>" . TEXT_DUMPER_BACK . "</span></a>";
     echo tpl_page(tpl_process($TEXT_DUMPER_CREATE), $buttons);
     $this->SET['last_action'] = 0;
     $this->SET['last_db_backup'] = isset($_REQUEST['db_backup']) ? $_REQUEST['db_backup'] : '';
     $this->SET['tables_exclude'] = !empty($_REQUEST['tables']) && $_REQUEST['tables'][0] == '^' ? 1 : 0;
     $this->SET['tables'] = isset($_REQUEST['tables']) ? $_REQUEST['tables'] : '';
     $this->SET['comp_method'] = isset($_REQUEST['comp_method']) ? intval($_REQUEST['comp_method']) : 0;
     $this->SET['comp_level'] = isset($_REQUEST['comp_level']) ? intval($_REQUEST['comp_level']) : 0;
     $this->fn_save();
     $this->SET['tables'] = explode(",", $this->SET['tables']);
     if (!empty($_REQUEST['tables'])) {
         foreach ($this->SET['tables'] as $table) {
             $table = preg_replace("/[^\\w*?^]/", "", $table);
             $pattern = array("/\\?/", "/\\*/");
             $replace = array(".", ".*?");
             $tbls[] = preg_replace($pattern, $replace, $table);
         }
     } else {
         $this->SET['tables_exclude'] = 1;
     }
     if ($this->SET['comp_level'] == 0) {
         $this->SET['comp_method'] = 0;
     }
     $db = $this->SET['last_db_backup'];
     if (!$db) {
         echo tpl_l($TEXT_DUMPER_NAME_ERROR, C_ERROR);
         echo tpl_enableBack();
         exit;
     }
     echo tpl_l($TEXT_DUMPER_CONNECT . "`{$db}`.");
     mysql_select_db($db) or trigger_error($TEXT_DUMPER_CONNECT_ERROR . "<br />" . mysql_error(), E_USER_ERROR);
     $tables = array();
     $result = mysql_query("SHOW tableS");
     $all = 0;
     while ($row = mysql_fetch_array($result)) {
         $status = 0;
         if (!empty($tbls)) {
             foreach ($tbls as $table) {
                 $exclude = preg_match("/^\\^/", $table) ? true : false;
                 if (!$exclude) {
                     if (preg_match("/^{$table}\$/i", $row[0])) {
                         $status = 1;
                     }
                     $all = 1;
                 }
                 if ($exclude && preg_match("/{$table}\$/i", $row[0])) {
                     $status = -1;
                 }
             }
         } else {
             $status = 1;
         }
         if ($status >= $all) {
             $tables[] = $row[0];
         }
     }
     $tabs = count($tables);
     // Определение размеров таблиц
     $result = mysql_query("SHOW table STATUS");
     $tabinfo = array();
     $tab_charset = array();
     $tab_type = array();
     $tabinfo[0] = 0;
     $info = '';
     while ($item = mysql_fetch_assoc($result)) {
         //print_r($item);
         if (in_array($item['Name'], $tables)) {
             $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows'];
             $tabinfo[0] += $item['Rows'];
             $tabinfo[$item['Name']] = $item['Rows'];
             $this->size += $item['Data_length'];
             $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1));
             if ($item['Rows']) {
                 $info .= "|" . $item['Rows'];
             }
             if (!empty($item['Collation']) && preg_match("/^([a-z0-9]+)_/i", $item['Collation'], $m)) {
                 $tab_charset[$item['Name']] = $m[1];
             }
             $tab_type[$item['Name']] = isset($item['Engine']) ? $item['Engine'] : $item['Type'];
         }
     }
     $show = 10 + $tabinfo[0] / 50;
     $info = $tabinfo[0] . $info;
     $name = $db . '_' . date("Y-m-d_H-i");
     $fp = $this->fn_open($name, "w");
     echo tpl_l($TEXT_DUMPER_CREATE_FILE . "<br />\\n  -  {$this->filename}");
     $this->fn_write($fp, "#SKD101|{$db}|{$tabs}|" . date("Y.m.d H:i:s") . "|{$info}\n\n");
     $t = 0;
     echo tpl_l(str_repeat("-", 60));
     $result = mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
     // Кодировка соединения по умолчанию
     if ($this->mysql_version > 40101 && CHARSET != 'auto') {
         mysql_query("SET NAMES '" . CHARSET . "'") or trigger_error($TEXT_DUMPER_CHARSET_ERROR . "<br />" . mysql_error(), E_USER_ERROR);
         $last_charset = CHARSET;
     } else {
         $last_charset = '';
     }
     foreach ($tables as $table) {
         // Выставляем кодировку соединения соответствующую кодировке таблицы
         if ($this->mysql_version > 40101 && $tab_charset[$table] != $last_charset) {
             if (CHARSET == 'auto') {
                 mysql_query("SET NAMES '" . $tab_charset[$table] . "'") or trigger_error($TEXT_DUMPER_CHARSET_ERROR . "<br />" . mysql_error(), E_USER_ERROR);
                 echo tpl_l($TEXT_DUMPER_CHARSET . "`" . $tab_charset[$table] . "`.", C_WARNING);
                 $last_charset = $tab_charset[$table];
             } else {
                 echo tpl_l($TEXT_DUMPER_CHARSET_COLLATION, C_ERROR);
                 echo tpl_l($TEXT_DUMPER_TABLE . '`' . $table . '` -> ' . $tab_charset[$table] . ' (' . $TEXT_DUMPER_CONNECT . '' . CHARSET . ')', C_ERROR);
             }
         }
         echo tpl_l($TEXT_DUMPER_PROCESS . "`{$table}` [" . fn_int($tabinfo[$table]) . "].");
         // Создание таблицы
         $result = mysql_query("SHOW CREATE table `{$table}`");
         $tab = mysql_fetch_array($result);
         $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab);
         $this->fn_write($fp, "DROP table IF EXISTS `{$table}`;\n{$tab[1]};\n\n");
         // Проверяем нужно ли дампить данные
         if (in_array($tab_type[$table], $this->only_create)) {
             continue;
         }
         // Опредеделяем типы столбцов
         $NumericColumn = array();
         $result = mysql_query("SHOW COLUMNS FROM `{$table}`");
         $field = 0;
         while ($col = mysql_fetch_row($result)) {
             $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0;
         }
         $fields = $field;
         $from = 0;
         $limit = $tabsize[$table];
         $limit2 = round($limit / 3);
         if ($tabinfo[$table] > 0) {
             if ($tabinfo[$table] > $limit2) {
                 echo tpl_s(0, $t / $tabinfo[0]);
             }
             $i = 0;
             $this->fn_write($fp, "INSERT INTO `{$table}` VALUES");
             while (($result = mysql_query("SELECT * FROM `{$table}` LIMIT {$from}, {$limit}")) && ($total = mysql_num_rows($result))) {
                 while ($row = mysql_fetch_row($result)) {
                     $i++;
                     $t++;
                     for ($k = 0; $k < $fields; $k++) {
                         if ($NumericColumn[$k]) {
                             $row[$k] = isset($row[$k]) ? $row[$k] : "NULL";
                         } else {
                             $row[$k] = isset($row[$k]) ? "'" . mysql_real_escape_string($row[$k]) . "'" : "NULL";
                         }
                     }
                     $this->fn_write($fp, ($i == 1 ? "" : ",") . "\n(" . implode(", ", $row) . ")");
                     if ($i % $limit2 == 0) {
                         echo tpl_s($i / $tabinfo[$table], $t / $tabinfo[0]);
                     }
                 }
                 mysql_free_result($result);
                 if ($total < $limit) {
                     break;
                 }
                 $from += $limit;
             }
             $this->fn_write($fp, ";\n\n");
             echo tpl_s(1, $t / $tabinfo[0]);
         }
     }
     $this->tabs = $tabs;
     $this->records = $tabinfo[0];
     $this->comp = $this->SET['comp_method'] * 10 + $this->SET['comp_level'];
     echo tpl_s(1, 1);
     echo tpl_l(str_repeat("-", 60));
     $this->fn_close($fp);
     echo tpl_l($TEXT_DUMPER_MAKE . "`{$db}`" . $TEXT_DUMPER_MAKE1, C_RESULT);
     echo tpl_l($TEXT_DUMPER_SIZE . round($this->size / 1048576, 2) . $TEXT_DUMPER_MB, C_RESULT);
     $filesize = round(filesize(PATH . $this->filename) / 1048576, 2) . $TEXT_DUMPER_MB;
     echo tpl_l($TEXT_DUMPER_FILE_SIZE . "{$filesize}", C_RESULT);
     echo tpl_l($TEXT_DUMPER_TABLES_COUNT . "{$tabs}", C_RESULT);
     echo tpl_l($TEXT_DUMPER_STRING_COUNT . fn_int($tabinfo[0]), C_RESULT);
     //echo "<script>with (document.getElementById('save')) {style.display = ''; innerHTML = '" . TEXT_DUMPER_DOWNLOAD . " ({$filesize})'; href = '" . URL . $this->filename . "'; }document.getElementById('back').disabled = 0;</script>";
     // Передача данных для глобальной статистики
     if (GS) {
         echo "<script>document.getElementById('GS').src = 'http://sypex.net/gs.php?b={$this->tabs},{$this->records},{$this->size},{$this->comp},108';</script>";
     }
 }