Ver Mensaje Individual
  #14 (permalink)  
Antiguo 28/11/2010, 12:26
Avatar de Flakiss
Flakiss
 
Fecha de Ingreso: septiembre-2009
Mensajes: 113
Antigüedad: 14 años, 7 meses
Puntos: 1
Respuesta: Respaldar Base de datos MYSQL..

Amigos

comparto con ustedes el script que me salvo la vida, este me aguanto descargar una base dedatos qe pesa mas entre 130 y 140 MB. Para mi ya esta muy bien con esto!
Gracias a todos los que aportaron con su tiempo y disposicion :D

El script comprime el archivo en .gz es yo lo deje tal cual :D
les deje el link de descarga ... http://www.zoneartcss.com/wp-content...e_db_1.1.1.zip

<?php
include "pags/conectar.php";
/*
Copyright 2005 © [email protected]

Se otorga el permiso para copiar, distribuir, y/o modificar este programa bajo los términos
de la Licencia GNU de Documentación Libre (GFDL, GNU Free Documentation License) versión 2
o posteriores publicadas por la Fundación Software Libre (FSF, Free Software Foundation).

Según esta licencia, cualquier trabajo derivado de esta documentación deberá ser notificado
al autor, aunque la voluntad del mismo es otorgar la máxima libertad posible.

Este programa se distribuye con la intención de ser útil, pero SIN NINGUNA GARANTÍA; incluso
sin la garantía implícita de USABILIDAD o UTILIDAD PARA UN FIN PARTICULAR. Vea la Licencia
Pública General GNU para más detalles.

Soporte y Updaters: http://insidephp.sytes.net
email: [email protected]
*/
//------------------------------------------------------------------------------------------
// Definiciones


// Conexión con la Base de Datos.

$db_server = "localhost";
$db_name = "basededatos";
$db_username = "user";
$db_password = "password";

// Nombre del archivo.

$filename = "respaldo_bd/respaldobd.sql";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</HEAD>
<body>
<table width="829" height="368" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#99CCFF" bgcolor="#FFFFFF">

<tr>

<td width="825" height="366" align="center"><p>&nbsp;</p>

<p><strong><font size="3" face="Verdana">RESPALDO BASE DE DATOS </font></strong><br>

<br>

</p>

<table width="74%" height="87" border="1" align="center">

<tr>

<td height="81" valign="top" bgcolor="#CCCCCC" align="center"><B>

<?


function fetch_table_dump_sql($table, $fp = 0) {
$tabledump = "--\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "-- Table structure for table `$table`\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "--\n\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);

$tabledump = query_first("SHOW CREATE TABLE $table");
strip_backticks($tabledump['Create Table']);
$tabledump = "DROP TABLE IF EXISTS $table;\n" . $tabledump['Create Table'] . ";\n\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);

$tabledump = "--\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "-- Dumping data for table `$table`\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "--\n\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);

$tabledump = "LOCK TABLES $table WRITE;\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);

$rows = query("SELECT * FROM $table");
$numfields=mysql_num_fields($rows);
while ($row = fetch_array($rows, DBARRAY_NUM)) {
$tabledump = "INSERT INTO $table VALUES(";
$fieldcounter = -1;
$firstfield = 1;
// campos
while (++$fieldcounter < $numfields) {
if( !$firstfield) {
$tabledump .= ', ';
}
else {
$firstfield = 0;
}
if( !isset($row["$fieldcounter"])) {
$tabledump .= 'NULL';
}
else {
$tabledump .= "'" . mysql_escape_string($row["$fieldcounter"]) . "'";
}
}
$tabledump .= ");\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
}
free_result($rows);
$tabledump = "UNLOCK TABLES;\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
}

function strip_backticks(&$text) {
return $text;
}

function fetch_array($query_id=-1) {
if( $query_id!=-1) {
$query_id=$query_id;
}
$record = mysql_fetch_array($query_id);
return $record;
}

function problemas($msg) {
$errdesc = mysql_error();
$errno = mysql_errno();
die("");
}

function free_result($query_id=-1) {
if( $query_id!=-1) {
$query_id=$query_id;
}
return @mysql_free_result($query_id);
}

