Added crashed DB table display to admin web screens
Added --vicidial-dial-log-only flag to log archive script git-svn-id: svn://192.168.202.10@3950 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -75,6 +75,7 @@
|
||||
# 240924-2041 - Added --vicidial-log-only
|
||||
# 250914-1537 - Added archiving of recording_log_stereo and recording_log_parallel tables
|
||||
# 251011-2048 - Added archiving of recording_live_log table
|
||||
# 251024-1518 - Added --vicidial-dial-log-only flag
|
||||
#
|
||||
|
||||
$CALC_TEST=0;
|
||||
@@ -122,6 +123,8 @@ if (length($ARGV[0])>1)
|
||||
print " [--api-log-days=XX] = REQUIRED FOR --api-only, number of days to archive vicidial_api_log table only past\n";
|
||||
print " [--vicidial-log-only] = OPTIONAL, only archive vicidial_log table then exit\n";
|
||||
print " [--vicidial-log-days=XX] = REQUIRED FOR --vicidial-log-only, number of days to archive vicidial_log table only past\n";
|
||||
print " [--vicidial-dial-log-only] = OPTIONAL, only archive vicidial_dial_log table then exit\n";
|
||||
print " [--vicidial-dial-log-days=XX] = REQUIRED FOR --vicidial-dial-log-only, number of days to archive vicidial_dial_log table only past\n";
|
||||
print " [--extended-log-only] = OPTIONAL, only archive vicidial_log_extended table then exit\n";
|
||||
print " [--extended-log-days=XX] = REQUIRED FOR --extended-log-only, number of days to archive vicidial_log_extended table only past\n";
|
||||
print " [--api-archive-only] = OPTIONAL, only purge vicidial_api_log_archive table then exit\n";
|
||||
@@ -294,7 +297,6 @@ if (length($ARGV[0])>1)
|
||||
if ($Q < 1)
|
||||
{print "\n----- VICIDIAL LOG ARCHIVE ONLY $vicidial_log_only -----\n\n";}
|
||||
}
|
||||
|
||||
if ($args =~ /--vicidial-log-days=/i)
|
||||
{
|
||||
$vicidial_log_only++;
|
||||
@@ -308,13 +310,31 @@ if (length($ARGV[0])>1)
|
||||
{print "\n----- VICIDIAL LOG ARCHIVE ACTIVE, DAYS: $extendeddays -----\n\n";}
|
||||
}
|
||||
|
||||
if ($args =~ /--vicidial-dial-log-only/i)
|
||||
{
|
||||
$vicidial_dial_log_only++;
|
||||
if ($Q < 1)
|
||||
{print "\n----- VICIDIAL DIAL LOG ARCHIVE ONLY $vicidial_dial_log_only -----\n\n";}
|
||||
}
|
||||
if ($args =~ /--vicidial-dial-log-days=/i)
|
||||
{
|
||||
$vicidial_dial_log_only++;
|
||||
@data_in = split(/--vicidial-dial-log-days=/,$args);
|
||||
$extendeddays = $data_in[1];
|
||||
$extendeddays =~ s/ .*$//gi;
|
||||
$extendeddays =~ s/\D//gi;
|
||||
if ($extendeddays > 999999)
|
||||
{$extendeddays=1825;}
|
||||
if ($Q < 1)
|
||||
{print "\n----- VICIDIAL DIAL LOG ARCHIVE ACTIVE, DAYS: $extendeddays -----\n\n";}
|
||||
}
|
||||
|
||||
if ($args =~ /--extended-log-only/i)
|
||||
{
|
||||
$extended_log_only++;
|
||||
if ($Q < 1)
|
||||
{print "\n----- EXTENDED LOG ARCHIVE ONLY $extended_log_only -----\n\n";}
|
||||
}
|
||||
|
||||
if ($args =~ /--extended-log-days=/i)
|
||||
{
|
||||
$extended_log_only++;
|
||||
@@ -334,7 +354,6 @@ if (length($ARGV[0])>1)
|
||||
if ($Q < 1)
|
||||
{print "\n----- API ARCHIVE PURGE ONLY -----\n\n";}
|
||||
}
|
||||
|
||||
if ($args =~ /--api-archive-days=/i)
|
||||
{
|
||||
$api_log_archive_purge++;
|
||||
@@ -354,7 +373,6 @@ if (length($ARGV[0])>1)
|
||||
if ($Q < 1)
|
||||
{print "\n----- URL LOG PURGE ONLY -----\n\n";}
|
||||
}
|
||||
|
||||
if ($args =~ /--url-log-days=/i)
|
||||
{
|
||||
$url_log_only++;
|
||||
@@ -505,7 +523,7 @@ if ($url_log_only > 0)
|
||||
if ($URLsec < 10) {$URLsec = "0$URLsec";}
|
||||
$URLdel_time = "$URLyear-$URLmon-$URLmday $URLhour:$URLmin:$URLsec";
|
||||
}
|
||||
if ( ($extended_log_only > 0) || ($vicidial_log_only > 0) )
|
||||
if ( ($extended_log_only > 0) || ($vicidial_log_only > 0) || ($vicidial_dial_log_only > 0) )
|
||||
{
|
||||
$EXTENDEDdel_epoch = ($secX - (86400 * $extendeddays)); # X days ago
|
||||
($EXTENDEDsec,$EXTENDEDmin,$EXTENDEDhour,$EXTENDEDmday,$EXTENDEDmon,$EXTENDEDyear,$EXTENDEDwday,$EXTENDEDyday,$EXTENDEDisdst) = localtime($EXTENDEDdel_epoch);
|
||||
@@ -2083,6 +2101,66 @@ if (!$T)
|
||||
########## END --vicidial-log-only flag processing ##########
|
||||
|
||||
|
||||
|
||||
|
||||
########## BEGIN --vicidial-dial-log-only flag processing ##########
|
||||
if ($vicidial_dial_log_only > 0)
|
||||
{
|
||||
##### vicidial_dial_log
|
||||
$stmtA = "SELECT count(*) from vicidial_dial_log;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$vicidial_dial_log_count = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$stmtA = "SELECT count(*) from vicidial_dial_log_archive;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$vicidial_dial_log_archive_count = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if (!$Q) {print "\nProcessing vicidial_dial_log table... ($vicidial_dial_log_count|$vicidial_dial_log_archive_count)\n";}
|
||||
$stmtA = "INSERT IGNORE INTO vicidial_dial_log_archive SELECT * from vicidial_dial_log;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
|
||||
$sthArows = $sthA->rows;
|
||||
if (!$Q) {print "$sthArows rows inserted into vicidial_dial_log_archive table \n";}
|
||||
|
||||
$rv = $sthA->err();
|
||||
if (!$rv)
|
||||
{
|
||||
if ($wipe_all > 0)
|
||||
{$stmtA = "DELETE FROM vicidial_dial_log;";}
|
||||
else
|
||||
{$stmtA = "DELETE FROM vicidial_dial_log WHERE call_date < '$EXTENDEDdel_time';";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows = $sthA->rows;
|
||||
if (!$Q) {print "$sthArows rows deleted from vicidial_dial_log table \n";}
|
||||
|
||||
$stmtA = "optimize table vicidial_dial_log;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
}
|
||||
|
||||
if (!$Q) {print "\nProcessing vicidial_dial_log table finished: ($sthArows rows deleted) \n";}
|
||||
|
||||
exit;
|
||||
}
|
||||
########## END --vicidial-dial-log-only flag processing ##########
|
||||
|
||||
|
||||
if ($queue_log > 0)
|
||||
{
|
||||
#############################################
|
||||
|
||||
@@ -177,9 +177,10 @@
|
||||
# 250924-2212 - Added code for deprecation of "Monitor" application after Asterisk 20
|
||||
# 251006-0832 - Added truncating of vicidial_dtmf_log older than 24 hours & If recording_dtmf_muting enabled, force use of MixMonitor for recording
|
||||
# 251011-1000 - Added archiving of recording_dtmf_muting_log, disabled purging of recording_live_log after 7 days
|
||||
# 251024-2222 - Added crashed table detection
|
||||
#
|
||||
|
||||
$build = '251011-1000';
|
||||
$build = '251024-2222';
|
||||
|
||||
$DB=0; # Debug flag
|
||||
$teodDB=0; # flag to log Timeclock End of Day processes to log file
|
||||
@@ -502,7 +503,7 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA
|
||||
|
||||
|
||||
##### Get the settings from system_settings #####
|
||||
$stmtA = "SELECT sounds_central_control_active,active_voicemail_server,custom_dialplan_entry,default_codecs,generate_cross_server_exten,voicemail_timezones,default_voicemail_timezone,call_menu_qualify_enabled,allow_voicemail_greeting,reload_timestamp,meetme_enter_login_filename,meetme_enter_leave3way_filename,allow_chats,enable_auto_reports,enable_drop_lists,expired_lists_inactive,sip_event_logging,call_quota_lead_ranking,inbound_answer_config,log_latency_gaps,demographic_quotas,weekday_resets,highest_lead_id,hopper_hold_inserts,stereo_recording,stereo_parallel_recording,recording_dtmf_muting FROM system_settings;";
|
||||
$stmtA = "SELECT sounds_central_control_active,active_voicemail_server,custom_dialplan_entry,default_codecs,generate_cross_server_exten,voicemail_timezones,default_voicemail_timezone,call_menu_qualify_enabled,allow_voicemail_greeting,reload_timestamp,meetme_enter_login_filename,meetme_enter_leave3way_filename,allow_chats,enable_auto_reports,enable_drop_lists,expired_lists_inactive,sip_event_logging,call_quota_lead_ranking,inbound_answer_config,log_latency_gaps,demographic_quotas,weekday_resets,highest_lead_id,hopper_hold_inserts,stereo_recording,stereo_parallel_recording,recording_dtmf_muting,db_crashed_tables_check FROM system_settings;";
|
||||
# print "$stmtA\n";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
@@ -537,6 +538,7 @@ if ($sthArows > 0)
|
||||
$SSstereo_recording = $aryA[24];
|
||||
$SSstereo_parallel_recording = $aryA[25];
|
||||
$SSrecording_dtmf_muting = $aryA[26];
|
||||
$SSdb_crashed_tables_check = $aryA[27];
|
||||
}
|
||||
$sthA->finish();
|
||||
if ($DBXXX > 0) {print "SYSTEM SETTINGS: $sounds_central_control_active|$active_voicemail_server|$SScustom_dialplan_entry|$SSdefault_codecs\n";}
|
||||
@@ -604,6 +606,7 @@ else
|
||||
$runningASTERISK=0;
|
||||
$runningsip_logger=0;
|
||||
$runningconf_updater=0;
|
||||
$runningcrash_test=0;
|
||||
$AST_conf_3way=0;
|
||||
$AST_rec_monitor=0;
|
||||
|
||||
@@ -780,6 +783,11 @@ else
|
||||
$runningAST_rec_monitor++;
|
||||
if ($DB) {print "AST_rec_monitor RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
if ($psline[1] =~ /$REGhome\/AST_table_status\.pl/)
|
||||
{
|
||||
$runningcrash_test++;
|
||||
if ($DB) {print "AST_table_status RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
@@ -953,6 +961,11 @@ else
|
||||
$runningAST_rec_monitor++;
|
||||
if ($DB) {print "AST_rec_monitor RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
if ($psline[1] =~ /$REGhome\/AST_table_status\.pl/)
|
||||
{
|
||||
$runningcrash_test++;
|
||||
if ($DB) {print "AST_table_status RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
@@ -1522,6 +1535,15 @@ if ($timeclock_end_of_day_NOW > 0)
|
||||
if ($DB) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
||||
$sthA->finish();
|
||||
|
||||
$stmtA = "optimize table crashed_tables;";
|
||||
if($DBX){print STDERR "\n|$stmtA|\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
if ($DB) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
||||
$sthA->finish();
|
||||
|
||||
if ($agents_calls_reset > 0)
|
||||
{
|
||||
$stmtA = "delete from vicidial_live_inbound_agents where last_call_finish < \"$TDSQLdate\";";
|
||||
@@ -2318,7 +2340,7 @@ if ($timeclock_end_of_day_NOW > 0)
|
||||
|
||||
|
||||
##### BEGIN vicidial_dtmf_log end of day process removing records older than 24 hours #####
|
||||
$stmtA = "DELETE from vicidial_dtmf_log where vicidial_dtmf_log < \"$RMSQLdate\";";
|
||||
$stmtA = "DELETE from vicidial_dtmf_log where dtmf_time < \"$RMSQLdate\";";
|
||||
if($DBX){print STDERR "\n|$stmtA|\n";}
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
if($DB){print STDERR "\n|$affected_rows vicidial_dtmf_log records older than 1 day purged|\n";}
|
||||
@@ -6812,6 +6834,49 @@ if ($AST_VDadapt > 0)
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
##### BEGIN check for crashed tables
|
||||
################################################################################
|
||||
if ( ($THISserver_voicemail > 0) && ($SSdb_crashed_tables_check > 0) )
|
||||
{
|
||||
if ($DB) {print "Begin check for crashed table... |db_crashed_tables_check setting: $SSdb_crashed_tables_check| \n";}
|
||||
|
||||
if ($runningcrash_test > 0)
|
||||
{
|
||||
if ($DB) {print "Previous crash test already running, do not start another one.\n";}
|
||||
}
|
||||
else
|
||||
{
|
||||
$start_crash_check_now=0;
|
||||
if ($SSdb_crashed_tables_check >= 4)
|
||||
{$start_crash_check_now++;}
|
||||
if ( ($SSdb_crashed_tables_check >= 3) && ($reset_test =~ /0$/) )
|
||||
{$start_crash_check_now++;}
|
||||
if ( ($SSdb_crashed_tables_check >= 2) && ($reset_test =~ /00$/) )
|
||||
{$start_crash_check_now++;}
|
||||
if ( ($SSdb_crashed_tables_check >= 1) && ($timeclock_end_of_day_NOW > 0) )
|
||||
{$start_crash_check_now++;}
|
||||
|
||||
if ($start_crash_check_now > 0)
|
||||
{
|
||||
if ($DB) {print "starting AST_table_status... |$start_crash_check_now| \n";}
|
||||
# add a '-L' to the command below to activate logging
|
||||
`/usr/bin/screen -d -m -S ASTcrash $PATHhome/AST_table_status.pl --debugX`;
|
||||
if ($megaDB)
|
||||
{
|
||||
`/usr/bin/screen -S ASTcrash -X logfile $PATHlogs/ASTcrash-screenlog.0`;
|
||||
`/usr/bin/screen -S ASTcrash -X log`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
################################################################################
|
||||
##### END check for crashed tables
|
||||
################################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ($DB) {print "DONE\n";}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_table_status.pl version 2.12
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# - gathers MySQL "SHOW TABLE STATUS" info to check for crashed tables
|
||||
#
|
||||
#
|
||||
# Copyright (C) 2025 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# CHANGES
|
||||
# 251025-1618 - First build
|
||||
#
|
||||
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
$i=0;
|
||||
while ($#ARGV >= $i)
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($args =~ /--help/i)
|
||||
{
|
||||
print "allowed run time options:\n";
|
||||
print " [-q] = quiet\n";
|
||||
print " [-t] = test\n";
|
||||
print " [--debug] = debugging messages\n";
|
||||
print " [--debugX] = Extra debugging messages\n";
|
||||
print "\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /-q/i)
|
||||
{
|
||||
$q=1; $Q=1;
|
||||
}
|
||||
if ($args =~ /--debug/i)
|
||||
{
|
||||
$DB=1;
|
||||
print "\n----- DEBUGGING -----\n\n";
|
||||
}
|
||||
if ($args =~ /--debugX/i)
|
||||
{
|
||||
$DBX=1;
|
||||
print "\n----- EXTRA DEBUGGING -----\n\n";
|
||||
}
|
||||
if ($args =~ /-t|--test/i)
|
||||
{
|
||||
$T=1; $TEST=1;
|
||||
print "\n----- TESTING -----\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set Exiting...\n";
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
$secX = time();
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||
$year = ($year + 1900);
|
||||
$yy = $year; $yy =~ s/^..//gi;
|
||||
$mon++;
|
||||
if ($mon < 10) {$mon = "0$mon";}
|
||||
if ($mday < 10) {$mday = "0$mday";}
|
||||
if ($hour < 10) {$hour = "0$hour";}
|
||||
if ($min < 10) {$min = "0$min";}
|
||||
if ($sec < 10) {$sec = "0$sec";}
|
||||
$now_date="$year-$mon-$mday $hour:$min:$sec";
|
||||
|
||||
if (!$Q) {print "NOW DATETIME: $now_date \n";}
|
||||
|
||||
# default path to astguiclient configuration file:
|
||||
$PATHconf = '/etc/astguiclient.conf';
|
||||
|
||||
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
|
||||
@conf = <conf>;
|
||||
close(conf);
|
||||
$i=0;
|
||||
foreach(@conf)
|
||||
{
|
||||
$line = $conf[$i];
|
||||
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
|
||||
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
|
||||
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
|
||||
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
|
||||
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
|
||||
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
|
||||
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
|
||||
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
|
||||
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
|
||||
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
|
||||
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
|
||||
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
|
||||
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
|
||||
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
|
||||
$i++;
|
||||
}
|
||||
|
||||
# Customized Variables
|
||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
||||
|
||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||
|
||||
use DBI;
|
||||
|
||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
||||
or die "Couldn't connect to database: " . DBI->errstr;
|
||||
|
||||
|
||||
if ($DB) {print "Begin check for crashed table...\n";}
|
||||
# gather crashed table records
|
||||
$stmtA = "SHOW TABLE STATUS WHERE Comment LIKE \"%crash%\";";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArowsCRASH=$sthA->rows;
|
||||
$i=0;
|
||||
while ($sthArowsCRASH > $i)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CRASHEDtables[$i] = $aryA[0];
|
||||
|
||||
if($DBX){print STDERR "\nCRASHED TABLE: |$i|$CRASHEDtables[$i]| \n";}
|
||||
|
||||
$i++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ($i > 0)
|
||||
{
|
||||
$keep_tables="''";
|
||||
$i=0;
|
||||
while ($sthArowsCRASH > $i)
|
||||
{
|
||||
$keep_tables .= ",'$CRASHEDtables[$i]'";
|
||||
$stmtA = "INSERT INTO crashed_tables SET table_name='$CRASHEDtables[$i]',crashed_datetime='$now_date',last_check_datetime='$now_date' ON DUPLICATE KEY UPDATE last_check_datetime='$now_date';";
|
||||
$Iaffected_rows = $dbhA->do($stmtA);
|
||||
if ($DB) {print "Crashed table update: |$Iaffected_rows|$stmtA";}
|
||||
$i++;
|
||||
}
|
||||
$stmtA = "DELETE FROM crashed_tables where table_name NOT IN($keep_tables);";
|
||||
$Iaffected_rows = $dbhA->do($stmtA);
|
||||
if ($DB) {print "Crashed table old entries cleared: |$Iaffected_rows|$stmtA";}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($DBX){print STDERR "\nNO CRASHED TABLES FOUND.\n";}
|
||||
$CRASHEDtable_ct=0;
|
||||
# gather crashed table records count
|
||||
$stmtA = "SELECT count(*) FROM crashed_tables;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArowsCRASHct=$sthA->rows;
|
||||
if ($sthArowsCRASHct > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CRASHEDtable_ct = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ($CRASHEDtable_ct > 0)
|
||||
{
|
||||
$stmtA = "DELETE FROM crashed_tables;";
|
||||
$Iaffected_rows = $dbhA->do($stmtA);
|
||||
if ($DB) {print "Crashed table cleared: |$Iaffected_rows|$stmtA";}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$dbhA->disconnect();
|
||||
|
||||
if (!$Q) {print "Script exiting\n";}
|
||||
|
||||
exit;
|
||||
Reference in New Issue
Block a user