Please help on this MySQL backup script...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
compuXP
Forum Newbie
Posts: 17
Joined: Sat Feb 26, 2005 11:19 am

Please help on this MySQL backup script...

Post by compuXP »

Hi,

I would like to know why this doesn't work:

Code: Select all

<?PHP
/* Function to backup a mysql database table
* @param host
*     The database host name (server)
* @param user
*     Database user
* @param password
*     Database password
* @param table
*     Database table name
* @param backup_path
*     The path to backup directory
* @param backup_name
*     The name of the backup file - no extension
*/


function mysql_backup($host, $user, $password, $table, $backup_path, $backup_name) &#123;
 $day = date('w');
 # gzip (.gz)
 $backup = $backup_path.$backup_name.'_'.$day.'.gz';
 exec(sprintf('mysqldump --host=%s --user=%s --password=%s %s --quick --lock-tables --add-drop-table | gzip > %s', $host, $user, $password, $table, $backup));
 # sql (.sql)
 //$backup = $backup_path.$backup_name.'_'.$day.'.sql';
 //exec(sprintf('mysqldump --host=%s --user=%s --password=%s %s --quick --lock-tables --add-drop-table > %s', $host, $user, $password, $table, $backup));
&#125;
mysql_backup('localhost', 'username', 'password', 'members', '/home/*******/public_html/path/backups/', 'members_bckp');
//exec("/home/********/public_html/path/backups/mysql_backup_grabber.php");
?>
How come this won't backup the table? It does not give me any errors but does not copy the table "membes". Also, how can I get it to do the whole database as a compressed file?

Thanks,

-compuXP
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you sure you have permission to call exec() ?
compuXP
Forum Newbie
Posts: 17
Joined: Sat Feb 26, 2005 11:19 am

Post by compuXP »

oh... I'm not sure... actually :?

I need permission? I set the folder CHMOD's to 777...
compuXP
Forum Newbie
Posts: 17
Joined: Sat Feb 26, 2005 11:19 am

Post by compuXP »

i still need some help :( How do I know if I have permission to call the function?
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post by thegreatone2176 »

if you did have perms it would say

exec() : permission denied in /folder/script.php

b/c ive tryed to use chmod before and it told me that so im sure it would do the same ehre
compuXP
Forum Newbie
Posts: 17
Joined: Sat Feb 26, 2005 11:19 am

Post by compuXP »

so now what? How can I get it to work? :(
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

as usual, debugging 101:

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

then probably you will have to find out the complete path for mysqlump and change that in your code...

and the same will go for gzip too....
compuXP
Forum Newbie
Posts: 17
Joined: Sat Feb 26, 2005 11:19 am

Post by compuXP »

hm thanks, I'll try that and get back to you.
Post Reply