FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour BACKUP MYSQL como ?
Posts: 210
Joined: Sun Jul 23, 2006 01:15 AM
BACKUP MYSQL como ?
Posted: Fri Mar 23, 2007 07:44 PM

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
Posts: 210
Joined: Sun Jul 23, 2006 01:15 AM
SOLUCIONADO
Posted: Sun Mar 25, 2007 08:02 PM

SOLUCIONADO :D

FWH25+XHARBOUR 99.50
Posts: 1818
Joined: Wed Oct 26, 2005 02:49 PM
Amigo...
Posted: Mon Mar 26, 2007 06:20 AM

Me podrias Indicar como lo hiceste...

De antemano Gracias :D

Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Re: Amigo...
Posted: Mon Mar 26, 2007 07:16 AM
leandro wrote:Me podrias Indicar como lo hiceste...

De antemano Gracias :-)


Leandr,

Me corroe la inquietud.

Me gustaria que compartieras tu solución.

gracias de antemano
William, Morales

Saludos



méxico.sureste
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
BACKUP MYSQL como ?
Posted: Mon Mar 26, 2007 07:23 AM
En PHP:
<?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
Posts: 210
Joined: Sun Jul 23, 2006 01:15 AM
solução
Posted: Tue Mar 27, 2007 11:43 AM
FWH25+XHARBOUR 99.50
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
BACKUP MYSQL como ?
Posted: Tue Apr 03, 2007 06:18 PM

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

Continue the discussion