Hello,
There are some problems when backuping very large database. What should I change to backup the code below as table (not conbine)?
Can you help, please?
<?php
session_start();
error_reporting(E_ALL & ~E_NOTICE);
header('Content-Type: text/html; charset=utf-8');
include('../includes/baglantii.php');
@ini_set('memory_limit', '-1');
backup_tables($mysqlibag,$db_name);
/* backup the db OR just a table */
function backup_tables($baglanti, $dbname, $tables = '*'){
######## TARİH #################################################################
setlocale(LC_ALL, 'tr_TR.UTF8');
date_default_timezone_set('Europe/Istanbul');
$yedekleme_tarihi = strftime("%d_%m_%Y_%H_%M_%S", time());
######## TARİH #################################################################
// Yedeği GZ ile sıkıştır evet true, hayır false
$gz_enable=true; // true / false
if($_POST['rolu']=='1' AND !empty($_SESSION['uye']))
{
$first_table_veriable=$tables;
$return=null;
$mysql = $baglanti->query("SELECT VERSION() AS version")->fetch_row();
$mysql_character = $baglanti->query("SHOW VARIABLES LIKE '%character%'")->fetch_row();
// BASE TABLE SAVE
//get all of the tables
if($tables == '*')
{
$return .= "\n-- Karakter: ".$mysql_character[1]."\n";
$return .= "-- PHP Sürümü: ".phpversion()."\n";
$return .= "-- Sunucu sürümü: ".$mysql[0]."\n";
$return .= "-- Anamakine: ".$_SERVER['HTTP_HOST']."\n";
$return .= '-- Üretim Zamanı: ' . strftime("%d %B %Y, %H:%M:%S", time()) . "\n";
$return .= "-- Veritabanı: " . $dbname . "\n";
$return .= "--\n";
$return .= "-- --------------------------------------------------\n\n";
$return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ;
$return .= 'SET FOREIGN_KEY_CHECKS=0 ;';
$tables = array();
$result = $baglanti->query("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'");
while($row = $result->fetch_row())
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = $baglanti->query('SELECT * FROM '.$table);
$num_fields = $result->field_count;
$return .= "\n\n--\n" ;
$return .= '-- Tablo için tablo yapısı `' . $table . '`' . "\n" ;
$return .= "--\n\n" ;
$return.= 'DROP TABLE IF EXISTS '.$table.';';
$row2 = $baglanti->query('SHOW CREATE TABLE '.$table)->fetch_row();
$return.= "\n".$row2[1].";\n";
$return .= "\n--\n" ;
$return .= '-- Tablo döküm verisi `' . $table . '`' . "\n" ;
$return .= "--\n\n" ;
for ($i = 0; $i < $num_fields; $i++)
{
@set_time_limit(0);
while($row = $result->fetch_row())
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = preg_replace("/\r\n/","\\r\\n",$row[$j]);
if (isset($row[$j])) { $return.= "'".$row[$j]."'" ; } else { $return.= "''"; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n-- --------------------------------------------------------";
}
// WIEW SAVE
//get all of the tables
$tables = $first_table_veriable;
if($tables == '*')
{
$tables = array();
$result = $baglanti->query("SHOW FULL TABLES WHERE Table_type = 'VIEW'");
while($row = $result->fetch_row())
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = $baglanti->query('SELECT * FROM '.$table);
$return.= 'DROP TABLE IF EXISTS '.$table.';';
$row2 = $baglanti->query('SHOW CREATE VIEW '.$table)->fetch_row();
$return.= "\n".$row2[1].";\n";
$return.="\n\n\n";
}
// Close the connection
$baglanti->close();
$return.="\n\n";
$return .= 'SET FOREIGN_KEY_CHECKS = 1 ; ' . "\n" ;
$return .= 'COMMIT ; ' . "\n" ;
$return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
//save file
if($gz_enable){
$gzdata = gzencode($return, 9);
$handle = fopen('tarih-'.$yedekleme_tarihi.'.sql.gz','w+');
fwrite($handle, $gzdata);
fclose($handle);
}else{
$handle = fopen('tarih-'.$yedekleme_tarihi.'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
if($handle !=""){
echo '<center><b>Veritabanı Başarıyla Yedeklendi.</b></center>';
}else{
echo '<center><b>Veritabanı Bir Hatadan Dolayı Yedeklenemedi.</b></center>';
}
return $handle;
}
}
?>
Thank you in advance
Best Regards