Skip to content

Commit a156ebd

Browse files
author
LWT Project
committed
Version 1.2.0 (23-Aug-11 13:56)
1 parent f415138 commit a156ebd

3 files changed

Lines changed: 19 additions & 13051 deletions

File tree

‎backup_restore.php‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
if (isset($_REQUEST['restore'])) {
2929
if ( isset($_FILES["thefile"]) && $_FILES["thefile"]["tmp_name"] != "" && $_FILES["thefile"]["error"] == 0 ) {
30-
$handle = fopen ($_FILES["thefile"]["tmp_name"], "r");
30+
$handle = gzopen ($_FILES["thefile"]["tmp_name"], "r");
3131
if ($handle === FALSE) {
3232
$message = "Error: Restore file could not be opened";
3333
} // $handle not OK
@@ -39,11 +39,11 @@
3939
$inserts = 0;
4040
$creates = 0;
4141
$start = 1;
42-
while (! feof($handle)) {
42+
while (! gzeof($handle)) {
4343
$sql_line = trim(
4444
str_replace("\r","",
4545
str_replace("\n","",
46-
fgets($handle, 99999))));
46+
gzgets($handle, 99999))));
4747
if ($sql_line != "") {
4848
if($start) {
4949
if (strpos($sql_line,"-- lwt-backup-") === false ) {
@@ -66,7 +66,7 @@
6666
}
6767
}
6868
} // while (! feof($handle))
69-
fclose ($handle);
69+
gzclose ($handle);
7070
if ($errors == 0) {
7171
optimizedb();
7272
$message = "Success: Database restored - " .
@@ -89,16 +89,14 @@
8989
$result = mysql_query('SHOW TABLES');
9090
while ($row = mysql_fetch_row($result))
9191
$tables[] = $row[0];
92-
$fname = "lwt-backup-" . date('Y-m-d-H-i-s') . ".sql";
93-
header('Content-type: text/plain; charset=utf-8');
94-
header("Content-disposition: attachment; filename=" . $fname);
95-
echo "-- " . $fname . "\n";
92+
$fname = "lwt-backup-" . date('Y-m-d-H-i-s') . ".sql.gz";
93+
$out = "-- " . $fname . "\n";
9694
foreach($tables as $table) { // foreach table
9795
$result = mysql_query('SELECT * FROM ' . $table);
9896
$num_fields = mysql_num_fields($result);
99-
echo "\nDROP TABLE IF EXISTS " . $table . ";\n";
97+
$out .= "\nDROP TABLE IF EXISTS " . $table . ";\n";
10098
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE ' . $table));
101-
echo str_replace("\n"," ",$row2[1]) . ";\n";
99+
$out .= str_replace("\n"," ",$row2[1]) . ";\n";
102100
while ($row = mysql_fetch_row($result)) { // foreach record
103101
$return = 'INSERT INTO ' . $table . ' VALUES(';
104102
for ($j=0; $j < $num_fields; $j++) { // foreach field
@@ -109,9 +107,12 @@
109107
}
110108
if ($j < ($num_fields-1)) $return .= ',';
111109
} // foreach field
112-
echo $return . ");\n";
110+
$out .= $return . ");\n";
113111
} // foreach record
114112
} // foreach table
113+
header('Content-type: application/x-gzip');
114+
header("Content-disposition: attachment; filename=" . $fname);
115+
echo gzencode($out,9);
115116
exit();
116117
}
117118

@@ -126,15 +127,15 @@
126127
<th class="th1 center">Backup</th>
127128
<td class="td1">
128129
<p class="smallgray2">
129-
The database <i><?php echo tohtml($dbname); ?></i> will be exported to an SQL file. Please keep this file in a safe place.<br />If necessary, you can recreate the database via the Restore function below.<br />Important: If the backup file is too large, the restore may not be possible (see limits below).</p>
130+
The database <i><?php echo tohtml($dbname); ?></i> will be exported to a gzipped SQL file. Please keep this file in a safe place.<br />If necessary, you can recreate the database via the Restore function below.<br />Important: If the backup file is too large, the restore may not be possible (see limits below).</p>
130131
<p class="right">&nbsp;<br /><input type="submit" name="backup" value="Download LWT Backup" /></p>
131132
</td>
132133
</tr>
133134
<tr>
134135
<th class="th1 center">Restore</th>
135136
<td class="td1">
136137
<p class="smallgray2">
137-
The database <i><?php echo tohtml($dbname); ?></i> will be replaced by the data in the specified backup file.<br /><b>Please be careful - the existent database will be overwritten!</b> <br />Important: If the backup file is too large, the restore may not be possible.<br />Upload limits (in bytes): <b>post_max_size = <?php echo ini_get('post_max_size'); ?> / upload_max_filesize = <?php echo ini_get('upload_max_filesize'); ?></b><br />
138+
The database <i><?php echo tohtml($dbname); ?></i> will be replaced by the data in the specified backup file<br />(gzipped or normal SQL file, created above).<br /><b>Please be careful - the existent database will be overwritten!</b> <br />Important: If the backup file is too large, the restore may not be possible.<br />Upload limits (in bytes): <b>post_max_size = <?php echo ini_get('post_max_size'); ?> / upload_max_filesize = <?php echo ini_get('upload_max_filesize'); ?></b><br />
138139
If needed, increase in "<?php echo tohtml(php_ini_loaded_file()); ?>" and restart server.</p>
139140
<p><input name="thefile" type="file" /></p>
140141
<p class="right">&nbsp;<br /><input type="submit" name="restore" value="Restore from LWT Backup" /></p>

‎install_demo.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
// RESTORE DEMO
2525

2626
if (isset($_REQUEST['install'])) {
27-
$file = getcwd() . '/install_demo_db.sql';
27+
$file = getcwd() . '/install_demo_db.sql.gz';
2828
if ( file_exists($file) ) {
29-
$handle = fopen ($file, "r");
29+
$handle = gzopen ($file, "r");
3030
if ($handle === FALSE) {
3131
$message = "Error: File ' . $file . ' could not be opened";
3232
} // $handle not OK
@@ -38,11 +38,11 @@
3838
$inserts = 0;
3939
$creates = 0;
4040
$start = 1;
41-
while (! feof($handle)) {
41+
while (! gzeof($handle)) {
4242
$sql_line = trim(
4343
str_replace("\r","",
4444
str_replace("\n","",
45-
fgets($handle, 99999))));
45+
gzgets($handle, 99999))));
4646
if ($sql_line != "") {
4747
if($start) {
4848
if (strpos($sql_line,"-- lwt-backup-") === false ) {
@@ -65,7 +65,7 @@
6565
}
6666
}
6767
} // while (! feof($handle))
68-
fclose ($handle);
68+
gzclose ($handle);
6969
if ($errors == 0) {
7070
optimizedb();
7171
$message = "Success: Demo Database restored - " .

0 commit comments

Comments
 (0)