Softaculous


Topic : Mysql Dump/backUP


1

Posted By: Nube on January 23, 2012, 9:34 pm
Hi :-)

I need your help once again.. i try to backup my db using a php script but always get an error..

here the code i use:

PHP Code

<?php

include ("../../t6/include/connect.php");

$backupFile '../../t6/backup/' $db date("Y-m-d-H-i-s") . '.sql';
$command "mysqldump -h $host -u $user -p$password $db > $backupFile";
system($command$retval);
if (
$retval==0)
{
 echo 
"BackUP Done!";
}
else
{
 echo 
"BackUP Failed!";
}
?>



i always get "1" as value into $retval.. what's wrong with my code?

thanks for the help :)

Posted By: tidus on January 24, 2012, 6:08 am | Post: 1
Quote From : Nube January 23, 2012, 9:34 pm
Hi :-)

I need your help once again.. i try to backup my db using a php script but always get an error..

here the code i use:

PHP Code

<?php

include ("../../t6/include/connect.php");

$backupFile '../../t6/backup/' $db date("Y-m-d-H-i-s") . '.sql';
$command "mysqldump -h $host -u $user -p$password $db > $backupFile";
system($command$retval);
if (
$retval==0)
{
 echo 
"BackUP Done!";
}
else
{
 echo 
"BackUP Failed!";
}
?>



i always get "1" as value into $retval.. what's wrong with my code?

thanks for the help :)


Hi,

If you are trying to take Backup of scripts installed by Softaculous, why don't you use Softaculous Backup Feature.

http://ampps.com/wiki/How_to_Backup_an_Installation


-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on January 24, 2012, 12:38 pm | Post: 2
what i am trying to do with that code is to backup a db that i created.. but i don't know why it always return me "BackuP Failed"

Posted By: tidus on January 24, 2012, 12:45 pm | Post: 3
Quote From : Nube January 24, 2012, 12:38 pm
what i am trying to do with that code is to backup a db that i created.. but i don't know why it always return me "BackuP Failed"


Hi,

Create a temp.bat file and insert your mysql dump command into it. Then run that batch file with exec command of PHP.


-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on January 24, 2012, 1:10 pm | Post: 4
ok, so i have to copy my php code into a text file and rename the file as a "bat file" and then run the bat file from a php file using the comand exec? i understand well??

Posted By: tidus on January 24, 2012, 1:35 pm | Post: 5
Quote From : Nube January 24, 2012, 1:10 pm
ok, so i have to copy my php code into a text file and rename the file as a "bat file" and then run the bat file from a php file using the comand exec? i understand well??


No, you got it wrong. Create a file temp.bat from PHP with fopen function and insert your mysql dump command with fwrite function. Then run that created temp.bat file with exec function of php. All your php code will be in your script and not in bat file.


-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on January 28, 2012, 6:22 pm | Post: 6
hi :)

sorry for my late reply.. i edited my code in this way but still it doesn't work..

PHP Code

<?php <?php

include ("../../t6/include/connect.php");

$backupFile '../../t6/backup/' $db date("Y-m-d-H-i-s") . '.sql';
$command "mysqldump -h $host -u $user -p$password $db > $backupFile";
$file fopen("../../t6/backup/temp.php""w+");
fwrite($file,$command);
fclose($file);
exec("$file"); 




Posted By: Nube on January 28, 2012, 6:25 pm | Post: 7
sorry for reposting the message but i do not how to edit e post.. any clue??

btw, the code is:

PHP Code

<?php

include ("../../t6/include/connect.php");

$backupFile '../../t6/backup/' $db date("Y-m-d-H-i-s") . '.sql';
$command "mysqldump -h $host -u $user -p$password $db > $backupFile";
$file fopen("../../t6/backup/temp.php""w+");
fwrite($file,$command);
fclose($file);
exec("$file");

?>




Posted By: Nube on January 28, 2012, 6:41 pm | Post: 8
sorry for the second time but the right code, the one that i used to try to dump my db is this one:

PHP Code

<?php

