Ejemplo n.º 1
0
    $status[$row['Variable_name']] = $row['Value'];
}
$filter = getPrefixArray($status);
// values that will be formatted as times
$timeValues = array('Uptime', 'Uptime_since_flush_status');
$tplSqlbrowserGeneralStatus = new MSDTemplate();
$tplSqlbrowserGeneralStatus->set_filenames(array('tplSqlbrowserGeneralStatus' => 'tpl/sqlbrowser/general/status.tpl'));
if ($selectedFilter != '-1') {
    $query = 'SHOW GLOBAL STATUS LIKE \'' . $selectedFilter . '_%\'';
    $res = $dbo->query($query, MsdDbFactory::ARRAY_ASSOC);
}
if (@sizeof($res) == 0) {
    $tpl->assign_block_vars('NO_STATUS', array());
} else {
    if (count($filter) > 0) {
        $tplSqlbrowserGeneralStatus->assign_block_vars('FILTER', array('SEL_FILTER' => Html::getOptionlist($filter, $selectedFilter)));
    }
    $i = 0;
    foreach ($status as $key => $val) {
        if ($selectedFilter != '-1' && substr($key, 0, strlen($selectedFilter)) != $selectedFilter) {
            continue;
        }
        if (in_array($key, $timeValues)) {
            $val = getTimeFormat($val);
        } else {
            $val = String::formatNumber($val);
        }
        $tplSqlbrowserGeneralStatus->assign_block_vars('ROW', array('ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1', 'NR' => $i + 1, 'VAR_NAME' => $key, 'VAR_VALUE' => $val));
        $i++;
    }
}
$refdir = substr($config['cron_execution_path'], 0, 1) == '/' ? '' : $url;
$scriptdir = $config['cron_execution_path'] . 'crondump.' . $cext;
$perlModultest = $config['cron_execution_path'] . "perltest.{$cext}";
$perlSimpletest = $config['cron_execution_path'] . "simpletest.{$cext}";
$scriptentry = myRealpath('./') . $config['paths']['config'];
$cronabsolute = myRealpath('./') . $scriptdir;
if (substr($config['cron_execution_path'], 0, 1) == '/') {
    $cronabsolute = $_SERVER['DOCUMENT_ROOT'] . $scriptdir;
}
$confabsolute = $config['config_file'];
$perlHttpCall = getServerProtocol() . $serverName . $refdir;
$perlHttpCall .= $config['cron_execution_path'] . 'crondump.' . $cext;
$perlHttpCall .= '?config=' . $confabsolute;
$perlCrontabCall = 'perl ' . $cronabsolute . ' -config=' . $confabsolute;
$perlCrontabCall .= ' -html_output=0';
$tplDumpPrepare->assign_vars(array('SESSION_ID' => session_id(), 'CONFIG_FILE' => $config['config_file'], 'POSSIBLE_DUMP_ENCODINGS' => Html::getOptionlist($charsetsDescription, 'utf8'), 'DBS_TO_BACKUP' => $dbsToBackup, 'TABLES_TOTAL' => $dump['tables_total'], 'RECORDS_TOTAL' => String::formatNumber(intval($dump['records_total'])), 'DATASIZE_TOTAL' => byteOutput($dump['datasize_total']), 'NR_OF_DBS' => count($dump['databases']), 'DUMP_COMMENT' => Html::replaceQuotes($dump['comment']), 'PERL_TEST' => $perlSimpletest, 'PERL_MODULTEST' => $perlModultest, 'PERL_HTTP_CALL' => $perlHttpCall, 'PERL_CRONTAB_CALL' => $perlCrontabCall, 'PERL_ABSOLUTE_PATH_OF_CONFIGDIR' => $scriptentry, 'TIMESTAMP' => time()));
if (count($dump['databases']) == 1 && $config['db_actual'] == $dbsToBackup) {
    $tplDumpPrepare->assign_block_vars('TABLESELECT', array());
}
if ($config['compression'] == 1) {
    $tplDumpPrepare->assign_block_vars('GZIP_ACTIVATED', array());
} else {
    $tplDumpPrepare->assign_block_vars('GZIP_NOT_ACTIVATED', array());
}
if ($config['multi_part'] == 1) {
    $tplDumpPrepare->assign_block_vars('MULTIPART', array('SIZE' => byteOutput($config['multipart_groesse'])));
} else {
    $tplDumpPrepare->assign_block_vars('NO_MULTIPART', array());
}
if ($config['send_mail'] == 1) {
    $tplDumpPrepare->assign_block_vars('SEND_MAIL', array('RECIPIENT' => $config['email']['recipient_address']));
/**
 * Reads next lines from file and extracts a complete SQL-Command
 *
 * @return string $sql_command The complete Query
 */
function getQueryFromFile($showErrors = true)
{
    global $restore, $config, $databases, $lang, $dbo, $log;
    //Init
    $complete_sql = '';
    $sqlparser_status = 0;
    $query_found = false;
    //Parse
    while (!$query_found && !$restore['fileEOF'] && !$restore['EOB']) {
        //get next line from file
        $zeile = $restore['compressed'] ? gzgets($restore['filehandle']) : fgets($restore['filehandle']);
        // if we are at the beginning of a file look for BOM and remove it
        if ($restore['offset'] == 0) {
            $zeile = removeBom($zeile);
        }
        // what kind of command did we read from the file?
        if ($sqlparser_status == 0) {
            // build comparing line in uppercase
            $zeile2 = strtoupper(trim(substr($zeile, 0, 9)));
            // pre-build compare strings - so we need the CPU power only once :)
            $sub9 = substr($zeile2, 0, 9);
            $sub7 = substr($sub9, 0, 7);
            $sub6 = substr($sub7, 0, 6);
            $sub4 = substr($sub6, 0, 4);
            $sub3 = substr($sub4, 0, 3);
            $sub2 = substr($sub3, 0, 2);
            $sub1 = substr($sub2, 0, 1);
            if ($sub7 == 'INSERT ') {
                $sqlparser_status = 3;
                $restore['actual_table'] = getTablename($zeile, $restore['actual_table']);
            } elseif ($sub7 == 'REPLACE') {
                $sqlparser_status = 8;
                $restore['actual_table'] = getTablename($zeile, $restore['actual_table']);
            } elseif ($sub7 == 'LOCK TA') {
                $sqlparser_status = 4;
            } elseif ($sub6 == 'COMMIT') {
                $sqlparser_status = 7;
            } elseif (substr($sub6, 0, 5) == 'BEGIN') {
                $sqlparser_status = 7;
            } elseif ($sub9 == 'UNLOCK TA') {
                $sqlparser_status = 4;
            } elseif ($sub3 == 'SET') {
                $sqlparser_status = 4;
            } elseif ($sub6 == 'START ') {
                $sqlparser_status = 4;
            } elseif ($sub3 == '/*!') {
                $sqlparser_status = 5;
            } elseif ($sub9 == 'ALTER TAB') {
                $sqlparser_status = 4;
            } elseif ($sub9 == 'CREATE TA') {
                $sqlparser_status = 2;
            } elseif ($sub9 == 'CREATE AL') {
                $sqlparser_status = 2;
            } elseif ($sub9 == 'CREATE IN') {
                $sqlparser_status = 4;
            } elseif ($sub7 == 'UPDATE ') {
                $sqlparser_status = 4;
            } elseif ($sub7 == 'SELECT ') {
                $sqlparser_status = 4;
            } elseif ($sqlparser_status != 5 && $sub2 == '/*') {
                $sqlparser_status = 6;
            } elseif ($sub9 == 'DROP TABL') {
                $sqlparser_status = 1;
            } elseif ($sub9 == 'DROP VIEW') {
                $sqlparser_status = 1;
            } elseif ($sub7 == 'DELETE ') {
                $sqlparser_status = 1;
            } elseif ($sub9 == 'CREATE DA ') {
                $sqlparser_status = 7;
            } elseif ($sub9 == 'DROP DATA ') {
                $sqlparser_status = 7;
            } elseif ($sub3 == 'USE') {
                $sqlparser_status = 7;
            } elseif ($sub6 == '-- EOB' || $sub4 == '# EO') {
                $restore['EOB'] = true;
                $restore['fileEOF'] = true;
                $zeile = '';
                $zeile2 = '';
                $query_found = true;
            } elseif ($sub2 == '--' || $sub1 == '#') {
                $zeile = '';
                $zeile2 = '';
                $sqlparser_status = 0;
            }
            // continue extended Insert?
            if ($restore['extended_insert_flag'] == 1) {
                $sqlparser_status = 3;
            }
            if ($sqlparser_status == 0 && trim($complete_sql) > '' && $restore['extended_insert_flag'] == -1) {
                if ($showErrors) {
                    // unknown command -> output debug information
                    v($restore);
                    echo "<br />Sql: " . htmlspecialchars($complete_sql);
                    die('<br />' . $lang['L_UNKNOWN_SQLCOMMAND'] . ': ' . $zeile . '<br /><br />' . $complete_sql);
                } else {
                    return array(false, $complete_sql);
                }
            }
        }
        $last_char = substr(rtrim($zeile), -1);
        // retain new lines - otherwise keywords are glued together
        // e.g. 'null' and on next line 'check' would necome 'nullcheck'
        $complete_sql .= $zeile . "\n";
        if ($sqlparser_status == 3 || $sqlparser_status == 8) {
            //INSERT or REPLACE
            if (isCompleteQuery($complete_sql)) {
                $query_found = true;
                $complete_sql = trim($complete_sql);
                if (substr($complete_sql, -2) == '*/') {
                    $complete_sql = deleteInlineComments($complete_sql);
                }
                // end of extended insert found?
                if (substr($complete_sql, -2) == ');') {
                    $restore['extended_insert_flag'] = -1;
                } else {
                    if (substr($complete_sql, -2) == '),') {
                        // letztes Komme gegen Semikolon tauschen
                        $complete_sql = substr($complete_sql, 0, -1);
                        $restore['extended_inserts'] = 1;
                        $restore['extended_insert_flag'] = 1;
                    }
                }
                $compare = substr(strtoupper($complete_sql), 0, 7);
                if ($compare != 'INSERT ' && $compare != 'REPLACE') {
                    // we do have extended inserts here -> prepend insert syntax
                    // if we don't have it because of a page refresh -> get it
                    if (!isset($restore['insert_syntax'])) {
                        $restore['insert_syntax'] = Sql::getInsertSyntax($dbo, $restore['actual_table']);
                    }
                    $complete_sql = $restore['insert_syntax'] . ' VALUES ' . $complete_sql;
                } else {
                    // remember the INSERT syntax
                    $ipos = strpos(strtoupper($complete_sql), ' VALUES');
                    if (!$ipos === false) {
                        $restore['insert_syntax'] = substr($complete_sql, 0, $ipos);
                    } else {
                        if ($sqlparser_status == 3) {
                            $restore['insert_syntax'] = 'INSERT INTO `' . $restore['actual_table'] . '`';
                        } else {
                            $restore['insert_syntax'] = 'REPLACE INTO `' . $restore['actual_table'] . '`';
                        }
                    }
                }
            }
        } else {
            if ($sqlparser_status == 1) {
                // delete action
                if ($last_char == ';') {
                    $query_found = true;
                }
                $restore['actual_table'] = getTablename($complete_sql);
            } else {
                if ($sqlparser_status == 2) {
                    // Create-command is finished if there is a colon at the end of line
                    if ($last_char == ';') {
                        $restore['speed'] = $config['minspeed'];
                        // Restore this table?
                        $do_it = true;
                        if (is_array($restore['tables_to_restore'])) {
                            $do_it = false;
                            if (in_array($restore['actual_table'], $restore['tables_to_restore'])) {
                                $do_it = true;
                            } else {
                                // if we do a partial restore with selected tables and we already inserted all
                                // of them and we now have a table we don't need to restore
                                // -> we did all we need to do! Check and finish the process in that case
                                // (we don't need to further walk through the file if all needed tables are done)
                                if ($restore['table_ready'] == $restore['tables_total']) {
                                    $sqlparser_status = 0;
                                    $restore['EOB'] = true;
                                }
                            }
                        }
                        $tablename = getTablename($complete_sql);
                        if ($do_it) {
                            $complete_sql = getCorrectedCreateCommand($complete_sql);
                            $restore['table_ready']++;
                        } else {
                            $complete_sql = '';
                        }
                        $restore['actual_table'] = $tablename;
                        $query_found = true;
                        $sqlparser_status = 0;
                    }
                } else {
                    if ($sqlparser_status == 4) {
                        if ($last_char == ';') {
                            $restore['speed'] = $config['minspeed'];
                            $complete_sql = deleteInlineComments($complete_sql);
                            $query_found = true;
                        }
                    } else {
                        if ($sqlparser_status == 5) {
                            $t = strrpos($zeile, '*/;');
                            if (!$t === false) {
                                $restore['speed'] = $config['minspeed'];
                                $query_found = true;
                            }
                        } else {
                            if ($sqlparser_status == 6) {
                                $t = strrpos($zeile, '*/');
                                if (!$t === false) {
                                    $complete_sql = '';
                                    $sqlparser_status = 0;
                                }
                            } else {
                                if ($sqlparser_status == 7) {
                                    if ($last_char == ';') {
                                        $restore['speed'] = $config['minspeed'];
                                        $complete_sql = '';
                                        $sqlparser_status = 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if ($restore['compressed'] && gzeof($restore['filehandle'])) {
            $restore['fileEOF'] = true;
        } elseif (!$restore['compressed'] && feof($restore['filehandle'])) {
            $restore['fileEOF'] = true;
        }
    }
    // if special tables are selected for restoring, check if this query belongs to them
    if (is_array($restore['tables_to_restore']) && !in_array($restore['actual_table'], $restore['tables_to_restore'])) {
        $complete_sql = '';
    }
    //detect if a table is finished and write log message
    if ($sqlparser_status != 3 && $sqlparser_status != 8 && in_array($restore['last_parser_status'], array(3, 8))) {
        if (isset($restore['records_inserted_table'][$restore['actual_table']])) {
            $message = sprintf($lang['L_RESTORE_TABLE'], $restore['actual_table']) . ': ';
            $message .= sprintf($lang['L_RECORDS_INSERTED'], String::formatNumber($restore['records_inserted_table'][$restore['actual_table']]));
            $log->write(Log::PHP, $message);
        }
    }
    $restore['last_parser_status'] = $sqlparser_status;
    $complete_sql = trim($complete_sql);
    return $complete_sql;
}
if ($restore['progress_overall_percent'] > 0) {
    $r['progress_overall_percent'] = String::formatNumber($restore['progress_overall_percent'], 2);
    $r['progress_overall_bar_width'] = round($restore['progress_overall_percent'] * 3, 0);
} else {
    $r['progress_overall_percent'] = $lang['L_UNKNOWN'];
    $r['progress_overall_bar_width'] = 0;
}
if ($restore['part'] > 0) {
    $r['part'] = $restore['part'];
}
$r['tables_to_create'] = $tablesToCreate;
$r['records_done'] = $recordsDone;
$r['actual_table'] = sprintf($lang['L_ANALYZING_TABLE'], $restore['actual_table']);
$r['speed'] = String::formatNumber($restore['speed']);
$r['speedbar_width'] = round($restore['speed'] * 100 / $config['maxspeed'] * 3, 0);
$r['page_refreshs'] = String::formatNumber($restore['page_refreshs']);
$elapsed = time() - $restore['restore_start_time'];
$r['elapsed_time'] = getTimeFormat($elapsed);
// if we restore a MySQLDumper-Backup we know the nr of records and can
// calculate the estimated time from it
// if we restore a backup from another program we need to rely on the filesize
//which is not accurate
// when the file is gzipped, but we can't help it because there is no way to
// get the exact file pointer position in a gzipped file.
// So we give our best to guess the corect position (see line 117 above)
if ($restore['progress_overall_percent'] > 0) {
    $percentageDone = $restore['progress_overall_percent'];
} else {
    $percentageDone = $restore['progress_file_percent'];
}
$estimatedTime = 0;
// we need to save this before the Ajax-Requests starts, so we are doing it here
// although it is done in dump.php
$_SESSION['dump'] = $dump;
// checks after first dump-prepare if we need to head over to table selection
// or if we can start the backup process
if (!isset($_POST['tableselect'])) {
    // nothing to select - start dump action
    $action = 'do_dump';
} else {
    // yes, we need to show the table-selection, but first save commetn and
    // encoding that was set before
    $tplDumpSelectTables = new MSDTemplate();
    $tplDumpSelectTables->set_filenames(array('tplDumpSelectTables' => 'tpl/dump/selectTables.tpl'));
    $dbo->selectDb($dump['db_actual']);
    $tables = $dbo->getTableStatus();
    $i = 0;
    foreach ($tables as $tableName => $row) {
        $klasse = $i % 2 ? 1 : '';
        $tableSize = byteOutput($row['Data_length'] + $row['Index_length']);
        $tableType = $row['Engine'];
        $nrOfRecords = String::formatNumber($row['Rows']);
        if (substr($row['Comment'], 0, 4) == 'VIEW' && $row['Engine'] == '') {
            $tableType = 'View';
            $tableSize = '-';
            $nrOfRecords = '-';
        }
        $tplDumpSelectTables->assign_block_vars('ROW', array('CLASS' => 'dbrow' . $klasse, 'ID' => $i, 'NR' => $i + 1, 'TABLENAME' => $tableName, 'TABLETYPE' => $tableType, 'RECORDS' => $nrOfRecords, 'SIZE' => $tableSize, 'LAST_UPDATE' => $row['Update_time']));
        $i++;
    }
    $tplDumpSelectTables->assign_vars(array('PAGETITLE' => $lang['L_TABLESELECTION'], 'SESSION_ID' => session_id(), 'DATABASE' => $config['db_actual'], 'ICON_OK' => $icon['ok'], 'ICON_DELETE' => $icon['delete'], 'ICON_DB' => $icon['db'], 'L_NO_MSD_BACKUP' => $lang['L_NOT_SUPPORTED']));
}
Ejemplo n.º 6
0
// check if new log-messages werde added
$messages = getArrayDiffAssocRecursive($_SESSION['log'], $_SESSION['temp_log']);
if (isset($messages['actions']) && is_array($messages['actions'])) {
    $r['actions'] = implode('<br />', $messages['actions']);
}
if (isset($messages['errors']) && is_array($messages['errors'])) {
    $r['errors'] = implode('<br />', $messages['errors']);
}
$_SESSION['log'] = $_SESSION['log'] + $_SESSION['temp_log'];
$dump['last_db_actual'] = $dump['db_actual'];
//backup_done means that all tables are saved. The overall progress
//(emails, ftp) can still continue
if ($dump['backup_done'] == 1) {
    // some values need to be decreased
    $r['progressbar_table_width'] = 0;
    $r['progress_table_percent'] = '';
    $r['actual_database'] = '';
    $r['actual_table'] = '';
    $r['record_offset_start'] = '-';
    $r['record_offset_end'] = '-';
    $r['table_records_total'] = '-';
    $r['actual_table_nr'] = String::formatNumber($dump['table_offset_total']);
    $r['progress_overall_percent'] = String::formatNumber(100, 2);
    $r['progressbar_overall_width'] = 300;
    $r['speed'] = 0;
    $r['speedbar_width'] = 0;
}
// save actual values to session
$_SESSION['dump'] = $dump;
echo $json->encode($r);
obend(true);
 * http://www.mysqldumper.net
 *
 * @package         MySQLDumper
 * @version         SVN: $rev: 1207 $
 * @author          $Author$
 * @lastmodified    $Date$
 */
if (!defined('MSD_VERSION')) {
    die('No direct access.');
}
$fileName = isset($_GET['filename']) ? urldecode($_GET['filename']) : '';
if (isset($_POST['file'][0])) {
    $fileName = $_POST['file'][0];
}
$tplRestoreSelectTables = new MSDTemplate();
$tplRestoreSelectTables->set_filenames(array('tplRestoreSelectTables' => 'tpl/restore/selectTables.tpl'));
//Get Header-Infos from file
$sline = readStatusline($fileName);
if ($sline['records'] == -1) {
    // not a backup of MySQLDumper
    $tplRestoreSelectTables->assign_block_vars('NO_MSD_BACKUP', array());
} else {
    // Get Tableinfo from file header
    $tabledata = getTableHeaderInfoFromBackup($fileName);
    for ($i = 0; $i < sizeof($tabledata); $i++) {
        $klasse = $i % 2 ? 1 : '';
        $tplRestoreSelectTables->assign_block_vars('ROW', array('CLASS' => 'dbrow' . $klasse, 'ID' => $i, 'NR' => $i + 1, 'TABLENAME' => $tabledata[$i]['name'], 'RECORDS' => String::formatNumber($tabledata[$i]['records']), 'SIZE' => byteOutput($tabledata[$i]['size']), 'LAST_UPDATE' => $tabledata[$i]['update'], 'TABLETYPE' => $tabledata[$i]['engine']));
    }
}
$confirmRestore = $lang['L_FM_ALERTRESTORE1'] . ' `' . $config['db_actual'] . '`  ' . $lang['L_FM_ALERTRESTORE2'] . ' ' . $fileName . ' ' . $lang['L_FM_ALERTRESTORE3'];
$tplRestoreSelectTables->assign_vars(array('PAGETITLE' => $lang['L_RESTORE'] . ' - ' . $lang['L_TABLESELECTION'], 'DATABASE' => $config['db_actual'], 'FILENAME' => $fileName, 'ICON_OK' => $icon['ok'], 'ICON_DELETE' => $icon['delete'], 'ICON_RESTORE' => $icon['restore'], 'L_NO_MSD_BACKUP' => $lang['L_NOT_SUPPORTED'], 'CONFIRM_RESTORE' => $confirmRestore));
            $i++;
        }
    }
    $maxOffset = floor($entriesTotal / $entriesShown);
    if ($maxOffset * $entriesShown == $entriesTotal) {
        $maxOffset--;
    }
    $offsetForeward = $offset < $maxOffset ? $offset + 1 : 0;
    $offsetBackward = $offset > 0 ? $offset - 1 : $maxOffset;
    if ($revers == 0) {
        $entryTo = ($offset + 1) * $entriesShown;
        if ($entryTo > $entriesTotal) {
            $entryTo = $entriesTotal;
        }
        $pagination = sprintf($lang['L_SHOWING_ENTRY_X_TO_Y_OF_Z'], String::formatNumber($offset * $entriesShown + 1), String::formatNumber($entryTo), String::formatNumber($entriesTotal));
    } else {
        $total = $maxOffset * $entriesShown;
        $entryFrom = $entriesTotal - $offset * $entriesShown;
        if ($entryFrom > $entriesTotal) {
            $entryFrom = $entriesTotal;
        }
        $entryTo = $entriesTotal - ($offset + 1) * $entriesShown + 1;
        if ($entryTo < 1) {
            $entryTo = 1;
        }
        $pagination = sprintf($lang['L_SHOWING_ENTRY_X_TO_Y_OF_Z'], String::formatNumber($entryFrom), String::formatNumber($entryTo), String::formatNumber($entriesTotal));
    }
    $tplLog->assign_vars(array('OFFSET_FOREWARD' => $offsetForeward, 'OFFSET_BACKWARD' => $offsetBackward, 'PAGINATION_ENTRIES' => $pagination));
}
$tplLog->pparse('tplLog');
obend(true);
/**
 * Read records from table, build query-strings and write them to dump file
 *
 * @param string $db    The database to read from
 * @param string $table The table to read from
 * @return void
 */
function getContent($db, $table)
{
    global $dbo, $config, $dump, $lang, $log;
    $content = '';
    $fields = $dbo->getTableColumns($table, $db);
    // TODO decide if the type of field needs to be escaped and placed between quotes
    // also handle NULL-values very strict for MySQL-servers running with sql-mod=STRICT
    $fieldNames = array_keys($fields);
    $fieldList = '`' . implode('`,`', $fieldNames) . '`';
    // indicator if the actual table is fully dumped in this call
    $tableDone = 0;
    $sql = 'SELECT * FROM `' . $db . '`.`' . $table . '` LIMIT ' . $dump['table_record_offset'] . ',' . ($dump['restzeilen'] + 1);
    $result = $dbo->query($sql, MsdDbFactory::ARRAY_NUMERIC);
    $numRows = @count($result);
    if ($numRows > 0) {
        // we've got records - get fields
        $numfields = count($result[0]);
        if ($numRows > $dump['restzeilen']) {
            // there are more records to get - table is not fully dumped
            $dump['table_record_offset'] += $dump['restzeilen'];
            //set table record offset for next call
            $numRows--;
            // correct counter - we only used the last record to find out if there is more to fetch
            unset($result[$numRows]);
        } else {
            // table is done -> increase table offset
            $recordsSaved = $dump['table_record_offset'] + $numRows;
            $log->write(Log::PHP, sprintf($lang['L_BACKUP_TABLE_DONE'], $table, String::formatNumber($recordsSaved)));
            $dump['table_offset']++;
            $dump['table_offset_total']++;
            $dump['table_record_offset'] = 0;
            $tableDone = 1;
        }
        foreach ($result as $row) {
            //if($config['backup_using_updates']==1){
            $insert = 'INSERT INTO `' . $table . '` (' . $fieldList . ') VALUES (';
            //TODO implement REPLACE INTO for expert mode
            //	}
            //else{
            //$insert='REPLACE INTO `'.$table.'` '.$complete.' VALUES (';
            //	}
            foreach ($row as $field => $val) {
                if ($val != '') {
                    $insert .= '\'' . $dbo->escape($val) . '\',';
                } else {
                    $insert .= '\'\',';
                }
            }
            $insert = substr($insert, 0, -1) . ');' . "\n";
            $dump['data'] .= $insert;
            $dump['restzeilen']--;
            $dump['countdata']++;
            if (strlen($dump['data']) > $config['memory_limit'] || $config['multi_part'] == 1 && strlen($dump['data']) + MULTIPART_FILESIZE_BUFFER > $config['multipart_groesse']) {
                writeToDumpFile();
            }
        }
        if ($tableDone == 1) {
            // check if records have been saved and add "enable keys"
            $tables = $dump['databases'][$dump['db_actual']]['tables'];
            if ($tables[$table]['dump_records'] == 1) {
                $dump['data'] .= "/*!40000 ALTER TABLE `{$table}`" . " ENABLE KEYS */;";
            }
        }
    } else {
        // table corrupt -> skip it
        $dump['table_offset']++;
        $dump['table_offset_total']++;
        $dump['table_record_offset'] = 0;
        $dump['restzeilen'] = $dump['restzeilen'] - $numRows;
        $dump['data'] .= "/*!40000 ALTER TABLE `{$table}` ENABLE KEYS */;\n";
        if (strlen($dump['data']) > $config['memory_limit'] || $config['multi_part'] == 1 && strlen($dump['data']) + MULTIPART_FILESIZE_BUFFER > $config['multipart_groesse']) {
            writeToDumpFile();
        }
    }
}
 }
 $scriptVersion = $lang['L_UNKNOWN'];
 if ($backup['script'] > '') {
     $scriptVersion = $backup['script'];
 }
 $comment = '&nbsp;';
 if ($backup['comment'] > '') {
     $comment = nl2br(wordwrap($backup['comment'], 50));
 }
 $nrOfTables = $lang['L_UNKNOWN'];
 if ($backup['tables'] > -1) {
     $nrOfTables = String::formatNumber($backup['tables']);
 }
 $nrOfRecords = $lang['L_UNKNOWN'];
 if ($backup['records'] > -1) {
     $nrOfRecords = String::formatNumber($backup['records']);
 }
 $fileCharset = $lang['L_UNKNOWN'];
 if ($backup['charset'] != '?') {
     $fileCharset = $backup['charset'];
 }
 $tplRestorePrepare->assign_block_vars('FILE', array('ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1', 'FILE_INDEX' => $i, 'FILE_NAME' => $backup['name'], 'DB_NAME' => $dbName, 'DB_EXPAND_LINK' => $backup['db'], 'ICON_COMPRESSED' => $compressed, 'SCRIPT_VERSION' => $scriptVersion, 'COMMENT' => $comment, 'FILE_CREATION_DATE' => $backup['date'], 'NR_OF_TABLES' => $nrOfTables, 'NR_OF_RECORDS' => $nrOfRecords, 'FILESIZE' => byteOutput($backup['size']), 'FILE_CHARSET' => $fileCharset, 'NR_OF_MULTIPARTS' => $backup['multipart']));
 if ($backup['multipart'] > 0) {
     $fileCount = $lang['L_FILES'];
     if ($backup['multipart'] == 1) {
         $fileCount = $lang['L_FILE'];
     }
     $tplRestorePrepare->assign_block_vars('FILE.IS_MULTIPART', array('FILES' => $fileCount));
 } else {
     $tplRestorePrepare->assign_block_vars('FILE.NO_MULTIPART', array());
 }
 * This file is part of MySQLDumper released under the GNU/GPL 2 license
 * http://www.mysqldumper.net
 *
 * @package         MySQLDumper
 * @version         SVN: $rev: 1207 $
 * @author          $Author$
 * @lastmodified    $Date$
 */
if (!defined('MSD_VERSION')) {
    die('No direct access.');
}
include './inc/define_icons.php';
$dump = $_SESSION['dump'];
$tplDumpFinished = new MSDTemplate();
$tplDumpFinished->set_filenames(array('tplDumpFinished' => 'tpl/dump/dump_finished.tpl'));
$recordsTotal = String::formatNumber((int) $dump['records_total']);
$tablesTotal = $dump['tables_total'];
$msg = sprintf($lang['L_DUMP_ENDERGEBNIS'], $tablesTotal, $recordsTotal);
$tplDumpFinished->assign_vars(array('ICON_OPEN_FILE' => $icon['small']['open_file'], 'ICON_EDIT' => $icon['small']['edit'], 'ICON_VIEW' => $icon['small']['view'], 'SESSION_ID' => session_id(), 'BACKUPPATH' => $config['paths']['backup'], 'PAGE_REFRESHS' => $dump['page_refreshs'], 'TIME_ELAPSED' => getTimeFormat(time() - $dump['dump_start_time']), 'MSG' => $msg));
if (count($dump['databases']) > 1) {
    $msg = sprintf($lang['L_MULTIDUMP_FINISHED'], count($dump['databases']));
    $tplDumpFinished->assign_block_vars('MULTIDUMP', array('MSG' => $msg));
}
$i = 1;
foreach ($_SESSION['log']['files_created'] as $file) {
    $fileSize = @filesize($config['paths']['backup'] . $file);
    $tplDumpFinished->assign_block_vars('FILE', array('NR' => $i, 'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1', 'FILENAME' => $file, 'FILENAME_URLENCODED' => urlencode($file), 'FILESIZE' => byteOutput($fileSize)));
    $i++;
}
$i = 1;
foreach ($_SESSION['log']['actions'] as $message) {
/**
 * This file is part of MySQLDumper released under the GNU/GPL 2 license
 * http://www.mysqldumper.net
 *
 * @package         MySQLDumper
 * @version         SVN: $rev: $
 * @author          $Author$
 * @lastmodified    $Date$
 */
// Restore is finished
include './inc/define_icons.php';
$restore = $_SESSION['restore'];
$tplRestoreFinished = new MSDTemplate();
$tplRestoreFinished->set_filenames(array('tplRestoreFinished' => 'tpl/restore/restore_finished.tpl'));
$recordsInserted = String::formatNumber($restore['records_inserted']);
$recordsInserted = sprintf($lang['L_RECORDS_INSERTED'], $recordsInserted);
$tablesCreated = sprintf($lang['L_RESTORE_COMPLETE'], $restore['table_ready']);
$timeElapsed = getTimeFormat(time() - $restore['restore_start_time']);
$tplRestoreFinished->assign_vars(array('SESSION_ID' => session_id(), 'ICON_OPEN_FILE' => $icon['small']['open_file'], 'ICON_EDIT' => $icon['small']['edit'], 'ICON_VIEW' => $icon['small']['view'], 'SESSION_ID' => session_id(), 'BACKUPPATH' => $config['paths']['backup'], 'PAGE_REFRESHS' => $restore['page_refreshs'], 'TIME_ELAPSED' => $timeElapsed, 'TABLES_CREATED' => $tablesCreated, 'RECORDS_INSERTED' => $recordsInserted, 'ICONPATH' => $config['files']['iconpath']));
if (count($_SESSION['log']['errors']) > 0) {
    $i = 1;
    $tplRestoreFinished->assign_block_vars('ERRORS', array());
    foreach ($_SESSION['log']['errors'] as $logError) {
        $timestamp = substr($logError, 0, 19);
        $message = substr($logError, 20);
        $tplRestoreFinished->assign_block_vars('ERRORS.ERROR', array('NR' => $i, 'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1', 'TIMESTAMP' => $timestamp, 'MSG' => $message));
        $i++;
    }
}
$i = 1;
Ejemplo n.º 13
0
            case 'ALTE':
                $count['alter']++;
                break;
            case 'DELE':
                $count['delete']++;
                break;
            default:
                if (substr($compare, 0, 2) == '--' || substr($compare, 0, 1) == '#') {
                    $skip = true;
                }
        }
        if (!$skip) {
            $start = getMicrotime();
            try {
                $res = $dbo->query($query, MsdDbFactory::SIMPLE);
            } catch (Exception $e) {
                $logMsg = '(' . $e->getCode() . ') ' . $e->getMessage();
                $tplSqlbrowserSqlboxShowQueryResults->assign_block_vars('ERROR', array('TEXT' => Html::getJsQuote($logMsg)));
            }
            $end = getMicrotime();
            $queries[$key]['time'] = $end - $start;
            $i++;
            $tplSqlbrowserSqlboxShowQueryResults->assign_block_vars('SQL_COMMAND', array('SQL' => substr($query, 0, 100), 'EXEC_TIME' => $queries[$key]['time'], 'NR' => $i));
        }
        $tplSqlbrowserSqlboxShowQueryResults->assign_vars(array('COUNT_DROP' => String::formatNumber($count['drop']), 'COUNT_DELETE' => String::formatNumber($count['delete']), 'COUNT_CREATE' => String::formatNumber($count['create']), 'COUNT_ALTER' => String::formatNumber($count['alter']), 'COUNT_INSERT' => String::formatNumber($count['insert']), 'COUNT_SELECT' => String::formatNumber($count['select']), 'COUNT_UPDATE' => String::formatNumber($count['update'])));
    }
}
$_SESSION['sql']['statements'] = $sql['sql_statements'];
$_SESSION['sql']['order_by_field'] = $orderByField;
$_SESSION['sql']['order_direction'] = $orderDirection;
$_SESSION['sql']['offset'] = $offset;
Ejemplo n.º 14
0
foreach ($sortedTableInfos as $val) {
    if ($val['update_time'] > $lastUpdate) {
        $lastUpdate = $val['update_time'];
    }
    $updateTime = $val['update_time'] > '' ? $val['update_time'] : '&nbsp;';
    $autoIncrement = '-';
    if ((int) $val['auto_increment'] > 0) {
        $autoIncrement = String::formatNumber($val['auto_increment']);
    }
    $tplSqlbrowserTableListTables->assign_block_vars('ROW', array('ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1', 'NR' => $i + 1, 'TABLE_NAME' => $val['name'], 'TABLE_NAME_URLENCODED' => base64_encode($val['name']), 'RECORDS' => String::formatNumber($val['records']), 'DATA_LENGTH' => byteOutput($val['data_length']), 'INDEX_LENGTH' => byteOutput($val['index_length']), 'LAST_UPDATE' => $updateTime, 'ENGINE' => $val['engine'], 'COLLATION' => $val['collation'], 'COMMENT' => $val['comment'] > '' ? $val['comment'] : '', 'AUTO_INCREMENT' => $autoIncrement));
    // re-check table if it was checked before
    if (in_array(base64_encode($val['name']), $tables)) {
        $tplSqlbrowserTableListTables->assign_block_vars('ROW.TABLE_CHECKED', array());
    }
    // is table optimized?
    if (in_array($val['engine'], array('MyISAM', 'ARCHIVE'))) {
        if ($val['data_free'] == 0) {
            $tplSqlbrowserTableListTables->assign_block_vars('ROW.OPTIMIZED', array());
        } else {
            $tplSqlbrowserTableListTables->assign_block_vars('ROW.NOT_OPTIMIZED', array('VALUE' => byteOutput($val['data_free'])));
        }
    } else {
        // optimize is not supported for this engine
        $tplSqlbrowserTableListTables->assign_block_vars('ROW.OPTIMIZE_NOT_SUPPORTED', array());
    }
    $i++;
}
// Output sum-line
$indexLen = $tableInfos[$db]['size_total'] - $tableInfos[$db]['datasize_total'];
$tplSqlbrowserTableListTables->assign_block_vars('SUM', array('RECORDS' => String::formatNumber($tableInfos[$db]['records_total']), 'DATA_LENGTH' => byteOutput($tableInfos[$db]['datasize_total']), 'INDEX_LENGTH' => byteOutput($indexLen), 'LAST_UPDATE' => $lastUpdate));