matd Posted April 28, 2003 Share Posted April 28, 2003 Hi, 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: Quote Link to comment https://forums.phpfreaks.com/topic/409-passthru-system-or-exec-for-mysqlhotcopy-or-mysqldump/ Share on other sites More sharing options...
effigy Posted April 28, 2003 Share Posted April 28, 2003 the system or exec should work... what errors do they return? Quote Link to comment https://forums.phpfreaks.com/topic/409-passthru-system-or-exec-for-mysqlhotcopy-or-mysqldump/#findComment-1365 Share on other sites More sharing options...
matd Posted April 28, 2003 Author Share Posted April 28, 2003 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 :- <?php include(\"../../config/config_sql.php\"); $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 :-( Quote Link to comment https://forums.phpfreaks.com/topic/409-passthru-system-or-exec-for-mysqlhotcopy-or-mysqldump/#findComment-1367 Share on other sites More sharing options...
effigy Posted April 29, 2003 Share Posted April 29, 2003 from php.net, although very basic: exec -- Execute an external programpassthru -- 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. Quote Link to comment https://forums.phpfreaks.com/topic/409-passthru-system-or-exec-for-mysqlhotcopy-or-mysqldump/#findComment-1385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.