include ("../../t6/include/connect.php");

$backupFile '../../t6/backup/' $db date("Y-m-d-H-i-s") . '.sql';
$command "mysqldump -h $host -u $user -p$password $db > $backupFile";
$file fopen("../../t6/backup/temp.bat""w+");
fwrite($file,$command);
fclose($file);
exec("$file");

?>



Posted By: tidus on January 29, 2012, 3:08 pm | Post: 9
Hi,

$file is handler in your code. Use file path instead of handler.
$filepath = '../../t6/backup/temp.bat';
exec($filepath);


-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on January 29, 2012, 3:46 pm | Post: 10
sorry but i think to do not understand what you are telling me..

i modified the code in this way but i don't get the point..

PHP Code
pan style="color: #000000">
include ("../../t6/include/connect.php");

$backupFile = '../../t6/backup/' . $db . date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump -h $host -u $user -p$password $db > $backupFile";
$file = fopen('../../t6/backup/temp.bat', 'w+');
$filepath = '../../t6/backup/temp.bat';
fwrite($file,$command);
fclose($file);
exec($filepath);

?>


still it doesn't work..

Posted By: Nube on January 29, 2012, 3:47 pm | Post: 11
PHP Code

<?php

include ("../../t6/include/connect.php");

$backupFile '../../t6/backup/' $db date("Y-m-d-H-i-s") . '.sql';
$command "mysqldump -h $host -u $user -p$password $db > $backupFile";
$file fopen('../../t6/backup/temp.bat''w+');
$filepath '../../t6/backup/temp.bat';
fwrite($file,$command);
fclose($file);
exec($filepath);

?>


Posted By: tidus on February 2, 2012, 5:54 am | Post: 12
Hi,

I am afraid i won't be able to help you much with PHP code. You should take help from other PHP forums. If you need more information about AMPPS or if you're facing any problem with the AMPPS Package feel free to contact us.

temp.bat is actually a batch file which you are creating. Set of commands are executed. Learn more from Google. Executing the batch file with the proper command in it should work. Confirm that your command is correct by
Code
echo $command;



-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on February 2, 2012, 1:11 pm | Post: 13
Thanks for replying :-)

Browsing other forums i discovered that the problem could be the "shell path", indeed to use the mysql dump i cannot use it directly at the prompt but i have to browse the correct path to "bin/mysqldump".. maybe is this the problem?
Indeed a user told me that is it correct that the file will be created even if empty but the reason for the empty file could be the "shell path".. How can i fix the path? and how to solve this problem (shell path) also on MacOS X?

Hope you understand what i mean as my english is not so good.. :-)

Posted By: tidus on February 2, 2012, 1:42 pm | Post: 14
Hi,

I have written a code, this worked for me. exec function of php doesn't work for me too, it gives empty .sql file.

PHP Code

 $mydump '"C:/Ampps/mysql/bin/mysqldump.exe"';
$command $mydump.' -h '.$host.' -u '.$user.' -p"'.$pass.'" '.$db.' > "'.$file.'"';
$temp 'C:/Ampps/temp/t'.rand(1999).'.bat';
$fp fopen ($temp"w");
fwrite($fp$command);
fclose ($fp);
@
exec('"'.$temp.'"'$array$ret);
unlink($temp); 




-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on February 2, 2012, 5:21 pm | Post: 15
Hi :) thanks for the code but unfortunatly still it doesn't work.. i don't know why.. this time i can see the console opening and the dump on scrolling inside it but the file is still empty..

I modified the code a bit to make it works on my system, yours didn't (don't know why)

Now, everytime i run the backup files, windows opens a requester asking me for permission (in my system there an admin and a user).. I also tried to modified the property of the mysqldump.exe giving it the permission (run as administrator)..

Here my code:

PHP Code

<?php

$host
="localhost";
$user="root";
$password="root";
$db="trasporti";
$file='C:/Program Files/Ampps/www/t6/backup/';
$file.="dump.sql";

$db_connect=mysql_connect("$host""$user""$password");

