Reputation:
I'm using this code to backup my mysql database, and it works fine for my purposes.This script save my backup as .sql file how can I zip that sql file.Here's the code
$username = "***";
$password = "***";
$hostname = "***";
$database = "***";
$username =escapeshellcmd($username);
$password =escapeshellcmd($password);
$hostname =escapeshellcmd($hostname);
$database =escapeshellcmd($database);
$backupFile=''.date("Y-m-d-H-i-s").$database.'.sql';
$command = "mysqldump -u$username -p$password -h$hostname $database > $backupFile";
system($command, $result);
echo $result;
Upvotes: 0
Views: 2288
Reputation: 1
Just change
`$backupFile=''.date("Y-m-d-H-i-s").$database.'.sql';`
to
`$backupFile=''.date("Y-m-d-H-i-s").$database.'.zip';`
or to any other zip file type. It is a shell command and can save in many different compressed formats.
Upvotes: 0
Reputation: 19736
For a pure PHP solution, I believe this should do it: (from http://www.php.net/manual/en/ziparchive.addfile.php
$z = new ZipArchive();
$z->open("sqldump.zip", ZIPARCHIVE::CREATE);
$z->addFile($backupFile);
$z->close();
Upvotes: 3
Reputation: 31723
Just pipe the output to gzip or similar
mysqldump -uroot | gzip > backupfile.zip
http://mediakey.dk/~cc/compressing-mysqldump-output-mysql-gzip-bzip2-and-lzma-7z/
Upvotes: 4