Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dump y Download la Base de Datos</title>
<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-store">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Cache-Control" content="must-revalidate">
<!-- end no cache headers -->
</HEAD>
<BODY
bgcolor="#D5D5D5"
text="#000000"
id="all"
leftmargin="25"
topmargin="25"
marginwidth="25"
marginheight="25"
link="#000020"
vlink="#000020"
alink="#000020">
<center><h1>Dump y Download la Base de Datos</h1></center>
<strong>
<?php
//---------------------------------------------------------------------------------------------------
define( 'Str_VERS', "v09/01/2006 shockly AT gmail DOT com" );
error_reporting( E_ALL );
@set_time_limit( 0 );
//---------------------------------------------------------------------------------------------------
// Mysql Database Information:
$db_name = "test_db";
$db_username = "user";
$db_password = "pass";
$backup_db_save_as = "test_base";
//---------------------------------------------------------------------------------------------------
function Display_dbs( $nombre ) {
// read this directory
$thisDir = "./";
$cntFile = 0; // start file counter, names that have an extension
$cntDir = 0; // start directory counter, names with no extension
$dlist = ''; // build the resulting list and then echo the final results
if ($dir = @opendir($thisDir)) { // open a specified directory
$dlist .= "\n" . "\n" . '<ul>';
while ($file = @readdir($dir)) { // read a name from the directory
$size = filesize($file);
if( $size != 0 && !(strpos(' '.$file,'.') != 1 && !strpos(' '.$file,'.')) ) { // las carpetas tienen tamaño
if( substr( $file, 0, strlen($nombre) ) == $nombre ) {
$dlist .= "\n" . '<li><a href="' . htmlentities($file) . '">';
$dlist .= htmlentities($file) . '</a>';
$size = filesize($file);
$size = number_format($size, 0, ',', '.');
$size = str_replace( ",",".",$size );
$dlist .= "\n" . '<small style="font-weight:500;">';
$dlist .= " - $size Bytes";
$dlist .= " - " . date ("d/m/Y H:i:s", filemtime($file));
$t_file = filemtime($file);
$t_now = time();
$t_delta = $t_now - $t_file;
$t_delta = (floor($t_delta/86400))." días, "
.floor(($t_delta-(floor($t_delta/86400)*86400))/3600)." horas, "
.floor(($t_delta-(floor($t_delta/3600)*3600))/60)." minutos y "
.floor($t_delta-(floor($t_delta/60))*60)." segundos.";
$dlist .= " - Esta Base de Datos es de hace $t_delta<br>";
$dlist .= '</small>';
$dlist .= '</li>';
$cntFile += 1; // increment the counter
}
}
}
if ($cntFile < 1)
$dlist .= "\n" . '<div><li><small>(No hay, primero Salva la Base de Datos)</small></div>';
$dlist .= "\n" . '</ul>';
closedir($dir); // close the directory
}
else
$dlist .= "\n" . '<p>(Could not read the directory, or the directory does not exist.)</p>';
echo '<p>';
if ($cntFile+$cntDir > 0) { // items found, any file or directory
if ($cntFile > 0 && $cntDir > 0) { // files and directories found
echo ', ';
}
}
echo $dlist;
}
//---------------------------------------------------------------------------------------------------
$error = false;
$message = "\n";
$backup_db_as = $backup_db_save_as;
$backup_db_as .= ".gz";
$backupcommand = "mysqldump --add-drop-table --add-locks -u$db_username -p$db_password $db_name | gzip > $backup_db_as";
// primero la borra
@unlink( $backup_db_as );
$t_start = time();
// backup
passthru( "$backupcommand", $error );
if( $error ) {
$message .= "\n";
$message .= "- Problema en passthru. Error = $error\n";
$message .= "\n";
}
else {
$t_delta_bk = time() - $t_start;
$t_delta_bk = (floor(($t_delta_bk-(floor($t_delta_bk/86400)*86400))/3600)." horas, "
.floor(($t_delta_bk-(floor($t_delta_bk/3600)*3600))/60)." minutos y "
.floor($t_delta_bk-(floor($t_delta_bk/60))*60)." segundos.");
$size = filesize( $backup_db_as );
$size = number_format($size, 0, ',', '.');
$message .= "\n";
$message .= "- Base de Datos salvada: '" . $backup_db_as . "'\n";
$message .= "- Tamaño: " . $size . " bytes.\n";
$message .= "- Tardó en salvarse: " . $t_delta_bk . "\n";
}
echo( "<br>" );
$message = preg_replace( "/\n/", "<br>", $message );
echo $message;
echo( "<br><br>- Bases de Datos disponibles:<br></strong>" );
Display_dbs( $backup_db_save_as );
echo( "<br><hr><center><small>" );
setlocale( LC_TIME,"spanish" );
echo strftime( "%A %d %B %Y - %H:%M:%S", time() );
echo( "<br>" . Str_VERS );
echo( "</small></center><br>" );
echo( "</BODY>" );
echo( "</HTML>" );
exit;
//---------------------------------------------------------------------------------------------------
?>