Jump to content

passthru, system or exec? for mysqlhotcopy or mysqldump


Recommended Posts

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:

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.