1 |
182
|
ryan
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
399
|
Ruebenwurz
|
Copyright (C) 2004-2007, Ryan Djurovich
|
9 |
182
|
ryan
|
|
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 |
286
|
stefan
|
if(!isset($_POST['backup'])){
|
31 |
|
|
header('Location: ../');
|
32 |
|
|
exit(0);
|
33 |
331
|
stefan
|
}
|
34 |
|
|
|
35 |
187
|
ryan
|
// Include config
|
36 |
|
|
require_once('../../config.php');
|
37 |
182
|
ryan
|
|
38 |
187
|
ryan
|
// Create new admin object
|
39 |
|
|
require(WB_PATH.'/framework/class.admin.php');
|
40 |
|
|
$admin = new admin('Settings', 'settings_advanced', false);
|
41 |
|
|
|
42 |
|
|
// Begin output var
|
43 |
189
|
ryan
|
$output = "".
|
44 |
188
|
ryan
|
"#\n".
|
45 |
189
|
ryan
|
"# Website Baker ".WB_VERSION." Database Backup\n".
|
46 |
|
|
"# ".WB_URL."\n".
|
47 |
191
|
ryan
|
"# ".gmdate(DATE_FORMAT, mktime()+TIMEZONE).", ".gmdate(TIME_FORMAT, mktime()+TIMEZONE)."\n".
|
48 |
187
|
ryan
|
"#".
|
49 |
|
|
"\n";
|
50 |
|
|
|
51 |
182
|
ryan
|
// Get table names
|
52 |
331
|
stefan
|
// Use this one for ALL tables in DB
|
53 |
|
|
$query = "SHOW TABLES";
|
54 |
182
|
ryan
|
|
55 |
331
|
stefan
|
if ($_POST['tables']=='WB') {
|
56 |
|
|
// Or use this to get ONLY wb tables
|
57 |
|
|
$prefix=str_replace('_','\_',TABLE_PREFIX);
|
58 |
|
|
$query = "SHOW TABLES LIKE '".$prefix."%'";
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
$result = $database->query($query);
|
62 |
|
|
|
63 |
182
|
ryan
|
// Loop through tables
|
64 |
190
|
ryan
|
while($row = $result->fetchRow()) {
|
65 |
|
|
//show sql query to rebuild the query
|
66 |
326
|
stefan
|
$sql = 'SHOW CREATE TABLE '.$row[0].'';
|
67 |
190
|
ryan
|
$query2 = $database->query($sql);
|
68 |
182
|
ryan
|
// Start creating sql-backup
|
69 |
326
|
stefan
|
$sql_backup ="\r\n# Create table ".$row[0]."\r\n\r\n";
|
70 |
190
|
ryan
|
$out = $query2->fetchRow();
|
71 |
|
|
$sql_backup.=$out['Create Table'].";\r\n\r\n";
|
72 |
326
|
stefan
|
$sql_backup.="# Dump data for ".$row[0]."\r\n\r\n";
|
73 |
190
|
ryan
|
// Select everything
|
74 |
326
|
stefan
|
$out = $database->query('SELECT * FROM '.$row[0]);
|
75 |
182
|
ryan
|
$sql_code = '';
|
76 |
190
|
ryan
|
// Loop through all collumns
|
77 |
|
|
while($code = $out->fetchRow()) {
|
78 |
326
|
stefan
|
$sql_code .= "INSERT INTO ".$row[0]." SET ";
|
79 |
182
|
ryan
|
$numeral = 0;
|
80 |
190
|
ryan
|
foreach($code as $insert => $value) {
|
81 |
|
|
// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't?
|
82 |
182
|
ryan
|
if($numeral==1) {
|
83 |
190
|
ryan
|
$sql_code.=$insert ."='".addslashes($value)."',";
|
84 |
182
|
ryan
|
}
|
85 |
|
|
$numeral = 1 - $numeral;
|
86 |
|
|
}
|
87 |
|
|
$sql_code = substr($sql_code, 0, -1);
|
88 |
|
|
$sql_code.= ";\r\n";
|
89 |
|
|
}
|
90 |
190
|
ryan
|
$output .= $sql_backup.$sql_code;
|
91 |
182
|
ryan
|
}
|
92 |
|
|
|
93 |
|
|
// Output file
|
94 |
191
|
ryan
|
header('Content-Type: text/html');
|
95 |
|
|
header('Content-Disposition: attachment; filename='.$filename);
|
96 |
187
|
ryan
|
echo $output;
|
97 |
182
|
ryan
|
|
98 |
|
|
?>
|