Created
May 24, 2018 14:50
-
-
Save flickerfly/1da964009ccf3dd80e551157a1ac6cfe to your computer and use it in GitHub Desktop.
Revisions
-
flickerfly created this gist
May 24, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ # 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