Page 1 of 1

BACKUP MYSQL como ?

Posted: Fri Mar 23, 2007 7:44 pm
by AOKISANTOS
Gente como executar e restaurar backup no mysql ?


Alguem poderia fornecer um exemplo de como criar uma rotina para esta finalidade?

Aokisantos

SOLUCIONADO

Posted: Sun Mar 25, 2007 8:02 pm
by AOKISANTOS
SOLUCIONADO :D

Amigo...

Posted: Mon Mar 26, 2007 6:20 am
by leandro
Me podrias Indicar como lo hiceste...

De antemano Gracias :D

Re: Amigo...

Posted: Mon Mar 26, 2007 7:16 am
by wmormar
leandro wrote:Me podrias Indicar como lo hiceste...

De antemano Gracias :D
Leandr,

Me corroe la inquietud.

Me gustaria que compartieras tu solución.

gracias de antemano

Posted: Mon Mar 26, 2007 7:23 am
by Antonio Linares
En PHP:

Code: Select all

<?php

//Copyright (C) 2000-2006  Antonio Grandío Botella http://www.antoniograndio.com
//Copyright (C) 2000-2006  Inmaculada Echarri San Adrián http://www.inmaecharri.com

//This file is part of Catwin.

//CatWin is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.

//CatWin is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details:
//http://www.gnu.org/copyleft/gpl.html

//You should have received a copy of the GNU General Public License
//along with Catwin Net; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

if (!is_dir("_backups")) {mkdir("_backups");}

deldir("_backups");

$fich = $_SESSION['empresa']."---".date('Y-m-d-His').".sql";

if( !@function_exists('gzopen')) {
	$gz = false;
	$f = fopen( "_backups/".$fich, 'w' );
}
else {
	$fich = $fich . ".gz";
	$gz = true;
	$f = gzopen( "_backups/".$fich, 'w6' );
}

$db = mysql_select_db($_SESSION['empresa']);

$escribir = "-- Base de datos: ".$_SESSION['empresa']." - Fecha: " . strftime( "%d/%m/%Y - %H:%M:%S", time() )."\n";
escribir($f, $gz, $escribir);

$result = mysql_query( 'SHOW tables' );
while( $fila = mysql_fetch_array($result) ) {
	if ($_SESSION['empresa'] == "nuevocat" AND $fila[0] == "referers") {continue;}
	escribetabla( $fila[0], $f, $gz);
	escribir($f, $gz, "\n");
}

if( !$gz ){ 
	fclose($f);
	} else {
	gzclose($f);
}

echo "<a href='_backups/$fich'>Bajar la copia de seguridad <span class='b'>$fich</span></a>";

function escribetabla($table, $f = 0, $gz) {
	$escribir = "\n-- Tabla `$table`\n";
	escribir($f, $gz, "\n");
	escribir($f, $gz, $escribir);
	$escribir = mysql_fetch_array(mysql_query("SHOW CREATE TABLE $table"));
	quitar($escribir['Create Table']);
	$escribir = "DROP TABLE IF EXISTS $table;\n" . $escribir['Create Table'] . ";\n\n";
	escribir($f, $gz, $escribir);
	$escribir = "--\n";
	escribir($f, $gz, $escribir);
	$escribir = "-- Dumping `$table`\n";
	escribir($f, $gz, $escribir);
	$escribir = "--\n\n";
	escribir($f, $gz, $escribir);
	$escribir = "LOCK TABLES $table WRITE;\n";
	escribir($f, $gz, $escribir);

	$result = mysql_query("SELECT * FROM $table");
	$campos=mysql_num_fields($result);
	while ($fila = mysql_fetch_array($result)) {
		$escribir = "INSERT INTO $table VALUES(";
		escribir($f, $gz, $escribir);
		$n = 0;
		while ($n < $campos) {
			$escribir = "";
			if ($n) {$escribir = ", ";}
			if( !isset($fila["$n"])) {$escribir .= 'NULL';} else {$escribir .= "'" . mysql_escape_string($fila["$n"]) . "'";}
			escribir($f, $gz, $escribir);
			$n = $n+1;
		}
		$escribir = ");\n";
		escribir($f, $gz, $escribir);
	}
	$escribir = "UNLOCK TABLES;";
	escribir($f, $gz, $escribir);
}

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

function escribir($f, $gz, $escribir) {
	if( !$gz ){
		fwrite( $f, $escribir );
	} else {
		gzwrite( $f, $escribir );	
	}
}

function deldir($dir){
	$current_dir = opendir($dir);
	while($entryname = readdir($current_dir)){
		if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
			 deldir("${dir}/${entryname}");
			}elseif($entryname != "." and $entryname!=".."){
			unlink("${dir}/${entryname}");
		}
	}
	closedir($current_dir);
}

?>

solução

Posted: Tue Mar 27, 2007 11:43 am
by AOKISANTOS

Posted: Tue Apr 03, 2007 6:18 pm
by Willi Quintana
Holas, si se le asigna la usuario el priviliegio >"files", se puede usar la siguiente orden

"SELECT * INTO OUTFILE '/BACKS/listado.txt' FROM listado"

donde listado.txt contendra la infoirmacion de la tabla listado en formato txt plano...

Salu2