Toot4fun Posted December 11, 2007 Share Posted December 11, 2007 I'm trying to create a PHP script that will use mysqldump to backup my databases. I have the following code: $strCommand = "mysqldump --host=$strHostName --user=$strUserName --password=$strPassword $strDBName | gzip > $strBackupFile"; $strOutput = exec(escapeshellcmd($strCommand) . " 2>&1",$arrOutput,$intReturnValue); if($intReturnValue != 0){ etc... However, I get an error that says "mysqldump: Couldn't find table: "|"". I have to assume it's because of the escaping (\), but if I run it without the escapeshellcmd(), if I have an error, the error is written directly to the screen, not stored in $arrOutput or $intReturnValue. If I use escapeshellcmd(), $intReturnValue is populated as is my output array $arrOutput. What gives?? Hopefully I have supplied enough information. Thanks!! Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 I don't belive mysqldump outputs anything usefull to stdout. Nothing that could be piped to gzip anyway. And in fact, if you look at the man page... mysqldump [options] db_name [tables] The optional argument after the db_name tables. Hence, its getting confused and looking for a table called | You'll need to do this in a few steps. Quote Link to comment Share on other sites More sharing options...
Toot4fun Posted December 11, 2007 Author Share Posted December 11, 2007 If it wasn't for the fact that $strCommand = "mysqldump --host=$strHostName --user=$strUserName --password=$strPassword $strDBName | gzip > $strBackupFile"; $strOutput = system($strCommand, $intReturnValue); dumps and zips the output, I would agree with you. But if I run the same command using system() as shown above, I end up with a gzip file. The problem is that if I force an error (bad password), the error is written directly to the screen - $strOutput is empty and $intReturnValue is equal to 0. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.