mysql_select_db("$db");

$mydump '"C:/Program Files/Ampps/mysql/bin/mysqldump.exe"';
$command $mydump.' -h '.$host.' -u '.$user.' -p"'.$password.'" '.$db.' > "'.$file.'"';
$temp 'C:/Program Files/Ampps/temp/t'.rand(1999).'.bat';
$fp fopen ($temp"w+");
fwrite($fp$command);
fclose($fp);

@
exec('"'.$temp.'"'$array$ret);
unlink($temp); 

mysql_close($db_connect);

?>



I suspect there is something wrong in my apache/mysql setup or something that i am missing.. and also i think that the comand (mysqldump.exe) should be inserted into my shell path.. Do you know how to do this?

Thanks Davide,

Posted By: tidus on February 2, 2012, 6:40 pm | Post: 16
Since you are specifying the whole path, mysqldump.exe need not be in environment variable. If you still want it in environment then follow this link, add the directory path i.e path/to/Ampps/mysql/bin to PATH variable.

For XP : http://support.microsoft.com/kb/310519

For Windows 7 : http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

If you are using any other OS just search in google "set PATH environment variable in YOUR_OS_NAME",  you should be able to find easily.


-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on February 5, 2012, 4:45 pm | Post: 17
I still have the problem, btw i tried to use phpmyadmin and i was able to make a dump.. so what's the difference between using phpmyadmin and mysqldump directly??

Maybe i have to set some info into Apache or PHP ini file? i also noticed that you installed AMPPS in C:\ instead i Installed it in C:\Program Files\

maybe is this? or maybe the fact that i have an administrator and a user?..

I noticed that when i try to dump the database (from php or directly from the console) a console pops up showing all the data flowing inside (like if it was doing the dump) but then the file is still empty. If i did it from the console another console pops up, showing the data but no dump is done..

any ideas?, please help me.. i am going crazy..

Posted By: tidus on February 6, 2012, 6:30 am | Post: 18
>> I still have the problem, btw i tried to use phpmyadmin and i was able
to make a dump.. so what's the difference between using phpmyadmin and
mysqldump directly??

Nothing, both do the same work. phpMyAdmin is a UI for MySQL & mysqldump is used in command line.

>> Maybe i have to set some info into Apache or PHP ini file?

You can configure according to your need. Default setting, Development setting or Production setting. You should get help from other PHP forums for better knowledge.

>> i also noticed that you installed AMPPS in C:\ instead i Installed it in
C:\Program Files\ maybe is this? or maybe the fact that i have an administrator and a user?..

Path or Users won't matter here

>> I noticed that when i try to dump the database (from php or directly
from the console) a console pops up showing all the data flowing inside
(like if it was doing the dump) but then the file is still empty. If i
did it from the console another console pops up, showing the data but no
dump is done..

I tested it again with my php code & command line directly, it is working without any issues. Recheck your command. Try running the command directly from command prompt and not from a batch file. Refer MySQL documentation for more info.



-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: Nube on February 6, 2012, 9:06 pm | Post: 19
Hi :) finally i found the code that works for me! here it is:
PHP Code

<?php $command 'mysqldump -h localhost -u root -proot --database "trasporti" -r "C :P rogram FilesAmppswwwt6backupbackup.sql"';
system($command);?>

it seems that the -r is the key and also the add of --database

Posted By: tidus on February 7, 2012, 5:30 am | Post: 20
Good to know that the code is working.

Please let us know if you need further information regarding AMPPS.

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack

Posted By: raghubodi on February 8, 2012, 9:32 am | Post: 21
The mysqldump client is a backup program
        originally written by Igor Romanenko. It can be used to dump a
        database or a collection of databases for backup or transfer to
        another SQL server (not necessarily a MySQL server). The dump
        typically contains SQL statements to create the table, populate
        it, or both. However, mysqldump can also be
        used to generate files in CSV, other delimited text, or XML
        format.
     

-----------------------
website development services


Powered By AEF 1.0.8 © 2007-2008 Electron Inc.