00001 #!/usr/bin/perl -w
00002 #
00003 # Connects to the mythtv database and repairs/optimizes the tables that it
00004 # finds. Suggested use is to cron it to run once per day.
00005 #
00006 # @url $URL$
00007 # @date $Date: 2007-08-04 05:25:32 -0400 (Sat, 04 Aug 2007) $
00008 # @version $Revision: 14140 $
00009 # @author $Author: xris $
00010 # @license GPL
00011 #
00012
00013 # Includes
00014 use DBI;
00015 use MythTV;
00016
00017 # Connect to mythbackend
00018 my $Myth = new MythTV({'connect' => 0});
00019
00020 # Connect to the database
00021 $dbh = $Myth->{'dbh'};
00022
00023 # Repair and optimize each table
00024 foreach $table ($dbh->tables) {
00025 unless ($dbh->do("REPAIR TABLE $table")) {
00026 print "Skipped: $table\n";
00027 next;
00028 };
00029 if ($dbh->do("OPTIMIZE TABLE $table")) {
00030 print "Repaired/Optimized: $table\n";
00031 }
00032 if ($dbh->do("ANALYZE TABLE $table")) {
00033 print "Analyzed: $table\n";
00034 }
00035 }
00036