BACKUP MYSQL como ?

Post Reply
AOKISANTOS
Posts: 210
Joined: Sun Jul 23, 2006 1:15 am

BACKUP MYSQL como ?

Post by AOKISANTOS »

Gente como executar e restaurar backup no mysql ?


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

Aokisantos
FWH25+XHARBOUR 99.50
AOKISANTOS
Posts: 210
Joined: Sun Jul 23, 2006 1:15 am

SOLUCIONADO

Post by AOKISANTOS »

SOLUCIONADO :D
FWH25+XHARBOUR 99.50
User avatar
leandro
Posts: 958
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia
Contact:

Amigo...

Post by leandro »

Me podrias Indicar como lo hiceste...

De antemano Gracias :D
Saludos
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
User avatar
wmormar
Posts: 1050
Joined: Fri Oct 07, 2005 10:41 pm
Location: México
Contact:

Re: Amigo...

Post 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
William, Morales
Saludos

méxico.sureste
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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);
}

?>
regards, saludos

Antonio Linares
www.fivetechsoft.com
AOKISANTOS
Posts: 210
Joined: Sun Jul 23, 2006 1:15 am

solução

Post by AOKISANTOS »

FWH25+XHARBOUR 99.50
User avatar
Willi Quintana
Posts: 859
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú
Contact:

Post 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
Post Reply