Question : mysqldump , how to check for errors

I am automating backup of mysql using mysqldump, on linux. I will run the script from cron. I need a way to find out if the command has succeeded or failed. For example when I had corrupted tables the mysql dump was not backing up database and I did not know about it

I am using php to execute linux commans, so the script is PHP but command as shell, so in essence it is shell script
Code Snippet:
1:
2:
3:
4:
5:
$command= '/usr/bin/mysqldump --add-drop-table  -h localhost -u agir2 -ppassword agir2 > '.$sql_dump_file.' > '.$errorlog.' 2>&1'
 
the problem with above code it that it does report error on failure, but on success it outputs whole database in to log file.
 
I am happy to rewrite above or just use bash script.
Open in New Window Select All

Answer : mysqldump , how to check for errors

Add at the end of your command:
&& mailx -s "dump ok" your@email
With above, you will get email after mysqldump finishes its job. Mail will be with "dump ok" subject if everything was ok, and "dump failed" when there were errors.
Random Solutions  
 
programming4us programming4us