144 lines
4.4 KiB
Perl
144 lines
4.4 KiB
Perl
#!/usr/bin/perl
|
|
#
|
|
# AST_DB_optimize.pl version 0.2 *DBI-version*
|
|
#
|
|
# DESCRIPTION:
|
|
# optimizes the tables used in the asterisk MySQL database
|
|
#
|
|
# It is recommended that you run this program on the local Asterisk machine
|
|
#
|
|
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
|
#
|
|
# CHANGES
|
|
# 60717-1242 - changed to DBI by Marin Blu
|
|
#
|
|
|
|
### Make sure this file is in a libs path or put the absolute path to it
|
|
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
|
|
|
|
if (!$DB_port) {$DB_port='3306';}
|
|
|
|
use DBI;
|
|
|
|
$dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
|
|
or die "Couldn't connect to database: " . DBI->errstr;
|
|
|
|
|
|
$stmtA = "optimize table call_log;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$stmtA = "optimize table park_log;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$stmtA = "optimize table vicidial_log;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$stmtA = "optimize table vicidial_closer_log;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$stmtA = "optimize table vicidial_xfer_log;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
$stmtA = "optimize table vicidial_list;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$stmtA = "optimize table vicidial_manager;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$stmtA = "optimize table vicidial_auto_calls;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$stmtA = "optimize table vicidial_live_agents;";
|
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
|
if (!$T) {
|
|
$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 (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
|
|
$sthA->finish();
|
|
}
|
|
|
|
|
|
$dbhA->disconnect();
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
|
|
|