function query_first($query_string) {
$res = query($query_string);
$returnarray = fetch_array($res);
free_result($res);
return $returnarray;
}

function query($query_string) {
$query_id = mysql_query($query_string);
if( !$query_id) {
problemas("Invalid SQL: ".$query_string);
}
return $query_id;
}


//------------------------------------------------------------------------------------------
// Main
?>
<?php
@set_time_limit( 0 );
$error = false;
$tablas = 0;

if( !@function_exists( 'gzopen' ) ) {
$hay_Zlib = false;
}
else {
$filename = $filename. ".gz";
$hay_Zlib = true;
}

if( !$error ) {
$dbconnection = @mysql_connect( $db_server, $db_username, $db_password );
if( $dbconnection)
$db = mysql_select_db( $db_name );
if( !$dbconnection || !$db ) {
$error = true;
}
else {
}
}

if( !$error ) {
// MySQL versión
$result = mysql_query( 'SELECT VERSION() AS version' );
if( $result != FALSE && @mysql_num_rows($result) > 0 ) {
$row = mysql_fetch_array($result);
} else {
$result = @mysql_query( 'SHOW VARIABLES LIKE \'version\'' );
if( $result != FALSE && @mysql_num_rows($result) > 0 ){
$row = mysql_fetch_row( $result );
}
}
if(! isset($row) ) {
$row['version'] = '3.21.0';
}
}

if( !$error ) {
$el_path = getenv("REQUEST_URI");
$el_path = substr($el_path, strpos($el_path, "/"), strrpos($el_path, "/"));

$result = mysql_list_tables( $db_name );
if( !$result ) {
$error = true;
}
else {
$t_start = time();

if( !$hay_Zlib )
$filehandle = fopen( $filename, 'w' );
else
$filehandle = gzopen( $filename, 'w6' ); // nivel de compresión

if( !$filehandle ) {
$el_path = getenv("REQUEST_URI");
$el_path = substr($el_path, strpos($el_path, "/"), strrpos($el_path, "/"));
}
else {
$tabledump = "-- Dump de la Base de Datos\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
setlocale( LC_TIME,"spanish" );
$tabledump = "-- Fecha: " . strftime( "%A %d %B %Y - %H:%M:%S", time() ) . "\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
$tabledump = "--\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
$tabledump = "-- Version: " . Str_VERS . ", del " . Str_DATE . ", [email protected]\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
$tabledump = "-- Soporte y Updaters: http://insidephp.sytes.net\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
$tabledump = "--\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
$tabledump = "-- Host: `$db_server` Database: `$db_name`\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
$tabledump = "-- ------------------------------------------------------\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
$tabledump = "-- Server version ". $row['version'] . "\n\n";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );

$result = query( 'SHOW tables' );
while( $currow = fetch_array($result, DBARRAY_NUM) ) {
fetch_table_dump_sql( $currow[0], $filehandle );
fwrite( $filehandle, "\n" );
if( !$hay_Zlib )
fwrite( $filehandle, "\n" );
else
gzwrite( $filehandle, "\n" );
$tablas++;
}
$tabledump = "\n-- Dump de la Base de Datos Completo.";
if( !$hay_Zlib )
fwrite( $filehandle, $tabledump );
else
gzwrite( $filehandle, $tabledump );
if( !$hay_Zlib )
fclose( $filehandle );
else
gzclose( $filehandle );

$t_now = time();
$t_delta = $t_now - $t_start;
if( !$t_delta )
$t_delta = 1;
$t_delta = floor(($t_delta-(floor($t_delta/3600)*3600))/60)." minutos y "
.floor($t_delta-(floor($t_delta/60))*60)." segundos.";
echo( "- <br>Puede descargar directamente: </strong><a href=\"$filename\">Respaldo Base de Datos.</a>" );
$size = filesize($filename);
$size = number_format( $size );
$size = str_replace( ",",".",$size );
}
}
}

if( $dbconnection )
mysql_close();
//------------------------------------------------------------------------------------------
// END*/
?></B></td>
</tr>
</table>
</td>
</tr>
</table>

</body></HTML>