| 1 |
182
|
ryan
|
<?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 |
191
|
ryan
|
// Filename to use
|
| 27 |
|
|
$filename = $_SERVER['HTTP_HOST'].'-backup-'.gmdate('Y-m-d', mktime()+TIMEZONE).'.sql';
|
| 28 |
|
|
|
| 29 |
182
|
ryan
|
// Check if user clicked on the backup button
|
| 30 |
|
|
if(!isset($_POST['backup'])){ header('Location: ../'); }
|
| 31 |
|
|
|
| 32 |
187
|
ryan
|
// Include config
|
| 33 |
|
|
require_once('../../config.php');
|
| 34 |
182
|
ryan
|
|
| 35 |
187
|
ryan
|
// Create new admin object
|
| 36 |
|
|
require(WB_PATH.'/framework/class.admin.php');
|
| 37 |
|
|
$admin = new admin('Settings', 'settings_advanced', false);
|
| 38 |
|
|
|
| 39 |
|
|
// Begin output var
|
| 40 |
189
|
ryan
|
$output = "".
|
| 41 |
188
|
ryan
|
"#\n".
|
| 42 |
189
|
ryan
|
"# Website Baker ".WB_VERSION." Database Backup\n".
|
| 43 |
|
|
"# ".WB_URL."\n".
|
| 44 |
191
|
ryan
|
"# ".gmdate(DATE_FORMAT, mktime()+TIMEZONE).", ".gmdate(TIME_FORMAT, mktime()+TIMEZONE)."\n".
|
| 45 |
187
|
ryan
|
"#".
|
| 46 |
|
|
"\n";
|
| 47 |
|
|
|
| 48 |
182
|
ryan
|
// Get table names
|
| 49 |
|
|
$result = $database->query("SHOW TABLE STATUS");
|
| 50 |
|
|
|
| 51 |
|
|
// Loop through tables
|
| 52 |
190
|
ryan
|
while($row = $result->fetchRow()) {
|
| 53 |
|
|
//show sql query to rebuild the query
|
| 54 |
|
|
$sql = 'SHOW CREATE TABLE '.$row['Name'].'';
|
| 55 |
|
|
$query2 = $database->query($sql);
|
| 56 |
182
|
ryan
|
// Start creating sql-backup
|
| 57 |
190
|
ryan
|
$sql_backup ="\r\n# Create table ".$row['Name']."\r\n\r\n";
|
| 58 |
|
|
$out = $query2->fetchRow();
|
| 59 |
|
|
$sql_backup.=$out['Create Table'].";\r\n\r\n";
|
| 60 |
|
|
$sql_backup.="# Dump data for ".$row['Name']."\r\n\r\n";
|
| 61 |
|
|
// Select everything
|
| 62 |
|
|
$out = $database->query('SELECT * FROM '.$row['Name']);
|
| 63 |
182
|
ryan
|
$sql_code = '';
|
| 64 |
190
|
ryan
|
// Loop through all collumns
|
| 65 |
|
|
while($code = $out->fetchRow()) {
|
| 66 |
|
|
$sql_code .= "INSERT INTO ".$row['Name']." SET ";
|
| 67 |
182
|
ryan
|
$numeral = 0;
|
| 68 |
190
|
ryan
|
foreach($code as $insert => $value) {
|
| 69 |
|
|
// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't?
|
| 70 |
182
|
ryan
|
if($numeral==1) {
|
| 71 |
190
|
ryan
|
$sql_code.=$insert ."='".addslashes($value)."',";
|
| 72 |
182
|
ryan
|
}
|
| 73 |
|
|
$numeral = 1 - $numeral;
|
| 74 |
|
|
}
|
| 75 |
|
|
$sql_code = substr($sql_code, 0, -1);
|
| 76 |
|
|
$sql_code.= ";\r\n";
|
| 77 |
|
|
}
|
| 78 |
190
|
ryan
|
$output .= $sql_backup.$sql_code;
|
| 79 |
182
|
ryan
|
}
|
| 80 |
|
|
|
| 81 |
|
|
// Output file
|
| 82 |
191
|
ryan
|
header('Content-Type: text/html');
|
| 83 |
|
|
header('Content-Disposition: attachment; filename='.$filename);
|
| 84 |
187
|
ryan
|
echo $output;
|
| 85 |
182
|
ryan
|
|
| 86 |
|
|
?>
|