Mysql Dump - Database Backup

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
venkatgants
Forum Newbie
Posts: 3
Joined: Thu Jun 03, 2010 1:21 am

Mysql Dump - Database Backup

Post by venkatgants »

ahm i'm used this

$dump = "mysqldump-u$user-p$pass$dbname>db/backup.sql";

system($dump);

but when i open the backup.sql, its blank
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Mysql Dump - Database Backup

Post by requinix »

You did put spaces in there, right?

Try running that on the command line yourself and see if there are any error messages.
venkatgants
Forum Newbie
Posts: 3
Joined: Thu Jun 03, 2010 1:21 am

Re: Mysql Dump - Database Backup

Post by venkatgants »

Code: Select all

$backupFile =  "db/".date("Y-m-d-H-i-s")."."."sql";
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "pdmr_tracky";

echo $dump = "mysqldump --opt -h ".$dbhost." -u ". $dbuser." -p ". $dbpass. $dbname." > ".$backupFile; 
system($dump);

This is code. How to use in command prompt.
d:wamp this is wamp path...

pls help me...
Last edited by Benjamin on Thu Jun 03, 2010 2:23 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Mysql Dump - Database Backup

Post by requinix »

Like I said, try running that from the command line and see what happens.
venkatgants
Forum Newbie
Posts: 3
Joined: Thu Jun 03, 2010 1:21 am

Re: Mysql Dump - Database Backup

Post by venkatgants »

our wamp path is D:\wamp, we dont know how to enter query and where (path).
so that we included php code. please guide me.
kirank
Forum Newbie
Posts: 23
Joined: Thu Dec 03, 2009 2:19 am

Re: Mysql Dump - Database Backup

Post by kirank »

TRy this code

Create a folder named "backup" in current folder where this program runs and chmod to 777

Code: Select all

<?php


/*
 * -------------------------------------------------------------
 	Database backup script 
 * -------------------------------------------------------------
*/



set_time_limit(0);
/*
 * Directory name for storage
 * All back will store to backup folder in the current running folder
 
*/

$dirName	=	dirname(__FILE__)."";  

/*
 * Database configuration 
*/
$dbUser		=	"nroot";
$dbPass		=	"pass";
$dbName		=	"dbname";
$dbHost		=	"localhost";




/*
 * Executes the Mysqldump for backup 
*/

$fileName	=	strtotime(date("Y-m-d H:i:s"))."-{$dbName}-backup.sql";
$command	=	"mysqldump --opt --host={$dbHost} --user={$dbUser} --password={$dbPass} {$dbName} > {$dirName}/backup/{$fileName}";
$res = exec($command);

echo $command;
echo $res;

?>
this will
Last edited by Benjamin on Mon Jul 12, 2010 5:57 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
Post Reply