Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Zautomatyzowany zrzut bazy danych
wizard144
post 23.09.2009, 07:38:57
Post #1





Grupa: Zarejestrowani
Postów: 138
Pomógł: 3
Dołączył: 4.05.2009

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


Witam, czy znacie może jakieś DZIAŁAJĄCE skrypty które automatycznie zrzucają bazę danych?

Pozdrawiam!
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
marcio
post 24.09.2009, 11:56:27
Post #2





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


  1.  
  2. function create_backup_file($file_name_backup, $drop = false) {
  3.  
  4. $file = fopen($file_name_backup, 'w+');
  5.  
  6. $output = "# Czas wygenerowania: ".date('d-m-Y G:i')."\r\n";
  7. $output .= "# Wersja serwera: ".mysql_get_server_info()."\r\n";
  8. $output .= "# Wersja php: ".phpversion()."\r\n\r\n";
  9. fwrite($file, $output);
  10.  
  11. $query = 'SHOW TABLES';
  12. $result = mysql_query($query);
  13. while ($row = mysql_fetch_assoc($result)) foreach ($row as $table) {
  14.  
  15. $struct_table[$table] = '';
  16. $struct_table[$table] .= "\r\n\r\n# Struktura tabeli: ".$table."\r\n\r\n\r\n";
  17.  
  18. $query_struct_table = mysql_query("SHOW CREATE TABLE `$table`");
  19. while($struct = mysql_fetch_row($query_struct_table)) {
  20.  
  21. foreach($struct as $tbl)
  22.  
  23. if($drop) {
  24.  
  25. $struct_table[$table] .= 'DROP TABLE IF EXISTS `'.$table."`;\r\n";
  26. $struct_table[$table] .= $tbl. ";\r\n\r\n";
  27. }
  28. else $struct_table[$table] .= $tbl. ";\r\n\r\n";
  29. }
  30.  
  31. fwrite($file, $struct_table[$table]);
  32.  
  33. $table_zaw = "-------------------------------\r\n";
  34. $table_zaw .= '-- Zawartosc tabeli: '.$table."\r\n";
  35. $table_zaw .= "-------------------------------\r\n\r\n\r\n";
  36.  
  37. fwrite($file, $table_zaw);
  38. $result2 = mysql_query('SHOW COLUMNS FROM '.$table);
  39. $col_names= '';
  40.  
  41. while($row = mysql_fetch_array($result2)) $col_names .= "`$row[0]`".', ';
  42.  
  43. $col_names = substr($col_names, 0, -2);
  44. $result2 = mysql_query('SELECT * FROM '.$table);
  45. $num = mysql_num_fields($result2);
  46.  
  47. while($row2 = mysql_fetch_row($result2)) {
  48.  
  49. $values = '';
  50. for($i = 0; $i < $num; $i++) {
  51.  
  52. $type = mysql_field_type($result2, $i);
  53. if($type == "tinyint" || $type == "smallint" || $type == "mediumint" || $type == "int" || $type == "bigint" || $type == "timestamp") $values.= $row2[$i].', '; else $values .= "'$row2[$i]'".', ';
  54. }
  55. $values = substr($values, 0, -2);
  56. $insert = "INSERT INTO ".$table."(".$col_names.") VALUES(".$values.");\r\n";
  57. fwrite($file, trim($insert, "\n"));
  58. }
  59. }
  60. fclose($file);
  61. }
  62.  
  63.  
  64. function download_file($file_backup) {
  65.  
  66. header('Content-type: application/x-unknown');
  67. header('Content-Disposition: attachment; filename='.$file_backup);
  68. header('Connection: close');
  69. header('Expires: 0');
  70. readfile($file_backup);
  71. }
  72.  
  73.  


Moja funkcja jak wywolac chyba kazdy wie.









--------------------
Zainteresowania: XML | PHP | MY(SQL)| C# for .NET | PYTHON
http://code.google.com/p/form-builider/
Moj blog
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 21:45