Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         backup
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id: backup-sql.php 1289 2010-02-10 15:13:21Z kweitzel $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/trunk/wb/modules/backup/backup-sql.php $
15
 * @lastmodified    $Date: 2010-02-10 16:13:21 +0100 (Wed, 10 Feb 2010) $
16
 *
17
*/
18

    
19
// Filename to use
20
$filename = $_SERVER['HTTP_HOST'].'-backup-'.gmdate('Y-m-d', time()+TIMEZONE).'.sql';
21

    
22
// Check if user clicked on the backup button
23
if(!isset($_POST['backup'])){
24
	header('Location: ../');
25
	exit(0);
26
}
27

    
28
// Include config
29
require_once('../../config.php');
30

    
31
// Begin output var
32
$output = "".
33
"#\n".
34
"# Website Baker ".WB_VERSION." Database Backup\n".
35
"# ".WB_URL."\n".
36
"# ".gmdate(DATE_FORMAT, time()+TIMEZONE).", ".gmdate(TIME_FORMAT, time()+TIMEZONE)."\n".
37
"#".
38
"\n";
39

    
40
// Get table names
41
// Use this one for ALL tables in DB
42
$query  = "SHOW TABLES";
43

    
44
if ($_POST['tables']=='WB') {
45
	// Or use this to get ONLY wb tables
46
	$prefix=str_replace('_','\_',TABLE_PREFIX);
47
	$query = "SHOW TABLES LIKE '".$prefix."%'";
48
}
49

    
50
$result = $database->query($query);
51

    
52
// Loop through tables
53
while($row = $result->fetchRow()) {
54
	//show sql query to rebuild the query
55
	$sql = 'SHOW CREATE TABLE '.$row[0].''; 
56
	$query2 = $database->query($sql); 
57
	// Start creating sql-backup
58
	$sql_backup ="\r\n# Create table ".$row[0]."\r\n\r\n";
59
	$out = $query2->fetchRow();
60
	$sql_backup.=$out['Create Table'].";\r\n\r\n"; 
61
	$sql_backup.="# Dump data for ".$row[0]."\r\n\r\n";
62
	// Select everything
63
	$out = $database->query('SELECT * FROM '.$row[0]); 
64
	$sql_code = '';
65
	// Loop through all collumns
66
	while($code = $out->fetchRow()) { 
67
		$sql_code .= "INSERT INTO ".$row[0]." SET "; 
68
		$numeral = 0;
69
		foreach($code as $insert => $value) {
70
			// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't? 
71
			if($numeral==1) {
72
				$sql_code.=$insert ."='".addslashes($value)."',";
73
			}
74
			$numeral = 1 - $numeral;
75
		}
76
		$sql_code = substr($sql_code, 0, -1);
77
		$sql_code.= ";\r\n";
78
	}
79
	$output .= $sql_backup.$sql_code; 
80
}
81

    
82
// Output file
83
header('Content-Type: text/html');
84
header('Content-Disposition: attachment; filename='.$filename);
85
echo $output;
86

    
87
?>
(1-1/4)