This Tutorial shows how to use gzip and mysqldump from php scripts. Note that there is no space between the -p and the password – for whatever stupid reason. To gzip your mysqldump, you may use the below command:
/opt/lampp/bin/mysqldump --opt -h $dbhost -u $dbuser -p$dbpass DatabaseName| gzip > $backupFile
Note the /opt/lampp/bin/mysqldump part, on some systems you might need the whole path, while on other systems it might be fine to just use mysqldump – its down to configuration of course – but never mind that now.
To use mysqldump without gzip, you can use the below command – note the mising | gzip after the DatabaseName.
/opt/lampp/bin/mysqldump --opt -h $dbhost -u $dbuser -p$dbpass DatabaseName > $backupFile
The full PHP code would be something similar to the below.
$dbhost = 'my.personalmysql.host'; $dbuser = 'username'; $dbpass = 'password'; $backupFile = 'DatabaseName.sql.gz'; exec("/opt/lampp/bin/mysqldump --opt -h $dbhost -u $dbuser -p$dbpass DatabaseName| gzip > $backupFile");