|
27 | 27 |
|
28 | 28 | if (isset($_REQUEST['restore'])) { |
29 | 29 | 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"); |
31 | 31 | if ($handle === FALSE) { |
32 | 32 | $message = "Error: Restore file could not be opened"; |
33 | 33 | } // $handle not OK |
|
39 | 39 | $inserts = 0; |
40 | 40 | $creates = 0; |
41 | 41 | $start = 1; |
42 | | - while (! feof($handle)) { |
| 42 | + while (! gzeof($handle)) { |
43 | 43 | $sql_line = trim( |
44 | 44 | str_replace("\r","", |
45 | 45 | str_replace("\n","", |
46 | | - fgets($handle, 99999)))); |
| 46 | + gzgets($handle, 99999)))); |
47 | 47 | if ($sql_line != "") { |
48 | 48 | if($start) { |
49 | 49 | if (strpos($sql_line,"-- lwt-backup-") === false ) { |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } // while (! feof($handle)) |
69 | | - fclose ($handle); |
| 69 | + gzclose ($handle); |
70 | 70 | if ($errors == 0) { |
71 | 71 | optimizedb(); |
72 | 72 | $message = "Success: Database restored - " . |
|
89 | 89 | $result = mysql_query('SHOW TABLES'); |
90 | 90 | while ($row = mysql_fetch_row($result)) |
91 | 91 | $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"; |
96 | 94 | foreach($tables as $table) { // foreach table |
97 | 95 | $result = mysql_query('SELECT * FROM ' . $table); |
98 | 96 | $num_fields = mysql_num_fields($result); |
99 | | - echo "\nDROP TABLE IF EXISTS " . $table . ";\n"; |
| 97 | + $out .= "\nDROP TABLE IF EXISTS " . $table . ";\n"; |
100 | 98 | $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"; |
102 | 100 | while ($row = mysql_fetch_row($result)) { // foreach record |
103 | 101 | $return = 'INSERT INTO ' . $table . ' VALUES('; |
104 | 102 | for ($j=0; $j < $num_fields; $j++) { // foreach field |
|
109 | 107 | } |
110 | 108 | if ($j < ($num_fields-1)) $return .= ','; |
111 | 109 | } // foreach field |
112 | | - echo $return . ");\n"; |
| 110 | + $out .= $return . ");\n"; |
113 | 111 | } // foreach record |
114 | 112 | } // foreach table |
| 113 | + header('Content-type: application/x-gzip'); |
| 114 | + header("Content-disposition: attachment; filename=" . $fname); |
| 115 | + echo gzencode($out,9); |
115 | 116 | exit(); |
116 | 117 | } |
117 | 118 |
|
|
126 | 127 | <th class="th1 center">Backup</th> |
127 | 128 | <td class="td1"> |
128 | 129 | <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> |
130 | 131 | <p class="right"> <br /><input type="submit" name="backup" value="Download LWT Backup" /></p> |
131 | 132 | </td> |
132 | 133 | </tr> |
133 | 134 | <tr> |
134 | 135 | <th class="th1 center">Restore</th> |
135 | 136 | <td class="td1"> |
136 | 137 | <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 /> |
138 | 139 | If needed, increase in "<?php echo tohtml(php_ini_loaded_file()); ?>" and restart server.</p> |
139 | 140 | <p><input name="thefile" type="file" /></p> |
140 | 141 | <p class="right"> <br /><input type="submit" name="restore" value="Restore from LWT Backup" /></p> |
|
0 commit comments