Jump to content


This topic is now archived and is closed to further replies.


passthru, system or exec? for mysqlhotcopy or mysqldump

Recommended Posts



I\'m trying to execute a mysqlhotcopy or mysqldump from a php backup script that i\'m trying to put toghether...


Rather than complicating things as i\'m struggling with this, i have simplified the one command that i am trying to perform :-




passthru(\"mysqlhotcopy -u user -p password -s localhost:/var/run/mysqld/mysqld.sock mydatabase /home/matd/public_html/mysite/backup\");




This does nothing at all, so what i\'d like to know is how do i run commands like mysqldump or msqlhotcopy from a php script. I have tried system and exec instead of passthru but none of them work. The user, password and socket are all correctly set in my script as i use those successfully in other scripts for database queries and updates.


I just don\'t understand how to run more powerfull queries like those needed to back a mysql database up. Do i need to connect to the database first or does a passthru command just run by itself.


Would you expect passthru(\"mysqlhotcopy -u user -p password -s localhost:/var/run/mysqld/mysqld.sock reepower /home/matd/public_html/mysite/backup\"); to do exactly that or have i missed somthing out?


Please help, i really need to get a backup working for my site and yes i have seen http://www.phpfreaks.com/script/view/11.php but if i can\'t get any passthru, system or exec commands to run then i\'m stuck.. :roll:

Share this post

Link to post
Share on other sites

the system or exec should work... what errors do they return?

Share this post

Link to post
Share on other sites

Hi effigy :-)


I don\'t get any errors and the system, exec or passthru don\'t seem to execute any of the commands i try and run...


What is the difference between using passthru, exec and system and which of them should be used when trying to do a mysqldump or mysqlhotcopy?


By the way, i can do a simple command like system(\'ls\'); and that retuns a dir listing but i just can\'t get a dump or hotcopy to work..


This is the script i am trying to run which will prompt the user to save a gzip backup of the database :-






$export_filename = \"backup.gz\";


$export_dir = \"/home/matd/public_html/admin/backup\";


$filename = \"$export_dir/$export_filename\";


$passthru_output = system(\"mysqldump --opt -h$server -u$user -p$password $database | gzip >$filename\");


$mime_type = \'application/x-gzip\';


$now = gmdate(\'D, d M Y H:i:s\') . \' GMT\';


// finally send the headers and the file

header(\'Content-Type: \' . $mime_type);

header(\'Expires: \' . $now);


header(\'Content-Disposition: inline; filename=\"\'. $export_filename . \'\"\');


header(\'Cache-Control: must-revalidate, post-check=0, pre-check=0\');

header(\'Pragma: public\');


$dump_buffer = ($filename);


echo $dump_buffer;




I get prompted to save the right file and file type but its always empty :-(

Share this post

Link to post
Share on other sites

from php.net, although very basic:


exec -- Execute an external program

passthru --  Execute an external program and display raw output  

system -- Execute an external program and display output


your line to run the code looks fine... my thought is that you do not have the permissions to run mysqldump. run an ls -l and find out the file permissions, owner, and group. do the same for the web server. you could also try specifying the full path to mysqldump.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.