Jump to content


Photo

passthru, system or exec? for mysqlhotcopy or mysqldump


  • Please log in to reply
3 replies to this topic

#1 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 28 April 2003 - 01:31 PM

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...ipt/view/11.php but if i can\'t get any passthru, system or exec commands to run then i\'m stuck.. :roll:

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 28 April 2003 - 04:09 PM

the system or exec should work... what errors do they return?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 28 April 2003 - 04:17 PM

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 :-(

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 29 April 2003 - 11:10 PM

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.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users