Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Backup bazy z PHP - działało, nie działa
d.stp
post
Post #1





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 19.04.2012

Ostrzeżenie: (0%)
-----


Witam, mam prosty skrypt który robi mi backup bazy do pliku i w przeglądarce wyskakuje mi pobranie tego pliku. Po pobraniu plik jest usuwany z serwera. Do tej pory wszystko działało, ale baza waży już jakieś 10mb i po kliknięciu w link, który generuje mi ten plik cały czas jest ładowanie strony. Wcześniej trwało to max. 5 sekund, teraz mogę czekać i czekać...

Co może być przyczyną? może są jakieś ograniczenia?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
d.stp
post
Post #2





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 19.04.2012

Ostrzeżenie: (0%)
-----


Zarejestrowałem się tam ale nie ma tam odpowiedzi na moje pytanie...

  1. <?php
  2.  
  3. /* backup the db OR just a table */
  4. function backup_tables($host,$user,$pass,$name,$tables = '*')
  5. {
  6.  
  7. $link = mysql_connect($host,$user,$pass);
  8. mysql_select_db($name,$link);
  9.  
  10. //get all of the tables
  11. if($tables == '*')
  12. {
  13. $tables = array();
  14. $result = mysql_query('SHOW TABLES');
  15. while($row = mysql_fetch_row($result))
  16. {
  17. $tables[] = $row[0];
  18. }
  19. }
  20. else
  21. {
  22. $tables = is_array($tables) ? $tables : explode(',',$tables);
  23. }
  24.  
  25. //cycle through
  26. foreach($tables as $table)
  27. {
  28. $result = mysql_query('SELECT * FROM '.$table);
  29. $num_fields = mysql_num_fields($result);
  30.  
  31. $return.= 'DROP TABLE '.$table.';';
  32. $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
  33. $return.= "\n\n".$row2[1].";\n\n";
  34.  
  35. for ($i = 0; $i < $num_fields; $i++)
  36. {
  37. while($row = mysql_fetch_row($result))
  38. {
  39. $return.= 'INSERT INTO '.$table.' VALUES(';
  40. for($j=0; $j<$num_fields; $j++)
  41. {
  42. $row[$j] = addslashes($row[$j]);
  43. $row[$j] = ereg_replace("\n","\\n",$row[$j]);
  44. if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
  45. if ($j<($num_fields-1)) { $return.= ','; }
  46. }
  47. $return.= ");\n";
  48. }
  49. }
  50. $return.="\n\n\n";
  51. }
  52.  
  53. //save file
  54. $handle = fopen('backup-'.date('d-m-Y').'.sql','w+');
  55. $file = 'backup-'.date('d-m-Y').'.sql';
  56. fwrite($handle,$return);
  57. fclose($handle);
  58.  
  59. header('Content-Description: File Transfer');
  60. header('Content-Type: application/octet-stream');
  61. header('Content-Disposition: attachment; filename='.basename($file));
  62. header('Content-Transfer-Encoding: binary');
  63. header('Expires: 0');
  64. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  65. header('Pragma: public');
  66. header('Content-Length: ' . filesize($file));
  67. flush();
  68. readfile($file);
  69. unlink($file);
  70.  
  71. }
  72.  
  73. backup_tables('x');
  74.  
  75. echo 'Backup bazy danych';
  76. echo 'Wykonano';
  77.  
  78. ?>


Odświeżam
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 13.10.2025 - 09:15