Revision 182
Added by ryan about 20 years ago
| trunk/wb/modules/backup/backup-sql.php | ||
|---|---|---|
| 1 |
<?php |
|
| 2 |
|
|
| 3 |
// $Id$ |
|
| 4 |
|
|
| 5 |
/* |
|
| 6 |
|
|
| 7 |
Website Baker Project <http://www.websitebaker.org/> |
|
| 8 |
Copyright (C) 2004-2005, Ryan Djurovich |
|
| 9 |
|
|
| 10 |
Website Baker is free software; you can redistribute it and/or modify |
|
| 11 |
it under the terms of the GNU General Public License as published by |
|
| 12 |
the Free Software Foundation; either version 2 of the License, or |
|
| 13 |
(at your option) any later version. |
|
| 14 |
|
|
| 15 |
Website Baker is distributed in the hope that it will be useful, |
|
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 18 |
GNU General Public License for more details. |
|
| 19 |
|
|
| 20 |
You should have received a copy of the GNU General Public License |
|
| 21 |
along with Website Baker; if not, write to the Free Software |
|
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 23 |
|
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
// Check if user clicked on the backup button |
|
| 27 |
if(!isset($_POST['backup'])){ header('Location: ../'); }
|
|
| 28 |
|
|
| 29 |
// Temporary backup file |
|
| 30 |
$temp_file = WB_PATH.'/temp/WB-backup-'.date('ymd-His').'.sql';
|
|
| 31 |
|
|
| 32 |
// Get table names |
|
| 33 |
$result = $database->query("SHOW TABLE STATUS");
|
|
| 34 |
|
|
| 35 |
// Loop through tables |
|
| 36 |
while($row = $result->fetchRow()) {
|
|
| 37 |
$query = $database->query("SHOW CREATE TABLE ".$row['Name']);
|
|
| 38 |
$sql_backup = "\r\n# Create table ".$row['Name']."\r\n\r\n"; |
|
| 39 |
// Start creating sql-backup |
|
| 40 |
$out = $query->fetchRow(); |
|
| 41 |
$sql_backup .= $out['Create Table'].";\r\n\r\n"; |
|
| 42 |
$sql_backup .= "# Dump data\r\n\r\n"; |
|
| 43 |
$sql = "SELECT * FROM ".$row['Name']; |
|
| 44 |
// SQL code to select everything |
|
| 45 |
$out = $database->query($sql); |
|
| 46 |
$sql_code = ''; |
|
| 47 |
while($code = $out->fetchRow()) {
|
|
| 48 |
// Loop trough all collumns |
|
| 49 |
$sql_code .= "INSERT INTO ".$row['Name']." SET "; |
|
| 50 |
$numeral = 0; |
|
| 51 |
foreach($code as $insert => $value) {
|
|
| 52 |
if($numeral==1) {
|
|
| 53 |
// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't? |
|
| 54 |
$sql_code.= $insert." = '".addslashes($value)."',"; |
|
| 55 |
} |
|
| 56 |
$numeral = 1 - $numeral; |
|
| 57 |
} |
|
| 58 |
$sql_code = substr($sql_code, 0, -1); |
|
| 59 |
$sql_code.= ";\r\n"; |
|
| 60 |
} |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
// Output file |
|
| 64 |
header('Content-Type: application/octet-stream');
|
|
| 65 |
header('Content-Disposition: attachment; filename="'.str_replace(WB_PATH.'/temp', '', $temp_file).'"');
|
|
| 66 |
echo $sql_code; |
|
| 67 |
|
|
| 68 |
?> |
|
| 0 | 69 | |
Also available in: Unified diff
Moved backup-sql code into seperate script