From c8cc7d80bd1cb76372d946af046e738b12c5e0fd Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 17 Sep 2024 02:12:29 +0000 Subject: [PATCH] Added --extended-log-only option to archive script git-svn-id: svn://192.168.202.10@3874 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl | 101 +++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl b/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl index b17a438d..ce15794c 100644 --- a/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl +++ b/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl @@ -20,7 +20,7 @@ # Based on perl scripts in ViciDial from Matt Florell and post: # http://www.vicidial.org/VICIDIALforum/viewtopic.php?p=22506&sid=ca5347cffa6f6382f56ce3db9fb3d068#22506 # -# Copyright (C) 2023 I. Taushanov, Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2024 I. Taushanov, Matt Florell LICENSE: AGPLv2 # # CHANGES # 90615-1701 - First version @@ -71,6 +71,7 @@ # 231028-0810 - Added --url-log-only and --url-log-days=x options for purging of vicidial_url_log table only # 231117-1914 - Added vicidial_3way_press_log archiving # 231126-2227 - Added vicidial_hci_log archiving +# 240916-2159 - Added --extended-log-only # $CALC_TEST=0; @@ -116,6 +117,8 @@ if (length($ARGV[0])>1) print " [--park-log-days=XX] = OPTIONAL, number of days to archive park_log table only past\n"; print " [--api-only] = OPTIONAL, only archive vicidial_api_log table then exit\n"; print " [--api-log-days=XX] = REQUIRED FOR --api-only, number of days to archive vicidial_api_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"; print " [--api-archive-days=XX] = REQUIRED FOR --api-archive-only, number of days to purge vicidial_api_log_archive table only past\n"; print " [--url-log-only] = OPTIONAL, only purge vicidial_url_log table then exit\n"; @@ -280,6 +283,26 @@ if (length($ARGV[0])>1) {print "\n----- API LOG ARCHIVE ACTIVE, DAYS: $apidays -----\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++; + @data_in = split(/--extended-log-days=/,$args); + $extendeddays = $data_in[1]; + $extendeddays =~ s/ .*$//gi; + $extendeddays =~ s/\D//gi; + if ($extendeddays > 999999) + {$extendeddays=1825;} + if ($Q < 1) + {print "\n----- EXTENDED LOG ARCHIVE ACTIVE, DAYS: $extendeddays -----\n\n";} + } + if ($args =~ /--api-archive-only/i) { $api_archive_only++; @@ -457,7 +480,19 @@ if ($url_log_only > 0) if ($URLsec < 10) {$URLsec = "0$URLsec";} $URLdel_time = "$URLyear-$URLmon-$URLmday $URLhour:$URLmin:$URLsec"; } - +if ($extended_log_only > 0) + { + $EXTENDEDdel_epoch = ($secX - (86400 * $extendeddays)); # X days ago + ($EXTENDEDsec,$EXTENDEDmin,$EXTENDEDhour,$EXTENDEDmday,$EXTENDEDmon,$EXTENDEDyear,$EXTENDEDwday,$EXTENDEDyday,$EXTENDEDisdst) = localtime($EXTENDEDdel_epoch); + $EXTENDEDyear = ($EXTENDEDyear + 1900); + $EXTENDEDmon++; + if ($EXTENDEDmon < 10) {$EXTENDEDmon = "0$EXTENDEDmon";} + if ($EXTENDEDmday < 10) {$EXTENDEDmday = "0$EXTENDEDmday";} + if ($EXTENDEDhour < 10) {$EXTENDEDhour = "0$EXTENDEDhour";} + if ($EXTENDEDmin < 10) {$EXTENDEDmin = "0$EXTENDEDmin";} + if ($EXTENDEDsec < 10) {$EXTENDEDsec = "0$EXTENDEDsec";} + $EXTENDEDdel_time = "$EXTENDEDyear-$EXTENDEDmon-$EXTENDEDmday $EXTENDEDhour:$EXTENDEDmin:$EXTENDEDsec"; + } if ($cpd_log_purge > 0) { $CPDdel_epoch = ($secX - (86400 * $CPDdays)); # X days ago @@ -1907,6 +1942,68 @@ if (!$T) ########## END --url-log-only flag processing ########## + ########## BEGIN --extended-log-only flag processing ########## + if ($extended_log_only > 0) + { + ##### vicidial_log_extended + $stmtA = "SELECT count(*) from vicidial_log_extended;"; + $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_log_extended_count = $aryA[0]; + } + $sthA->finish(); + + $stmtA = "SELECT count(*) from vicidial_log_extended_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_log_extended_archive_count = $aryA[0]; + } + $sthA->finish(); + + if (!$Q) {print "\nProcessing vicidial_log_extended table... ($vicidial_log_extended_count|$vicidial_log_extended_archive_count)\n";} + $stmtA = "INSERT IGNORE INTO vicidial_log_extended_archive SELECT * from vicidial_log_extended;"; + $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_log_extended_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + if ($wipe_all > 0) + {$stmtA = "DELETE FROM vicidial_log_extended;";} + else + {$stmtA = "DELETE FROM vicidial_log_extended 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_log_extended table \n";} + + $stmtA = "optimize table vicidial_log_extended;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $stmtA = "optimize table vicidial_log_extended_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + + if (!$Q) {print "\nProcessing vicidial_log_extended table finished: ($sthArows rows deleted) \n";} + + exit; + } + ########## END --extended-log-only flag processing ########## + + if ($queue_log > 0) { #############################################