Mysql restore php commands

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Jzocco
Forum Newbie
Posts: 4
Joined: Mon Jun 13, 2005 11:35 am

Mysql restore php commands

Post by Jzocco »

Okay i think i have a script thats supposed to run a mysql restore command in shell but it doesn't work i wanted it to be able to pick the file run gzip on it then run the mysql restore command in shell but it wont work

Heres my script

<HTML>
<TITLE>Mysql Restore</TITLE>
<CENTER><B><FONT SIZE=32>Mysql Restore</FONT></B></CENTER>

<CENTER><FORM METHOD=post ACTION="">
<INPUT type="file" name="filename">
</FORM></CENTER>

<?php
$backupFile = filename
$command = "mysql -user -password database | gzip > $backupFile";
system($command);
?>
</HTML>

Thats the entire script if some one could possibly tell me what im doning wrong, or maybe fix the script for me i would be ever so greatful

Thanks!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Always put your code in php blocks - it makes it much easier to read:

Code: Select all

&lt;HTML&gt;
&lt;TITLE&gt;Mysql Restore&lt;/TITLE&gt;
&lt;CENTER&gt;&lt;B&gt;&lt;FONT SIZE=32&gt;Mysql Restore&lt;/FONT&gt;&lt;/B&gt;&lt;/CENTER&gt;

&lt;CENTER&gt;&lt;FORM METHOD=post ACTION=&quote;&quote;&gt;
&lt;INPUT type=&quote;file&quote; name=&quote;filename&quote;&gt;
&lt;/FORM&gt;&lt;/CENTER&gt;

&lt;?php
$backupFile = filename
$command = &quote;mysql -user -password database | gzip &gt; $backupFile&quote;;
system($command);
?&gt;
&lt;/HTML&gt;
- Line 10 needs quotes and a ;
- I think your shell command is wrong. 1st - is $backupFile gzipped? If so, I think you need to unzip it in a separate command. 2nd - the flags you send to mysql are wrong. You need to actually pass the username and password if you want to do it all in one line. 3rd - your bracket is wrong, it should be <, not >:

Code: Select all

gunzip $backupFile; mysql -u example_user -pexample_password example_database &lt; $backupFile_name_when_unzipped
There may be a way to put the gunzip command in with the mysql command, but I'm not sure - this should work nonetheless.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply