file type fix
git-svn-id: svn://192.168.202.10@3965 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -1,288 +1,288 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# VCA_log_manage.pl version 2.14
|
# VCA_log_manage.pl version 2.14
|
||||||
#
|
#
|
||||||
# This script is designed to manage the vicidial_vca_log table records, with
|
# This script is designed to manage the vicidial_vca_log table records, with
|
||||||
# options to archive them and/or purge them at specific intevals.
|
# options to archive them and/or purge them at specific intevals.
|
||||||
#
|
#
|
||||||
# Place in the crontab and run every month after one in the morning, or whenever
|
# Place in the crontab and run every month after one in the morning, or whenever
|
||||||
# your server is not busy with other tasks
|
# your server is not busy with other tasks
|
||||||
# 30 1 1 * * /usr/share/astguiclient/VCA_log_manage.pl
|
# 30 1 1 * * /usr/share/astguiclient/VCA_log_manage.pl
|
||||||
#
|
#
|
||||||
# Copyright (C) 2026 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
# Copyright (C) 2026 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||||
#
|
#
|
||||||
# CHANGES
|
# CHANGES
|
||||||
# 260112-1455 - First version, based on parts of ADMIN_archive_log_tables script
|
# 260112-1455 - First version, based on parts of ADMIN_archive_log_tables script
|
||||||
#
|
#
|
||||||
|
|
||||||
$CALC_TEST=0;
|
$CALC_TEST=0;
|
||||||
$T=0; $TEST=0;
|
$T=0; $TEST=0;
|
||||||
$DB=0; $DBX=0;
|
$DB=0; $DBX=0;
|
||||||
$archive_vca_only=0;
|
$archive_vca_only=0;
|
||||||
$archived_vca_purge_only=0;
|
$archived_vca_purge_only=0;
|
||||||
|
|
||||||
|
|
||||||
### begin parsing run-time options ###
|
### begin parsing run-time options ###
|
||||||
if (length($ARGV[0])>1)
|
if (length($ARGV[0])>1)
|
||||||
{
|
{
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($#ARGV >= $i)
|
while ($#ARGV >= $i)
|
||||||
{
|
{
|
||||||
$args = "$args $ARGV[$i]";
|
$args = "$args $ARGV[$i]";
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($args =~ /--help/i)
|
if ($args =~ /--help/i)
|
||||||
{
|
{
|
||||||
print "allowed run time options:\n";
|
print "allowed run time options:\n";
|
||||||
print " [--days=XX] = number of days to archive past, default is 732(2 years)\n";
|
print " [--days=XX] = number of days to archive past, default is 732(2 years)\n";
|
||||||
print " [--archive-vca-log-only] = OPTIONAL, only archive vicidial_vca_log table then exit\n";
|
print " [--archive-vca-log-only] = OPTIONAL, only archive vicidial_vca_log table then exit\n";
|
||||||
print " [--archived-vca-purge-only] = OPTIONAL, only delete vicidial_vca_log_archive table records then exit\n";
|
print " [--archived-vca-purge-only] = OPTIONAL, only delete vicidial_vca_log_archive table records then exit\n";
|
||||||
print " [--wipe-all-being-archived] = OPTIONAL, deletes all records from the active table after archiving\n";
|
print " [--wipe-all-being-archived] = OPTIONAL, deletes all records from the active table after archiving\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";
|
print " [--test] = test\n";
|
||||||
print " [--debug] = debug output for some options\n";
|
print " [--debug] = debug output for some options\n";
|
||||||
print " [--debugX] = extra debug output for some options\n\n";
|
print " [--debugX] = extra debug output for some options\n\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($args =~ /-quiet/i)
|
if ($args =~ /-quiet/i)
|
||||||
{
|
{
|
||||||
$q=1; $Q=1;
|
$q=1; $Q=1;
|
||||||
}
|
}
|
||||||
if ($args =~ /--test/i)
|
if ($args =~ /--test/i)
|
||||||
{
|
{
|
||||||
$T=1; $TEST=1;
|
$T=1; $TEST=1;
|
||||||
print "\n-----TESTING-----\n\n";
|
print "\n-----TESTING-----\n\n";
|
||||||
}
|
}
|
||||||
if ($args =~ /--debug/i)
|
if ($args =~ /--debug/i)
|
||||||
{
|
{
|
||||||
$DB=1;
|
$DB=1;
|
||||||
print "\n-----DEBUG-----\n\n";
|
print "\n-----DEBUG-----\n\n";
|
||||||
}
|
}
|
||||||
if ($args =~ /--debugX/i)
|
if ($args =~ /--debugX/i)
|
||||||
{
|
{
|
||||||
$DBX=1;
|
$DBX=1;
|
||||||
print "\n-----DEBUG X-----\n\n";
|
print "\n-----DEBUG X-----\n\n";
|
||||||
}
|
}
|
||||||
if ($args =~ /--calc-test/i)
|
if ($args =~ /--calc-test/i)
|
||||||
{
|
{
|
||||||
$CALC_TEST=1;
|
$CALC_TEST=1;
|
||||||
print "\n-----DATE CALCULATION TESTING ONLY-----\n\n";
|
print "\n-----DATE CALCULATION TESTING ONLY-----\n\n";
|
||||||
}
|
}
|
||||||
if ($args =~ /--wipe-all-being-archived/i)
|
if ($args =~ /--wipe-all-being-archived/i)
|
||||||
{
|
{
|
||||||
$wipe_all=1;
|
$wipe_all=1;
|
||||||
print "\n----- WIPE ALL LOG TABLES BEING ARCHIVED: $wipe_all -----\n\n";
|
print "\n----- WIPE ALL LOG TABLES BEING ARCHIVED: $wipe_all -----\n\n";
|
||||||
}
|
}
|
||||||
if ($args =~ /--days=/i)
|
if ($args =~ /--days=/i)
|
||||||
{
|
{
|
||||||
@data_in = split(/--days=/,$args);
|
@data_in = split(/--days=/,$args);
|
||||||
$CLIdays = $data_in[1];
|
$CLIdays = $data_in[1];
|
||||||
$CLIdays =~ s/ .*$//gi;
|
$CLIdays =~ s/ .*$//gi;
|
||||||
$CLIdays =~ s/\D//gi;
|
$CLIdays =~ s/\D//gi;
|
||||||
if ($CLIdays > 999999)
|
if ($CLIdays > 999999)
|
||||||
{$CLIdays=730;}
|
{$CLIdays=730;}
|
||||||
if ($Q < 1)
|
if ($Q < 1)
|
||||||
{print "\n----- DAYS OVERRIDE: $CLIdays -----\n\n";}
|
{print "\n----- DAYS OVERRIDE: $CLIdays -----\n\n";}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($args =~ /--archive-vca-log-only/i)
|
if ($args =~ /--archive-vca-log-only/i)
|
||||||
{
|
{
|
||||||
$archive_vca_only++;
|
$archive_vca_only++;
|
||||||
if ($Q < 1)
|
if ($Q < 1)
|
||||||
{print "\n----- ARCHIVE VCA LOG ONLY: |$archive_vca_only| -----\n\n";}
|
{print "\n----- ARCHIVE VCA LOG ONLY: |$archive_vca_only| -----\n\n";}
|
||||||
}
|
}
|
||||||
if ($args =~ /--archived-vca-purge-only/i)
|
if ($args =~ /--archived-vca-purge-only/i)
|
||||||
{
|
{
|
||||||
$archived_vca_purge_only++;
|
$archived_vca_purge_only++;
|
||||||
if ($Q < 1)
|
if ($Q < 1)
|
||||||
{print "\n----- ARCHIVED VCA LOG PURGE ONLY: |$archived_vca_purge_only| -----\n\n";}
|
{print "\n----- ARCHIVED VCA LOG PURGE ONLY: |$archived_vca_purge_only| -----\n\n";}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "no command line options set\n";
|
print "no command line options set\n";
|
||||||
}
|
}
|
||||||
### end parsing run-time options ###
|
### end parsing run-time options ###
|
||||||
if ( (length($CLIdays)<1) || ($CLIdays < 1) )
|
if ( (length($CLIdays)<1) || ($CLIdays < 1) )
|
||||||
{
|
{
|
||||||
$CLIdays = ($CLImonths * 30.5);
|
$CLIdays = ($CLImonths * 30.5);
|
||||||
$CLIdays = sprintf("%.0f",$CLIdays);
|
$CLIdays = sprintf("%.0f",$CLIdays);
|
||||||
}
|
}
|
||||||
|
|
||||||
$secX = time();
|
$secX = time();
|
||||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||||
|
|
||||||
$del_epoch = ($secX - (86400 * $CLIdays)); # X days ago
|
$del_epoch = ($secX - (86400 * $CLIdays)); # X days ago
|
||||||
($RMsec,$RMmin,$RMhour,$RMmday,$RMmon,$RMyear,$RMwday,$RMyday,$RMisdst) = localtime($del_epoch);
|
($RMsec,$RMmin,$RMhour,$RMmday,$RMmon,$RMyear,$RMwday,$RMyday,$RMisdst) = localtime($del_epoch);
|
||||||
$RMyear = ($RMyear + 1900);
|
$RMyear = ($RMyear + 1900);
|
||||||
$RMmon++;
|
$RMmon++;
|
||||||
if ($RMmon < 10) {$RMmon = "0$RMmon";}
|
if ($RMmon < 10) {$RMmon = "0$RMmon";}
|
||||||
if ($RMmday < 10) {$RMmday = "0$RMmday";}
|
if ($RMmday < 10) {$RMmday = "0$RMmday";}
|
||||||
if ($RMhour < 10) {$RMhour = "0$RMhour";}
|
if ($RMhour < 10) {$RMhour = "0$RMhour";}
|
||||||
if ($RMmin < 10) {$RMmin = "0$RMmin";}
|
if ($RMmin < 10) {$RMmin = "0$RMmin";}
|
||||||
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";
|
||||||
$del_date = "$RMyear-$RMmon-$RMmday";
|
$del_date = "$RMyear-$RMmon-$RMmday";
|
||||||
|
|
||||||
|
|
||||||
if (!$Q) {print "\n\n-- VCA_log_manage.pl --\n\n";}
|
if (!$Q) {print "\n\n-- VCA_log_manage.pl --\n\n";}
|
||||||
if (!$Q) {print "This program is designed manage the vicidial_vca_log table records, with \n";}
|
if (!$Q) {print "This program is designed manage the vicidial_vca_log table records, with \n";}
|
||||||
if (!$Q) {print "options to archive them and/or purge them at specific intevals.\n";}
|
if (!$Q) {print "options to archive them and/or purge them at specific intevals.\n";}
|
||||||
if (!$Q) {print "$CLIdays days ( $del_time [$del_date]|$del_epoch ) from current date \n\n";}
|
if (!$Q) {print "$CLIdays days ( $del_time [$del_date]|$del_epoch ) from current date \n\n";}
|
||||||
|
|
||||||
if ($CALC_TEST > 0)
|
if ($CALC_TEST > 0)
|
||||||
{
|
{
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
# default path to astguiclient configuration file:
|
# default path to astguiclient configuration file:
|
||||||
$PATHconf = '/etc/astguiclient.conf';
|
$PATHconf = '/etc/astguiclient.conf';
|
||||||
|
|
||||||
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
|
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
|
||||||
@conf = <conf>;
|
@conf = <conf>;
|
||||||
close(conf);
|
close(conf);
|
||||||
$i=0;
|
$i=0;
|
||||||
foreach(@conf)
|
foreach(@conf)
|
||||||
{
|
{
|
||||||
$line = $conf[$i];
|
$line = $conf[$i];
|
||||||
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
|
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
|
||||||
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
|
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
|
||||||
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
|
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
|
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
|
||||||
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
|
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
|
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
|
||||||
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
|
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
|
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
|
||||||
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
|
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
|
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
|
||||||
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
|
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
|
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
|
||||||
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
|
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
|
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
|
||||||
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
|
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
|
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
|
||||||
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
|
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
|
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
|
||||||
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
|
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
|
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
|
||||||
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
|
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
|
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
|
||||||
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
|
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
|
||||||
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
|
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
|
||||||
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
|
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Customized Variables
|
# Customized Variables
|
||||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
$server_ip = $VARserver_ip; # Asterisk server IP
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
or die "Couldn't connect to database: " . DBI->errstr;
|
||||||
|
|
||||||
|
|
||||||
if (!$T)
|
if (!$T)
|
||||||
{
|
{
|
||||||
########## BEGIN --archive-vca-log-only flag processing ##########
|
########## BEGIN --archive-vca-log-only flag processing ##########
|
||||||
if ($archive_vca_only > 0)
|
if ($archive_vca_only > 0)
|
||||||
{
|
{
|
||||||
##### vicidial_vca_log
|
##### vicidial_vca_log
|
||||||
$stmtA = "SELECT count(*) from vicidial_vca_log;";
|
$stmtA = "SELECT count(*) from vicidial_vca_log;";
|
||||||
$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;
|
||||||
$sthArows=$sthA->rows;
|
$sthArows=$sthA->rows;
|
||||||
if ($sthArows > 0)
|
if ($sthArows > 0)
|
||||||
{
|
{
|
||||||
@aryA = $sthA->fetchrow_array;
|
@aryA = $sthA->fetchrow_array;
|
||||||
$vicidial_vca_log_count = $aryA[0];
|
$vicidial_vca_log_count = $aryA[0];
|
||||||
}
|
}
|
||||||
$sthA->finish();
|
$sthA->finish();
|
||||||
|
|
||||||
$stmtA = "SELECT count(*) from vicidial_vca_log_archive;";
|
$stmtA = "SELECT count(*) from vicidial_vca_log_archive;";
|
||||||
$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;
|
||||||
$sthArows=$sthA->rows;
|
$sthArows=$sthA->rows;
|
||||||
if ($sthArows > 0)
|
if ($sthArows > 0)
|
||||||
{
|
{
|
||||||
@aryA = $sthA->fetchrow_array;
|
@aryA = $sthA->fetchrow_array;
|
||||||
$vicidial_vca_log_archive_count = $aryA[0];
|
$vicidial_vca_log_archive_count = $aryA[0];
|
||||||
}
|
}
|
||||||
$sthA->finish();
|
$sthA->finish();
|
||||||
|
|
||||||
if (!$Q) {print "\nProcessing vicidial_vca_log table... ($vicidial_vca_log_count|$vicidial_vca_log_archive_count)\n";}
|
if (!$Q) {print "\nProcessing vicidial_vca_log table... ($vicidial_vca_log_count|$vicidial_vca_log_archive_count)\n";}
|
||||||
$stmtA = "INSERT IGNORE INTO vicidial_vca_log_archive SELECT * from vicidial_vca_log;";
|
$stmtA = "INSERT IGNORE INTO vicidial_vca_log_archive SELECT * from vicidial_vca_log;";
|
||||||
$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;
|
||||||
|
|
||||||
$sthArows = $sthA->rows;
|
$sthArows = $sthA->rows;
|
||||||
if (!$Q) {print "$sthArows rows inserted into vicidial_vca_log_archive table \n";}
|
if (!$Q) {print "$sthArows rows inserted into vicidial_vca_log_archive table \n";}
|
||||||
|
|
||||||
$rv = $sthA->err();
|
$rv = $sthA->err();
|
||||||
if (!$rv)
|
if (!$rv)
|
||||||
{
|
{
|
||||||
if ($wipe_all > 0)
|
if ($wipe_all > 0)
|
||||||
{$stmtA = "DELETE FROM vicidial_vca_log;";}
|
{$stmtA = "DELETE FROM vicidial_vca_log;";}
|
||||||
else
|
else
|
||||||
{$stmtA = "DELETE FROM vicidial_vca_log WHERE analysis_date < '$del_time';";}
|
{$stmtA = "DELETE FROM vicidial_vca_log WHERE analysis_date < '$del_time';";}
|
||||||
if ($DBX > 0) {print " DEBUG: |$stmtA|\n";}
|
if ($DBX > 0) {print " DEBUG: |$stmtA|\n";}
|
||||||
$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;
|
||||||
$sthArows = $sthA->rows;
|
$sthArows = $sthA->rows;
|
||||||
if (!$Q) {print "$sthArows rows deleted from vicidial_vca_log table \n";}
|
if (!$Q) {print "$sthArows rows deleted from vicidial_vca_log table \n";}
|
||||||
|
|
||||||
$stmtA = "optimize table vicidial_vca_log;";
|
$stmtA = "optimize table vicidial_vca_log;";
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$Q) {print "\nProcessing vicidial_vca_log table finished: ($sthArows rows deleted) \n";}
|
if (!$Q) {print "\nProcessing vicidial_vca_log table finished: ($sthArows rows deleted) \n";}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
########## END --archive-vca-log-only flag processing ##########
|
########## END --archive-vca-log-only flag processing ##########
|
||||||
|
|
||||||
########## BEGIN --archived-vca-purge-only flag processing ##########
|
########## BEGIN --archived-vca-purge-only flag processing ##########
|
||||||
if ($archived_vca_purge_only > 0)
|
if ($archived_vca_purge_only > 0)
|
||||||
{
|
{
|
||||||
$stmtA = "SELECT count(*) from vicidial_vca_log_archive;";
|
$stmtA = "SELECT count(*) from vicidial_vca_log_archive;";
|
||||||
$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;
|
||||||
$sthArows=$sthA->rows;
|
$sthArows=$sthA->rows;
|
||||||
if ($sthArows > 0)
|
if ($sthArows > 0)
|
||||||
{
|
{
|
||||||
@aryA = $sthA->fetchrow_array;
|
@aryA = $sthA->fetchrow_array;
|
||||||
$vicidial_vca_log_archive_count = $aryA[0];
|
$vicidial_vca_log_archive_count = $aryA[0];
|
||||||
}
|
}
|
||||||
$sthA->finish();
|
$sthA->finish();
|
||||||
|
|
||||||
if (!$Q) {print "\nProcessing vicidial_vca_log_archive table purge... ($vicidial_vca_log_archive_count)\n";}
|
if (!$Q) {print "\nProcessing vicidial_vca_log_archive table purge... ($vicidial_vca_log_archive_count)\n";}
|
||||||
$stmtA = "DELETE FROM vicidial_vca_log_archive WHERE analysis_date < '$del_time';";
|
$stmtA = "DELETE FROM vicidial_vca_log_archive WHERE analysis_date < '$del_time';";
|
||||||
if ($DBX > 0) {print " DEBUG: |$stmtA|\n";}
|
if ($DBX > 0) {print " DEBUG: |$stmtA|\n";}
|
||||||
$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;
|
||||||
$sthArows = $sthA->rows;
|
$sthArows = $sthA->rows;
|
||||||
if (!$Q) {print "$sthArows rows deleted from vicidial_vca_log_archive table \n";}
|
if (!$Q) {print "$sthArows rows deleted from vicidial_vca_log_archive table \n";}
|
||||||
|
|
||||||
$stmtA = "optimize table vicidial_vca_log_archive;";
|
$stmtA = "optimize table vicidial_vca_log_archive;";
|
||||||
$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;
|
||||||
|
|
||||||
if (!$Q) {print "\nProcessing vicidial_vca_log_archive table finished: ($sthArows rows deleted) \n";}
|
if (!$Q) {print "\nProcessing vicidial_vca_log_archive table finished: ($sthArows rows deleted) \n";}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
########## END --archived-vca-purge-only flag processing ##########
|
########## END --archived-vca-purge-only flag processing ##########
|
||||||
}
|
}
|
||||||
|
|
||||||
### calculate time to run script ###
|
### calculate time to run script ###
|
||||||
$secY = time();
|
$secY = time();
|
||||||
$secZ = ($secY - $secX);
|
$secZ = ($secY - $secX);
|
||||||
$secZm = ($secZ /60);
|
$secZm = ($secZ /60);
|
||||||
if (!$Q) {print "\nscript execution time in seconds: $secZ minutes: $secZm\n";}
|
if (!$Q) {print "\nscript execution time in seconds: $secZ minutes: $secZm\n";}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Reference in New Issue
Block a user