Create backup gzip

Hello,

Have no problem with without a backup GZip

Problem creating GZip
The problem here:
[php]
//------ backup file name --------------//
if($_POST[‘gzip’]==‘1’){
$handle = fopen($datetime . ‘.sql.gz’, ‘a’);
}elseif($_POST[‘gzip’]==‘0’){
$handle = fopen($datetime . ‘.sql’, ‘a’);
}
//------ backup file name --------------//
[/php]
AND
[php]
//------ backup file name --------------//
if($_POST[‘gzip’]==‘1’){
$gzdata = gzencode($return, 9);
fwrite($handle, $gzdata);
}elseif($_POST[‘gzip’]==‘0’){
fwrite($handle, $return);
}
unset($return);
//------ backup file name --------------//
[/php]
What is wrong here?
Can you help?

All codes
[php]

<?php include('./includes/config.php'); // BASE TABLE SAVE //get all of the tables $datetime = date('d-m-Y-H-i'); $tables = '*'; $return=null; if($tables == '*'){ $tables = array(); $result = $mysqlibag->query("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"); while($row = $result->fetch_row()){ $tables[] = $row[0]; } }else{ $tables = is_array($tables) ? $tables : explode(',',$tables); } foreach ($tables as $table) { $result = $mysqlibag->query('SELECT * FROM ' . $table); $num_fields = $result->field_count; $return .= 'DROP TABLE IF EXISTS ' . $table . ';'; $row2 = $mysqlibag->query('SHOW CREATE TABLE ' . $table)->fetch_row(); $return .= "\n" . $row2[1] . ";\n"; //------ backup file name --------------// if($_POST['gzip']=='1'){ $handle = fopen($datetime . '.sql.gz', 'a'); }elseif($_POST['gzip']=='0'){ $handle = fopen($datetime . '.sql', 'a'); } //------ backup file name --------------// for ($i = 0; $i < $num_fields; $i++) { @set_time_limit(0); while ($row = $result->fetch_row()) { $return .= 'INSERT INTO `' . trim($table) . '` VALUES('; for ($j = 0; $j < $num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = preg_replace("/\r\n/", "\\r\\n", $row[$j]); if (isset($row[$j])) { $return .= "'" . $row[$j] . "'"; } else { $return .= "''"; } if ($j < ($num_fields - 1)) { $return .= ','; } } $return .= ");\n"; //------ backup file name --------------// if($_POST['gzip']=='1'){ $gzdata = gzencode($return, 9); fwrite($handle, $gzdata); }elseif($_POST['gzip']=='0'){ fwrite($handle, $return); } unset($return); //------ backup file name --------------// } } fclose($handle); }//foreach ($tables as $table) { $mysqlibag->close(); if($handle !=""){ echo 'Backup Completed Successfully.'; }else{ echo 'Backup Error Occurred.'; } return $handle; ?>

[/php]

Thanks in advance

Try using gzopen, gzwrite, and gzclose.

http://php.net/manual/en/function.gzopen.php
http://us2.php.net/manual/en/function.gzwrite.php
http://us2.php.net/manual/en/function.gzclose.php

Thank you for your answer, but I could not, Could you be a little more help?

You should be a little more spesific, why could you not? I assume you get some errors, you should post them with the code you’re working with.

GZip yes, but no compression

Example:
21-10-2013-01-16-searchcore.sql 9.063KB
21-10-2013-01-16-searchcore.sql.gz 9.354KB

See: http://n1310.hizliresim.com/1g/p/tsmhv.png

Sponsor our Newsletter | Privacy Policy | Terms of Service