-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbackup.php
More file actions
executable file
·198 lines (191 loc) · 5.46 KB
/
Copy pathbackup.php
File metadata and controls
executable file
·198 lines (191 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
include_once(__DIR__ . "/include/headers.php");
include __DIR__ . "/dbinfo.php";
extract($_POST);
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
flush();
?>
<table width="760" border="0" class="page" align="center">
<tr>
<td class="page" align="center">
<?php
require_once(__DIR__ . "/include/head.php");
if ($user_admin != 'y') {
echo sprintf('<h1>%s</h1>', $lang_admin_droit);
include_once(__DIR__ . "/include/bas.php");
exit;
}
# Table backup from MySql PHP Backup
$conn = @mysql_connect($dbhost,$dbuser,$dbpass);
if ($conn==false) {
die("password / user or database name wrong");
}
$x=$_SERVER['SERVER_SOFTWARE'];
$path = strpos($x,"Win32") != 0 ? $path . "dump\\" : $path . "dump/";
// If windows gives problems
// FOR WINDOWS change to ==> $path = $path . "dump\\";
if (!is_dir($path)) {
mkdir($path, 0766);
}
@chmod($path, 0777);
$fp2 = fopen ($path."backup.sql","w");
$copyr=sprintf('# Backup de %s', $lang_factux).'
# Table backup from MySql PHP Backup (AB Webservices 1999-2004 www.absoft-my.com/pondok)
# Creation date: '.date('m-d-Y h:s',time()).PHP_EOL.PHP_EOL;
fwrite ($fp2,$copyr);
fclose ($fp2);
//chmod($path . "backup." . date('m-d-Y ') . ".sql", 0777);
if (file_exists($path . "backup.gz")) {
unlink($path."backup.gz");
}
$recreate = 0;
function get_def($dbname, string $table): string {
global $conn;
$def = "";
$def .= "DROP TABLE IF EXISTS {$table};#%%\n";
$def .= "CREATE TABLE {$table} (\n";
$result = mysql_db_query($dbname, 'SHOW FIELDS FROM ' . $table,$conn) or die(sprintf('Table %s not existing in database', $table));
while($row = mysql_fetch_array($result)) {
$def .= sprintf(' %s %s', $row["Field"], $row["Type"]);
if ($row["Default"] !== null) {
// Fix 2025
$def .= sprintf(" DEFAULT '%s'", $row["Default"]);
}
if ($row["Null"] != "YES") {
$def .= " NOT NULL";
}
if ($row["Extra"] != "") {
$def .= ' ' . $row["Extra"];
}
$def .= ",\n";
}
$def = preg_replace("~,\n$~","", $def);#deprecated ereg_replace(",\n$","", $def);
$result = mysql_db_query($dbname, 'SHOW KEYS FROM ' . $table,$conn);
while($row = mysql_fetch_array($result)) {
$kname=$row['Key_name'];
if (($kname != "PRIMARY") && ($row['Non_unique'] == 0)) {
$kname='UNIQUE|' . $kname;
}
if (!isset($index[$kname])) {
$index[$kname] = [];
}
$index[$kname][] = $row['Column_name'];
}
foreach($index as $x => $columns){
$def .= ",\n";
if ($x == "PRIMARY") {
$def .= " PRIMARY KEY (" . implode(", ", $columns) . ")";
} elseif (substr($x,0,6) == "UNIQUE") {
$def .= " UNIQUE ".substr($x,7)." (" . implode(", ", $columns) . ")";
} else {
$def .= sprintf(' KEY %s (', $x) . implode(", ", $columns) . ")";
}
}
$def .= "\n);#%%";
return (stripslashes($def));
}
function get_content($dbname, string $table): string {
global $conn;
$content="";
$result = mysql_db_query($dbname, 'SELECT * FROM ' . $table,$conn);
while($row = mysql_fetch_row($result)) {
$insert = sprintf('INSERT INTO %s VALUES (', $table);
for($j=0; $j<mysql_num_fields($result);$j++) {
if (!isset($row[$j])) {
$insert .= "NULL,";
} elseif ($row[$j] != "") {
$insert .= "'".addslashes($row[$j])."',";
} else {
$insert .= "'',";
}
}
$insert = preg_replace("~,$~","",$insert);#deprecated ereg_replace(",$","",$insert);
$insert .= ");#%%\n";
$content .= $insert;
}
return $content;
}
$filetype = "sql";
$newfile ='';
if (!preg_match("~/restore\.~",$_SERVER['PHP_SELF'])) {#deprecated (!eregi("/restore\.",$_SERVER['PHP_SELF'])) {
$cur_time=date("Y-m-d H:i");
if ($table_names == "*" ) {
$tables = mysql_list_tables($dbname,$conn);
$num_tables = @mysql_num_rows($tables);
$i = 0;
while($i < $num_tables) {
$table = mysql_tablename($tables, $i);
$table = ltrim($table);
$newfile .= get_def($dbname,$table);
$newfile .= "\n\n";
$newfile .= get_content($dbname,$table);
$newfile .= "\n\n";
$i++;
}
} else {
$i=0;
$tables=explode(";",$table_names);
if (count($tables) != 0) {
while($i < count($tables)) {
$newfile .= get_def($dbname,ltrim($tables[$i]));
$newfile .= "\n\n";
$newfile .= get_content($dbname,ltrim($tables[$i]));
$newfile .= "\n\n";
$i++;
}
}
}
$fp = fopen ($path.('backup.' . $filetype),"a");
fwrite ($fp,$newfile);
fwrite ($fp,"# Valid end of backup For Factux from MySql PHP Backup\n");
fclose ($fp);
}
?>
<center>
<table class="page" width="80%">
<caption><?php echo $lang_back_titr; ?></caption>
<tr>
<td class="texte0" height="215" valign="top">
<p><?php echo $lang_back_ok; ?><img alt="<?php echo $lang_oui; ?>" src="image/oui.gif"></p>
<br />
<?php
echo $lang_back_lon . '<br />';
$count = $_POST['table_names'] == "*" ? $num_tables : count($tables);
if ($count != 0 ) {
$i=0;
while ($i < $count) {
if ($_POST['table_names'] == "*") {
echo " ++ <b>".mysql_tablename($tables, $i)."</b><br />";
} else {
echo " ++ <b>".$tables[$i]."</b><br />";
}
$i++;
}
} else {
echo sprintf("<font color='red'>%s</font><br>", $lang_back_err);
}
echo $lang_back_lon2;
?>
</td>
</tr>
<tr>
<td class="c texte0" height="27" >
<b><a href="main.php"><br><?php echo $lang_back_ret; ?></a></b>
</td>
</tr>
</table>
</center>
</td>
</tr>
<tr>
<td>
<?php
$aide='backups';
include(__DIR__ . "/help.php");
include_once(__DIR__ . "/include/bas.php");
?>
</td>
</tr>
</table>
</body>
</html>