Webmastersite.net
Register Log In

HOW-TO : mySQL backup + safe_mode = on

Comments on HOW-TO : mySQL backup + safe_mode = on

zippo
Forum Regular

Usergroup: Customer
Joined: Jan 11, 2006

Total Topics: 48
Total Comments: 166
zippo
Posted Oct 04, 2006 - 2:17 PM:

If you're tired of going to phpMyAdmin to export your tables this might provide some help.

First this may be mildly pertainant to my setup:

FreeBSD 5.4
PHP 4.4.2
MySQL 4.1.14

..but will still be relevant to other flavors of *nix and perhaps windows.

While many people just turn off safe_mode it's a relinquishment of some security in favor of running a more exploitable environment. Mind you, there is no safe_mode in PHP 6 so this will have little if any usefulness there, unless the reconstructed exec() helps. wink

First of all with safe_mode = on the PHP exec() function will be limited to directories listed by the safe_mode_exec_dir variable. If you are able to have a user php.ini then you can possibly tweak this variable. There may be some default directories already set too.

If you can customize your httpd.conf file that is good too. It all boils down to how your hosting is setup and what you have access to. For someone with a VPS or dedicated server this will be a snap since you're able to get at all this stuff.

In any event it is neccessary to for the backup and restore features to access mysql and mysqldump so where those are needs to be listed in the safe_mode_exec_dir value.

My approach was to use the custom httpd.conf feature of my hosting control panel. You'll want to add something similar to: (the path to mysql & mysqldump)
php_admin_value safe_mode_exec_dir '/usr/local/mysql/bin'
..in the appropriate <VirtualHost xxx.xxx.xxx.xxx:xx> section then restart or reload Apache (httpd) for the change to take effect.

At this point you may be ready to make and restore backups.

In my case I needed to modify the /admin/export.php file since I was unable to pipe the output to a file -- this may be true for "safe_mode = on" no matter what but since I didn't find out why, I just worked around the problem, here is my solution to the error I was getting:

mysqldump: Couldn't find table: ">"


In /admin/export.php find:
$execcommand = "mysqldump --add-drop-table -Q -h $dbhost -u $user -p". $pass ." $databasename > $outputfile &";
..and change to:
mysqldump --add-drop-table -Q -h $dbhost -u $user -p". $pass ." $databasename -r $outputfile";


On the import side of things, In /admin/export.php find:
exec("mysql -h $dbhost -u $user -p". $pass ." $databasename < $inputfile &");
..isn't working for me but the backup.sql file can be used via phpMyAdmin to restore things.

My guess is that it's something with the pipe input of the backup.sql file. I suppose there is a chance that I'm just not waiting long enough.. shaking head I'm not logging any error so maybe that is my problem, impatience.

I'll look into the restore situation more and edit any findings into this post if and when I get a solution.

If you can confirm that I am just not waiting long enough that would be nice to know.
Search thread for
Download thread as
  • 0/5
  • 1
  • 2
  • 3
  • 4
  • 5



This thread is closed, so you cannot post a reply.