Fix email report when mysql is down

This commit is contained in:
Jamie Cameron
2011-12-06 21:42:59 -08:00
parent 8fe0294bea
commit 6dff4d3c25
2 changed files with 16 additions and 14 deletions

View File

@ -16,15 +16,9 @@ else {
$cmode = 0;
}
if ($cmode) {
# Run and check before-backup command (for all DBs)
$bok = &execute_before(undef, STDOUT, 0, $config{'backup_'}, undef);
if (!$bok) {
$failure = "Before-backup command failed!\n";
$ex = 1;
goto EMAIL;
}
}
$ex = 0;
$email = $config{'backup_email_'.($all ? '' : $dbs[0])};
$notify = $config{'backup_notify_'.($all ? '' : $dbs[0])};
# Check if MySQL is running
($r, $out) = &is_mysql_running();
@ -35,9 +29,16 @@ if (!$r) {
goto EMAIL;
}
$ex = 0;
$email = $config{'backup_email_'.($all ? '' : $dbs[0])};
$notify = $config{'backup_notify_'.($all ? '' : $dbs[0])};
if ($cmode) {
# Run and check before-backup command (for all DBs)
$bok = &execute_before(undef, STDOUT, 0, $config{'backup_'}, undef);
if (!$bok) {
$failure = "Before-backup command failed!\n";
$ex = 1;
goto EMAIL;
}
}
foreach $db (@dbs) {
$sf = $all ? "" : $db;
if ($all) {

View File

@ -119,7 +119,7 @@ sub is_mysql_running
if ($driver_handle && !$config{'nodbi'}) {
local $main::error_must_die = 1;
local ($data, $rv);
eval { $data = &execute_sql_safe(undef, "select version()") };
eval { $data = &execute_sql_safe(undef, "select version()"); };
local $err = $@;
$err =~ s/\s+at\s+\S+\s+line.*$//;
if ($@ =~ /denied|password/i) {
@ -137,7 +137,8 @@ if ($driver_handle && !$config{'nodbi'}) {
}
# Fall back to mysqladmin command
local $out = `"$config{'mysqladmin'}" $authstr status 2>&1`;
local $out = &backquote_command(
"\"$config{'mysqladmin'}\" $authstr status 2>&1");
local $rv = $out =~ /uptime/i ? 1 :
$out =~ /denied|password/i ? -1 : 0;
$out =~ s/^.*\Q$config{'mysqladmin'}\E\s*:\s*//;