Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/07/2011, 06:01
Avatar de aniMAYtions
aniMAYtions
 
Fecha de Ingreso: diciembre-2007
Ubicación: Granada
Mensajes: 519
Antigüedad: 16 años, 4 meses
Puntos: 2
Respuesta: backup db desde script?

También he probado esta forma:
Código PHP:

$conexion 
conectar();
    
    
$db 'ilscnse';
    
$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." );
     
    
// CONEXION A LA DB
    
$conexion 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";
    } 
Y ocurren 2 cosas:
Si la llamo desde xajax no me da error. Se queda un ratillo cargando y no hace nada más.
Si la llamo como función php normal me aparece durante segundos varios warnings diciendo que no puedo cambiar las cabeceras...

Ésto es un lío.

Gracias!!