Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 29

Discussione: BAckup Database

  1. #1

    BAckup Database

    Salve,

    Ho realizzato un sito in php\mysql, come posso ad esempio ogni notte effettuare la copia del database, e spedirla ad un'altro sito con lo stesso database, in modo da fare una copia di backup?


    Grazie

  2. #2
    Devi creare uno scriptino semplicissimo che usi i comandi mysqldump (per il backup) e mysql (per l'inserimento), e mettere lo scriptino in cron o esecuzione automatica.

    Ovviamente il secondo server deve consentirti l'accesso dall'esterno e devi avere un utente con privilegi adeguati.

    Per tutte le opzioni dei comandi di cui sopra, vai su mysql.com

    Ciao
    Addio Aldo, amico mio... [03/12/70 - 16/08/03]

  3. #3
    Il server non mi permette l'accesso esterno, se salvassi il contenuto del database in un file, e dopo tramite form andassi a caricare il database leggendo i dati del file?

  4. #4
    Ciao, interessa anche a me questa cosa,
    ed ho cercato su php.net una documentazione riguardante il comando
    mysqldump, e non ho trovato nulla.

    mi potresti cortesemente linkare la pagina dove trovo le info sul comando?

    Grazie 1000
    Luca
    www.numeroverde800.com Numero Verde per le aziende.

  5. #5

    eccovi lo script del dump

    ciao gruppo, eccovi lo script per il dump dei dati, dovrete semplicemete indirizzare la pagina con lo script tramite crontab o altro

    **************** backup.php *****************

    codice:
    <?
    		$target="file";
    		$fileSalvato = "E-Bruno - Dump_Dati del " . date("d-m-Y Gis") . ".sql";
    		if($target=="file")
    		{
    			header('Content-Type: application/octetstream');
    			# header('Content-Disposition: filename="backup.sql"');
    			header('Content-Disposition: filename='. $fileSalvato);
    			$asfile="download";
    		}
    
    		
    		$crlf="\r\n";
    
    		$link = mysql_connect("localhost", "", "");
    		$database = mysql_select_db("assistenza"); 
    	
    		$dbname = "assistenza";
    	
    		$dump_buffer="";
    	
    		$tables = mysql_query("show tables from $dbname");
    		$num_tables = mysql_num_rows($tables);
    	
    		if($num_tables == 0)
    		{
    			echo "# nessuna tabella trovata";
    			exit;
    		}
    		
    		$dump_buffer.= "# DatabaseBackup $crlf";
    		$dump_buffer.= "# Backup eseguito da:$crlf";
    		$dump_buffer.= "# ".date("F j, Y, g:i a")."$crlf";
    		$dump_buffer.= "# Database: $dbname$crlf";
    		$dump_buffer.= "# backup tabelle : $dbname $crlf";
    	
    		$i = 0;
    		while($i < $num_tables)
    		{
    			$table = mysql_tablename($tables, $i);
    			//echo $table . "
    ";
    				$dump_buffer.= "# --------------------------------------------------------$crlf";
    				$dump_buffer.= "$crlf#$crlf";
    				$dump_buffer.= "# Struttura per la tabella  '$table'$crlf";
    				$dump_buffer.= "#$crlf$crlf";
    				$db = $table;
    				$dump_buffer.= get_table_def($table, $crlf,$dbname).";$crlf";
    				$dump_buffer.= "$crlf#$crlf";
    				$dump_buffer.= "# Dumping dati tabella '$table'$crlf";
    				$dump_buffer.= "#$crlf$crlf";
    				$tmp_buffer="";
    				get_table_content($dbname, $table, 0, 0, 'my_handler', $dbname);
    				$dump_buffer.=$tmp_buffer;
    				
    			$i++;
    			$dump_buffer.= "$crlf";
    		}
    		echo $dump_buffer;
    		exit;
    	
    	function get_table_def($table, $crlf,$dbname)
    	{
    	
    		$schema_create = "DROP TABLE IF EXISTS $table;$crlf";
    		$db = $table;
    	
    		$schema_create .= "CREATE TABLE $table ($crlf";
    	
    		$result = mysql_query("SHOW FIELDS FROM " .$dbname."."
    		. $table) or die();
    		while($row = mysql_fetch_array($result))
    		{
    			$schema_create .= "   $row[Field] $row[Type]";
    	
    			if(isset($row["Default"]) && (!empty($row["Default"]) || $row["Default"] == "0"))
    				$schema_create .= " DEFAULT '$row[Default]'";
    			if($row["Null"] != "YES")
    				$schema_create .= " NOT NULL";
    			if($row["Extra"] != "")
    				$schema_create .= " $row[Extra]";
    			$schema_create .= ",$crlf";
    		}
    		$schema_create = ereg_replace(",".$crlf."$", "", $schema_create);
    		$result = mysql_query("SHOW KEYS FROM " .$dbname."." .
    		$table) or die();
    		while($row = mysql_fetch_array($result))
    		{
    			$kname=$row['Key_name'];
    			$comment=(isset($row['Comment'])) ? $row['Comment'] : '';
    			$sub_part=(isset($row['Sub_part'])) ? $row['Sub_part'] : '';
    	
    			if(($kname != "PRIMARY") && ($row['Non_unique'] == 0))
    				$kname="UNIQUE|$kname";
    	
    			if($comment=="FULLTEXT")
    				$kname="FULLTEXT|$kname";
    			 if(!isset($index[$kname]))
    				 $index[$kname] = array();
    	
    			if ($sub_part>1)
    			 $index[$kname][] = $row['Column_name'] . "(" . $sub_part . ")";
    			else
    			 $index[$kname][] = $row['Column_name'];
    		}
    	
    		while(list($x, $columns) = @each($index))
    		{
    			 $schema_create .= ",$crlf";
    			 if($x == "PRIMARY")
    				$schema_create .= "   PRIMARY KEY (";
    			 elseif (substr($x,0,6) == "UNIQUE")
    				$schema_create .= "   UNIQUE " .substr($x,7)." (";
    			 elseif (substr($x,0,8) == "FULLTEXT")
    				$schema_create .= "   FULLTEXT ".substr($x,9)." (";
    			 else
    				$schema_create .= "   KEY $x (";
    	
    			$schema_create .= implode($columns,", ") . ")";
    		}
    	
    		$schema_create .= "$crlf)";
    		if(get_magic_quotes_gpc()) {
    		  return (stripslashes($schema_create));
    		} else {
    		  return ($schema_create);
    		}
    	}
    	function get_table_content($db, $table, $limit_from = 0, $limit_to = 0,$handler)
    	{
    		// Defines the offsets to use
    		if ($limit_from > 0) {
    			$limit_from--;
    		} else {
    			$limit_from = 0;
    		}
    		if ($limit_to > 0 && $limit_from >= 0) {
    			$add_query  = " LIMIT $limit_from, $limit_to";
    		} else {
    			$add_query  = '';
    		}
    	
    		get_table_content_fast($db, $table, $add_query,$handler);
    	
    	}
    	
    	function get_table_content_fast($db, $table, $add_query = '',$handler)
    	{
    		$result = mysql_query('SELECT * FROM ' . $db . '.' . $table . $add_query) or die();
    		if ($result != false) {
    	
    			@set_time_limit(1200); // 20 Minutes
    	
    			// Checks whether the field is an integer or not
    			for ($j = 0; $j < mysql_num_fields($result); $j++) {
    				$field_set[$j] = mysql_field_name($result, $j);
    				$type          = mysql_field_type($result, $j);
    				if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
    					$type == 'bigint'  ||$type == 'timestamp') {
    					$field_num[$j] = true;
    				} else {
    					$field_num[$j] = false;
    				}
    			} // end for
    	
    			// Get the scheme
    			if (isset($GLOBALS['showcolumns'])) {
    				$fields        = implode(', ', $field_set);
    				$schema_insert = "INSERT INTO $table ($fields) VALUES (";
    			} else {
    				$schema_insert = "INSERT INTO $table VALUES (";
    			}
    	
    			$field_count = mysql_num_fields($result);
    	
    			$search  = array("\x0a","\x0d","\x1a"); //\x08\\x09, not required
    			$replace = array("\\n","\\r","\Z");
    	
    	
    			while ($row = mysql_fetch_row($result)) {
    				for ($j = 0; $j < $field_count; $j++) {
    					if (!isset($row[$j])) {
    						$values[]     = 'NULL';
    					} else if (!empty($row[$j])) {
    						// a number
    						if ($field_num[$j]) {
    							$values[] = $row[$j];
    						}
    						// a string
    						else {
    							$values[] = "'" . str_replace($search, $replace, addslashes($row[$j])) . "'";
    						}
    					} else {
    						$values[]     = "''";
    					} // end if
    				} // end for
    	
    				$insert_line = $schema_insert . implode(',', $values) . ')';
    				unset($values);
    	
    				// Call the handler
    				$handler($insert_line);
    			} // end while
    		} // end if ($result != false)
    	
    		return true;
    	}
    	
    	
    	function my_handler($sql_insert)
    	{
    		global $crlf, $asfile;
    		global $tmp_buffer;
    	
    		if(empty($asfile))
    			$tmp_buffer.= htmlspecialchars("$sql_insert;$crlf");
    		else
    			$tmp_buffer.= "$sql_insert;$crlf";
    	}
    	
    	
    	
    	function faqe_db_error()
    	{
    		return mysql_error();
    	}
    	
    	
    	
    	function faqe_db_insert_id($result)
    	{
    		return mysql_insert_id($result);
    	}
    
    
    ?>
    creare poi lo script per l'esecuzione automatica

    c i a o ....
    "Puoi anche alzarti molto presto ma il tuo destino s'č alzato un'ora prima."
    Quello che noi osserviamo non č la natura in se stessa, ma la natura esposta al nostro metodo di interrogazione.Werner Heisenberg

  6. #6
    @massimodan

    con
    show create table

    acquisisci istantaneamente la struttura della tabella senza doverla ricostruire


    PS: tanto per completezza ... su www.phpsoft.it/downloads.php c'č il mio script per i dump dei database che ti fa fare export ed import con compressione e decompressione ... ti permette anche di definire dei filtri di esportazione

  7. #7

    x massimodan

    ho provato a mettere su il tuo script ma mi salva il file.sql con il seguente messaggio di errore:




    Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4953344 bytes) in /home/webadmin/miosito.com/html/admin/backup.php on line 53



    casa devo fare?
    Grazie
    www.numeroverde800.com Numero Verde per le aziende.

  8. #8

    che versione

    che versione di php ?

    p.s. oggi operano mio papā per cui potrei risponderti domani ok?
    ciao
    Quello che noi osserviamo non č la natura in se stessa, ma la natura esposta al nostro metodo di interrogazione.Werner Heisenberg

  9. #9

    daniele_dll

    bello veramente

    ciao
    Quello che noi osserviamo non č la natura in se stessa, ma la natura esposta al nostro metodo di interrogazione.Werner Heisenberg

  10. #10

    Re: x massimodan

    Originariamente inviato da elsombrero
    ho provato a mettere su il tuo script ma mi salva il file.sql con il seguente messaggio di errore:




    Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4953344 bytes) in /home/webadmin/miosito.com/html/admin/backup.php on line 53



    casa devo fare?
    Grazie
    non puoi usare ne il mio ne il suo sistema di backup allora

    purtroppo hai il db troppo grande mi sa :\

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.