Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Mar 31, 2005 8:05 am
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);
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Thu Mar 31, 2005 8:13 am
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...
Seriously now, does the command you are exec'ing runs properly when you run it via cmdline...
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Mar 31, 2005 8:26 am
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.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Thu Mar 31, 2005 8:37 am
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.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Mar 31, 2005 8:39 am
yeah, thats why I put the is_file() function in there. I'll mess around with it more.
thanks.
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Thu Mar 31, 2005 9:48 am
question (cuz i'm confused
), but are you trying to copy that file to a new directory or restore it back into mysql?...
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Mar 31, 2005 9:49 am
I'm trying to restore the database.
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Thu Mar 31, 2005 10:02 am
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.