Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/08/2009, 09:25
Avatar de mauroave
mauroave
 
Fecha de Ingreso: julio-2009
Mensajes: 50
Antigüedad: 14 años, 9 meses
Puntos: 0
hacer backup de base de datos

BUenas, disculpen la ignorancia, soy verde en mysql y php. mi problema es el siguiente: estoy haciendo una aplicacion web con php y mysql, y una de sus funciones es hacer backup de la base de datos. pero no se como empezar!, tengo este codigo que encontre por ahi, pero lo que hace es imprimirme en la pantalla.
Lo que yo quiero es que el backup se haga a un servidor mediante FTP. Ayuda por favor!. desde ya muchas gracias

Aqui el codigo que tengo:



Código PHP:
require "../../include/funciones_php.php";

$db 'hote_paraiso';
$nombre_backup date("Y-m-d") . "-" $db ".sql";
 
// CABECERAS PARA DESCARGAR EL ARCHIVO
header"Content-type: application/savingfile" );
header"Content-Disposition: attachment; filename=$nombre_backup" );
header"Content-Description: Document." );
 
$link=conectar(); 
// RECUPERO LAS TABLAS
$tablas mysql_list_tables($db);
if (!
$tablas) {
    echo 
"Error en la base de datos: no se pueden listar las tablas \n";
    echo 
'MySQL Error: ' mysql_error();
    exit;
}
 
// RECORRO TODAS LAS TABLAS
while ($tabla mysql_fetch_row($tablas)) {
 
    
// RECUPERO LA INFORMACION DE CREACION DE LA TABLA
    
$creacion mysql_fetch_array(mysql_query("SHOW CREATE TABLE $tabla[0]"));
    echo 
"-- Informacion de creacion de la tabla $tabla[0]\n\n";
    echo 
$creacion['Create Table']."\n\n";
 
    
// VUELCO LOS REGISTROS DE LA TABLA
    
echo "-- Volcado de registros en la tabla $tabla[0]\n\n";
 
    
// RECUPERO LOS NOMBRES DE LOS CAMPOS
    
$columnas_txt "";
    
$columnas mysql_query("SHOW COLUMNS FROM $tabla[0]");
    
$cantidad_columnas mysql_num_rows($columnas);
    if (
mysql_num_rows($columnas) > 0) {
        while (
$columna mysql_fetch_assoc($columnas)) {
            
$columnas_txt .= $columna['Field'] . ", ";
        }
    }
    
$columnas substr($columnas_txt0, -2);
    echo 
"INSERT INTO $tabla[0] ($columnas) VALUES\n";
 
    
$registros_txt "";
    
$registros mysql_query("SELECT * FROM $tabla[0]");
    while (
$registro mysql_fetch_array($registros)) {
        
$i 0;
        
$registro_txt "";
        while (
$i $cantidad_columnas) {
            
$registro_txt .= "'$registro[$i]', ";
            
$i++;
        }
        
$registros_txt .= "(".substr($registro_txt0, -2)."),\n";
    }
    echo 
substr($registros_txt0, -2).";\n\n\n";
}
desconectar($link);