Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Script for mysql backup

Status
Not open for further replies.

lexer

Programmer
Jun 13, 2006
432
VE
Hi

I've a php script for making a mysql db backup, I can browse a folder where to save the backup (it works), I want to change the code for saving the backup on a webserver folder example:

c:\backup

This is my code:
Code:
<?php
//Current Date
$date_month = date('m');
$date_year = date('Y');
$date_day = date('d');
$Date = "$date_year-$date_month-$date_day";

//File Name
$filename = "mydb_$Date.sql";

//My DB
$user = "root";
$passwd = "xpass";
$db = "users";

header("Pragma: no-cache");
header("Expires: 0");
header("Content-Transfer-Encoding: binary");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=$filename");


//Make the backup
$execute = "c:\wamp\bin\mysql\mysql5.0.51a\bin\mysqldump.exe -u $user --password=$passwd --opt $db";
system($execute, $result);

if ($result) { echo "<H1>Error on: $execute</H1>\n"; }

?>

Any Ideas?

Thanks!!!
 
something like this?
Code:
$execute = "c:\wamp\bin\mysql\mysql5.0.51a\bin\mysqldump.exe -u $user --password=$passwd --opt $db [red]c:\mydatabase.db[/red]";
system($execute, $result);

make sure that the relevant directory is writable by the php process
 
Thanks jpadie

The below code works fine:
Code:
<?php
//Current Date
$date_month = date('m');
$date_year = date('Y');
$date_day = date('d');
$Date = "$date_year-$date_month-$date_day";

//My BD
$user = "root";
$passwd = "mysq1";
$bd = "users";

//Make the backup
$execute = "c:\wamp\bin\mysql\mysql5.0.51a\bin\mysqldump.exe -u $user --password=$passwd --opt $bd > c:\backup\mydb_$Date.sql.sql";
system($execute, $result);



if ($result) { 
echo "<H1>Error on: $execute</H1>\n"; }
else { 
echo "Backup Ready: ". $Date; }

?>

 
Hi

lexer said:
Code:
$date_month = date('m');
$date_year = date('Y');
$date_day = date('d');
$Date = "$date_year-$date_month-$date_day";
Why not just one [tt]date()[/tt] call ?
Code:
[navy]$Date[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]date[/color][teal]([/teal][green][i]'Y-m-d'[/i][/green][teal]);[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top