Page 1 of 1

Restoring a mysqldump

Posted: Thu Mar 31, 2005 8:05 am
by hawleyjr
I'm using the following code to backup my db: (works fine)

Code: Select all

$_dir = dirname($_SERVER['DOCUMENT_ROOT']).'/dbbkup/';

exec('mysqldump --add-drop-table --all --complete-insert -h localhost -u USER_NAME -pPASSWORD DATABASE_NAME > ' . $_dir . date('Y_m_d_His').'.sql');

I'm not trying to restore the db using: (not working properly)

Code: Select all

$fileName = '2005_03_30_135901.sql';

$fileName = dirname($_SERVER['DOCUMENT_ROOT']) . '/dbbkup/'.$fileName;

if(is_file($fileName))/* validate correct file */
	echo 'is a file<BR>'.$fileName;
else
	echo 'is not a file<BR>'.$fileName;
	
	exec('mysql -h localhost -u USER_NAME -pPASSWORD -D DATABASE_NAME < ' . $fileName);

Posted: Thu Mar 31, 2005 8:13 am
by n00b Saibot
hawleyjr wrote:I'm not trying to restore the db using: (not working properly)
If you aren't trying, then why is it giving error... :lol:

Seriously now, does the command you are exec'ing runs properly when you run it via cmdline...:?:

Posted: Thu Mar 31, 2005 8:26 am
by hawleyjr
n00b Saibot wrote:
hawleyjr wrote:I'm not trying to restore the db using: (not working properly)
If you aren't trying, then why is it giving error... :lol:
lol, that's awesome...

I don't have access to the cmdline. I'm pretty much shooting in the dark.

Posted: Thu Mar 31, 2005 8:37 am
by n00b Saibot
you sure the file is in correct path and that you have priviledges to run the mysql command because command looks pretty good to me. perplexing thing, this. :?

Posted: Thu Mar 31, 2005 8:39 am
by hawleyjr
yeah, thats why I put the is_file() function in there. I'll mess around with it more.

thanks.

Posted: Thu Mar 31, 2005 9:48 am
by infolock
question (cuz i'm confused :? ), but are you trying to copy that file to a new directory or restore it back into mysql?...

Posted: Thu Mar 31, 2005 9:49 am
by hawleyjr
I'm trying to restore the database.

Posted: Thu Mar 31, 2005 10:02 am
by infolock
then all ya need to do is :

Code: Select all

`mysql -u username -p password databasename < file.sql;
make sure you have created the database name beforehand though...and also make sure you have the sql file in the correct location. otherwise you are gonna have to define the actual directory in which it resides.