backup med lidt hjælp fra phpmyadmin
Jeg har lånt ret kraftigt fra tbl_dump.php i phpmyadminjeg vil bare gerne bruge den lidt anderledes
den skal lave en fil på serveren hvor den ligger alle greate tables og alle inserts ind, men jeg kan ikke finde de variabler der har det rigtige indhold! her er det jeg har smedet sammen:
<?php
$what = "data";
$asfile = "sendit";
$server = "1";
$lang = "da-iso-8859-1";
$db = "skovhave";
/* $Id: tbl_dump.php,v 1.64 2002/06/14 11:59:49 lem9 Exp $ */
/**
* Formats the INSERT statements depending on the target (screen/file) of the
* sql dump
*
* @param string the insert statement
*
* @global string the buffer containing formatted strings
*/
function PMA_myHandler($sql_insert)
{
global $tmp_buffer;
// Kanji encoding convert feature appended by Y.Kawada (2001/2/21)
if (function_exists('PMA_kanji_str_conv')) {
$sql_insert = PMA_kanji_str_conv($sql_insert, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
}
// Defines the end of line delimiter to use
$eol_dlm = (isset($GLOBALS['extended_ins']) && ($GLOBALS['current_row'] < $GLOBALS['rows_cnt']))
? ','
: ';';
// Result has to be displayed on screen
if (empty($GLOBALS['asfile'])) {
echo htmlspecialchars($sql_insert . $eol_dlm . $GLOBALS['crlf']);
}
// Result has to be saved in a text file
else if (!isset($GLOBALS['zip']) && !isset($GLOBALS['bzip']) && !isset($GLOBALS['gzip'])) {
$res = $sql_insert . $eol_dlm . $GLOBALS['crlf'];
}
// Result will be saved in a *zipped file
else {
$tmp_buffer .= $sql_insert . $eol_dlm . $GLOBALS['crlf'];
}
} // end of the 'PMA_myHandler()' function
/**
* Formats the INSERT statements depending on the target (screen/file) of the
* cvs export
*
* Revisions: 2001-05-07, Lem9: added $add_character
* 2001-07-12, loic1: $crlf should be used only if there is no EOL
* character defined by the user
*
* @param string the insert statement
*
* @global string the character to add at the end of lines
* @global string the buffer containing formatted strings
*/
function PMA_myCsvHandler($sql_insert)
{
global $add_character;
global $tmp_buffer;
// Kanji encoding convert feature appended by Y.Kawada (2001/2/21)
if (function_exists('PMA_kanji_str_conv')) {
$sql_insert = PMA_kanji_str_conv($sql_insert, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
}
// Result has to be displayed on screen
if (empty($GLOBALS['asfile'])) {
$resc = htmlspecialchars($sql_insert) . $add_character;
}
// Result has to be saved in a text file
else if (!isset($GLOBALS['zip']) && !isset($GLOBALS['bzip']) && !isset($GLOBALS['gzip'])) {
$resd = $sql_insert . $add_character;
}
// Result will be saved in a *zipped file
else {
$tmp_buffer .= $sql_insert . $add_character;
}
} // end of the 'PMA_myCsvHandler()' function
/**
* Get the variables sent or posted to this script and a core script
*/
require('./libraries/grab_globals.lib.php');
require('./libraries/common.lib.php');
require('./libraries/build_dump.lib.php');
require('./libraries/zip.lib.php');
/**
* Defines the url to return to in case of error in a sql statement
*/
$err_url = 'tbl_properties.php'
. '?lang=' . $lang
. '&convcharset=' . $convcharset
. '&server=' . $server
. '&db=' . urlencode($db)
. (isset($table) ? '&table=' . urlencode($table) : '');
//over dette
/**
* Ensure zipped formats are associated with the download feature
*/
if (empty($asfile)
&& (!empty($zip) || !empty($gzip) || !empty($bzip))) {
$asfile = 1;
}
/**
* Send headers depending on whether the user choosen to download a dump file
* or not
*/
// No download
if (empty($asfile)) {
$backup_cfgServer = $cfg['Server'];
include('./header.inc.php');
$cfg['Server'] = $backup_cfgServer;
unset($backup_cfgServer);
echo '<div align="' . $cell_align_left . '">' . "\n";
echo ' <pre>' . "\n";
} // end if
// Download
else {
// Defines filename and extension, and also mime types
// Her kan filnavnet ændres!!
if (!isset($table)) {
$filename = $db;
} else {
$filename = $table;
}
$ext = 'sql';
} // end download
/**
* Builds the dump
*/
// Gets the number of tables if a dump of a database has been required
if (!isset($table)) {
$tables = PMA_mysql_list_tables($db);
$num_tables = ($tables) ? @mysql_numrows($tables) : 0;
} else {
$num_tables = 1;
$single = TRUE;
}
// No table -> error message
if ($num_tables == 0) {
echo '# ' . $strNoTablesFound;
}
// At least one table -> do the work
else {
// No csv or xml format -> add some comments at the top
if ($what != 'csv' && $what != 'excel' && $what != 'xml') {
$dump_buffer .= '# phpMyAdmin MySQL-Dump' . $crlf
. '# version ' . PMA_VERSION . $crlf
. '# http://phpwizard.net/phpMyAdmin/' . $crlf
. '# http://www.phpmyadmin.net/ (download page)' . $crlf
. '#' . $crlf
. '# ' . $strHost . ': ' . $cfg['Server']['host'];
if (!empty($cfg['Server']['port'])) {
$dump_buffer .= ':' . $cfg['Server']['port'];
}
$formatted_db_name = (isset($use_backquotes))
? PMA_backquote($db)
: '\'' . $db . '\'';
$dump_buffer .= $crlf
. '# ' . $strGenTime . ': ' . PMA_localisedDate() . $crlf
. '# ' . $strServerVersion . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
. '# ' . $strPHPVersion . ': ' . phpversion() . $crlf
. '# ' . $strDatabase . ': ' . $formatted_db_name . $crlf;
$i = 0;
if (isset($table_select)) {
$tmp_select = implode($table_select, '|');
$tmp_select = '|' . $tmp_select . '|';
}
while ($i < $num_tables) {
if (!isset($single)) {
$table = PMA_mysql_tablename($tables, $i);
}
if (isset($tmp_select) && !strpos(' ' . $tmp_select, '|' . $table . '|')) {
$i++;
} else {
$formatted_table_name = (isset($use_backquotes))
? PMA_backquote($table)
: '\'' . $table . '\'';
// If only datas, no need to displays table name
if ($what != 'dataonly') {
$dump_buffer .= '# --------------------------------------------------------' . $crlf
. $crlf . '#' . $crlf
. '# ' . $strTableStructure . ' ' . $formatted_table_name . $crlf
. '#' . $crlf . $crlf
. PMA_getTableDef($db, $table, $crlf, $err_url) . ';' . $crlf;
}
if (function_exists('PMA_kanji_str_conv')) { // Y.Kawada
$dump_buffer = PMA_kanji_str_conv($dump_buffer, $knjenc, isset($xkana) ? $xkana : '');
}
// At least data
if (($what == 'data') || ($what == 'dataonly')) {
$tcmt = $crlf . '#' . $crlf
. '# ' . $strDumpingData . ' ' . $formatted_table_name . $crlf
. '#' . $crlf .$crlf;
if (function_exists('PMA_kanji_str_conv')) { // Y.Kawada
$dump_buffer .= PMA_kanji_str_conv($tcmt, $knjenc, isset($xkana) ? $xkana : '');
} else {
$dump_buffer .= $tcmt;
}
$tmp_buffer = '';
if (!isset($limit_from) || !isset($limit_to)) {
$limit_from = $limit_to = 0;
}
// loic1: display data if they aren't bufferized
if (!isset($zip) && !isset($bzip) && !isset($gzip)) {
$rese = $dump_buffer;
// $dump_buffer = '';
}
PMA_getTableContent($db, $table, $limit_from, $limit_to, 'PMA_myHandler', $err_url);
$dump_buffer .= $tmp_buffer;
} // end if
$i++;
} // end if-else
} // end while
// staybyte: don't remove, it makes easier to select & copy from
// browser
$dump_buffer .= $crlf;
} // end 'no csv or xml' case
} // end building the dump
/**
* "Displays" the dump...
*/
$tid = date("d-m-Y",time());
$filnavn = $tid.".".$ext;
$fp = fopen ("c:\apache\htdocs/backup/$filnavn", "a");
fwrite ($fp, $dump_buffer);
fclose($fp);
//der der står her er bare får at find ud af hvad der er ivariablerne!
echo $filnavn."<br>";
echo "res<br>".substr($res,0,1000)."<p><strong> ...</strong>".strlen($res)."</p>";
echo "rese<br>".substr($rese,0,1000)."<p><strong> ...</strong>".strlen($rese)."</p>";
/**
* Close the html tags and add the footers in dump is displayed on screen
*/
if (empty($asfile)) {
echo ' </pre>' . "\n";
echo '</div>' . "\n";
echo "\n";
include('./footer.inc.php');
} // end if
?>
