Files
agc_2-X/bin/AST_DB_optimize.pl
T
mattf fba5777836 moving of executables into bin directory
git-svn-id: svn://192.168.202.10@26 3d104415-ff17-0410-8863-d5cf3c621b8a
2006-07-08 00:13:19 +00:00

154 lines
3.8 KiB
Perl

#!/usr/bin/perl
#
# AST_DB_optimize.pl version 0.1
#
# 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
#
### 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 Net::MySQL;
my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port")
or die "Couldn't connect to database: $DB_server - $DB_database\n";
$stmtA = "optimize table call_log;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table park_log;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table vicidial_log;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table vicidial_closer_log;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table vicidial_xfer_log;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table vicidial_list;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table vicidial_manager;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table vicidial_auto_calls;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$stmtA = "optimize table vicidial_live_agents;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) {$dbhA->query($stmtA); }
if ($dbhA->has_selected_record)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{
if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";}
}
}
$dbhA->close;
exit;