Added --recording-log-days=X option to the archive log tables script

git-svn-id: svn://192.168.202.10@2583 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2016-08-27 14:18:30 +00:00
parent e4d45959df
commit dfd44f9ad7
3 changed files with 94 additions and 2 deletions
+83 -1
View File
@@ -43,11 +43,13 @@
# 151109-1646 - Added --carrier-daily flag, only active if --daily flag is also used # 151109-1646 - Added --carrier-daily flag, only active if --daily flag is also used
# 151124-2252 - Added --vlog-daily flag, only active if --daily flag is also used, Also added system_settings date # 151124-2252 - Added --vlog-daily flag, only active if --daily flag is also used, Also added system_settings date
# 160612-0703 - Added --only-trim-archive-... options # 160612-0703 - Added --only-trim-archive-... options
# 160827-0957 - Added --recording-log-days=X option
# #
$CALC_TEST=0; $CALC_TEST=0;
$T=0; $TEST=0; $T=0; $TEST=0;
$only_trim_archive=0; $only_trim_archive=0;
$recording_log_archive=0;
### begin parsing run-time options ### ### begin parsing run-time options ###
if (length($ARGV[0])>1) if (length($ARGV[0])>1)
@@ -75,7 +77,8 @@ if (length($ARGV[0])>1)
print " [--only-trim-archive-level-two] = same as --only-trim-archive-level-one, except includes tables:\n"; print " [--only-trim-archive-level-two] = same as --only-trim-archive-level-one, except includes tables:\n";
print " vicidial_carrier_log_archive, vicidial_api_log_archive\n"; print " vicidial_carrier_log_archive, vicidial_api_log_archive\n";
print " [--only-trim-archive-level-three] = same as --only-trim-archive-level-two, except includes tables:\n"; print " [--only-trim-archive-level-three] = same as --only-trim-archive-level-two, except includes tables:\n";
print " vicidial_log_archive, vicidial_agent_log_archive, vicidial_closer_log_archive"; print " vicidial_log_archive, vicidial_agent_log_archive, vicidial_closer_log_archive\n";
print " [--recording-log-days=XX] = OPTIONAL, number of days to archive recording_log table only past\n";
print " [--quiet] = quiet\n"; print " [--quiet] = quiet\n";
print " [--calc-test] = date calculation test only\n"; print " [--calc-test] = date calculation test only\n";
print " [--test] = test\n\n"; print " [--test] = test\n\n";
@@ -167,6 +170,18 @@ if (length($ARGV[0])>1)
if ($Q < 1) if ($Q < 1)
{print "\n----- ONLY TRIM LOG ARCHIVES LEVEL 3 -----\n\n";} {print "\n----- ONLY TRIM LOG ARCHIVES LEVEL 3 -----\n\n";}
} }
if ($args =~ /--recording-log-days=/i)
{
$recording_log_archive++;
@data_in = split(/--recording-log-days=/,$args);
$RECORDINGdays = $data_in[1];
$RECORDINGdays =~ s/ .*$//gi;
$RECORDINGdays =~ s/\D//gi;
if ($RECORDINGdays > 999999)
{$RECORDINGdays=1825;}
if ($Q < 1)
{print "\n----- RECORDING LOG ARCHIVE ACTIVE, DAYS: $RECORDINGdays -----\n\n";}
}
} }
} }
else else
@@ -212,6 +227,19 @@ else
if ($RMsec < 10) {$RMsec = "0$RMsec";} if ($RMsec < 10) {$RMsec = "0$RMsec";}
$del_time = "$RMyear-$RMmon-$RMmday $RMhour:$RMmin:$RMsec"; $del_time = "$RMyear-$RMmon-$RMmday $RMhour:$RMmin:$RMsec";
} }
if ($recording_log_archive > 0)
{
$RECdel_epoch = ($secX - (86400 * $RECORDINGdays)); # X days ago
($RECsec,$RECmin,$REChour,$RECmday,$RECmon,$RECyear,$RECwday,$RECyday,$RECisdst) = localtime($RECdel_epoch);
$RECyear = ($RECyear + 1900);
$RECmon++;
if ($RECmon < 10) {$RECmon = "0$RECmon";}
if ($RECmday < 10) {$RECmday = "0$RECmday";}
if ($REChour < 10) {$REChour = "0$REChour";}
if ($RECmin < 10) {$RECmin = "0$RECmin";}
if ($RECsec < 10) {$RECsec = "0$RECsec";}
$RECdel_time = "$RECyear-$RECmon-$RECmday $REChour:$RECmin:$RECsec";
}
if (!$Q) {print "\n\n-- ADMIN_archive_log_tables.pl --\n\n";} if (!$Q) {print "\n\n-- ADMIN_archive_log_tables.pl --\n\n";}
if (!$Q) {print "This program is designed to put all records from call_log, vicidial_log,\n";} if (!$Q) {print "This program is designed to put all records from call_log, vicidial_log,\n";}
@@ -219,6 +247,7 @@ if (!$Q) {print "server_performance, vicidial_agent_log, vicidial_carrier_log, \
if (!$Q) {print "vicidial_call_notes, vicidial_lead_search_log and others into relevant\n";} if (!$Q) {print "vicidial_call_notes, vicidial_lead_search_log and others into relevant\n";}
if (!$Q) {print "_archive tables and delete records in original tables older than\n";} if (!$Q) {print "_archive tables and delete records in original tables older than\n";}
if (!$Q) {print "$CLIdays days ( $del_time|$del_epoch ) from current date \n\n";} if (!$Q) {print "$CLIdays days ( $del_time|$del_epoch ) from current date \n\n";}
if ( (!$Q) && ($recording_log_archive > 0) ) {print "REC $RECORDINGdays days ( $RECdel_time|$RECdel_epoch ) from current date \n\n";}
if ($CALC_TEST > 0) if ($CALC_TEST > 0)
{ {
@@ -1667,6 +1696,59 @@ if (!$T)
} }
if ($recording_log_archive > 0)
{
##### recording_log
$stmtA = "SELECT count(*) from recording_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;
$recording_log_count = $aryA[0];
}
$sthA->finish();
$stmtA = "SELECT count(*) from recording_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;
$recording_log_archive_count = $aryA[0];
}
$sthA->finish();
if (!$Q) {print "\nProcessing recording_log table... ($recording_log_count|$recording_log_archive_count)\n";}
$stmtA = "INSERT IGNORE INTO recording_log_archive SELECT * from recording_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 recording_log_archive table \n";}
$rv = $sthA->err();
if (!$rv)
{
$stmtA = "DELETE FROM recording_log WHERE start_time < '$RECdel_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 recording_log table \n";}
$stmtA = "optimize table recording_log;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$stmtA = "optimize table recording_log_archive;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
}
}
$stmtA = "UPDATE system_settings SET oldest_logs_date='$del_time';"; $stmtA = "UPDATE system_settings SET oldest_logs_date='$del_time';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -3713,6 +3713,10 @@ ALTER TABLE vicidial_api_log_archive MODIFY api_id INT(9) UNSIGNED NOT NULL;
CREATE TABLE vicidial_callbacks_archive LIKE vicidial_callbacks; CREATE TABLE vicidial_callbacks_archive LIKE vicidial_callbacks;
ALTER TABLE vicidial_callbacks_archive MODIFY callback_id INT(9) UNSIGNED NOT NULL; ALTER TABLE vicidial_callbacks_archive MODIFY callback_id INT(9) UNSIGNED NOT NULL;
CREATE TABLE recording_log_archive LIKE recording_log;
ALTER TABLE recording_log_archive MODIFY recording_id INT(10) UNSIGNED UNIQUE NOT NULL;
ALTER TABLE recording_log_archive DROP PRIMARY KEY;
GRANT RELOAD ON *.* TO cron@'%'; GRANT RELOAD ON *.* TO cron@'%';
GRANT RELOAD ON *.* TO cron@localhost; GRANT RELOAD ON *.* TO cron@localhost;
@@ -3787,4 +3791,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version';
UPDATE system_settings set vdc_agent_api_active='1'; UPDATE system_settings set vdc_agent_api_active='1';
UPDATE system_settings SET db_schema_version='1465',db_schema_update_date=NOW(),reload_timestamp=NOW(); UPDATE system_settings SET db_schema_version='1466',db_schema_update_date=NOW(),reload_timestamp=NOW();
+6
View File
@@ -644,3 +644,9 @@ ALTER TABLE vicidial_inbound_groups ADD customer_chat_survey_link TEXT;
ALTER TABLE vicidial_inbound_groups ADD customer_chat_survey_text TEXT; ALTER TABLE vicidial_inbound_groups ADD customer_chat_survey_text TEXT;
UPDATE system_settings SET db_schema_version='1465',db_schema_update_date=NOW() where db_schema_version < 1465; UPDATE system_settings SET db_schema_version='1465',db_schema_update_date=NOW() where db_schema_version < 1465;
CREATE TABLE recording_log_archive LIKE recording_log;
ALTER TABLE recording_log_archive MODIFY recording_id INT(10) UNSIGNED UNIQUE NOT NULL;
ALTER TABLE recording_log_archive DROP PRIMARY KEY;
UPDATE system_settings SET db_schema_version='1466',db_schema_update_date=NOW() where db_schema_version < 1466;