Forked from flickerfly/backup_mysqldump_error_reporting.sh
Created
August 22, 2022 07:53
-
-
Save k8scat/06a7fef05756c0959c8a570ad28901db to your computer and use it in GitHub Desktop.
mysqldump exit code processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What to do when mysqldump fails | |
function report_mysqldump_fail() { | |
cat $scratch/${filename}_raw.err >> $log | |
mailx -s "mysqldump failed for DB $db_name on $HOSTNAME!!!" [email protected] < $log | |
exit 2 | |
} | |
# How to report a step along the process | |
function status_report() { | |
message=$1 | |
if [[ -z $2 ]]; then | |
verbose_level=1 | |
else | |
verbose_level=$2 | |
fi | |
if [[ $verbose_level -le $verbosity ]]; then | |
now=$(date +"%d-%m-%y %T") | |
echo "$orgid $now $message" >> "/var/log/backup_worker/${orgid}.log" | |
fi | |
} | |
# Back something up | |
mysqldump -h $db_host --databases $db_name | |
# Check the return code and report accordingly | |
if [[ $? = 0 ]]; then | |
status_report "mysqldump succeeded" 2 | |
elif [[ $? = 1 ]]; then | |
status_report "mysqldump EX_USAGE 1 <-- command syntax issue" 1 | |
report_mysqldump_fail | |
elif [[ $? = 2 ]]; then | |
status_report "mysqldump EX_MYSQLERR 2 <-- privilege problem or other issue completing the command" 1 | |
report_mysqldump_fail | |
elif [[ $? = 3 ]]; then | |
status_report "mysqldump EX_CONSCHECK 3 <-- consistency check problem" 1 | |
report_mysqldump_fail | |
elif [[ $? = 4 ]]; then | |
status_report "mysqldump EX_EOM 4 <-- End of Memory" 1 | |
report_mysqldump_fail | |
elif [[ $? = 5 ]]; then | |
status_report "mysqldump EX_EOF 5 <-- Result file problem writing to file, space issue?" 1 | |
report_mysqldump_fail | |
elif [[ $? = 6 ]]; then | |
status_report "mysqldump EX_ILLEGAL_TABLE 6" 1 | |
report_mysqldump_fail | |
else | |
status_report "Backup presumed failed Unknown exit code $? from mysqldump" 1 | |
report_mysqldump_fail | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment