MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
optimize_mythdb.pl
Go to the documentation of this file.
1 #!/usr/bin/perl -w
2 #
3 # Connects to the mythtv database and repairs/optimizes the tables that it
4 # finds. Suggested use is to cron it to run once per day.
5 #
6 # @url $URL$
7 # @date $Date$
8 # @version $Revision$
9 # @author $Author$
10 # @license GPL
11 #
12 
13 # Includes
14  use DBI;
15  use MythTV;
16 
17 # Connect to mythbackend
18  my $Myth = new MythTV({'connect' => 0});
19 
20 # Connect to the database
21  $dbh = $Myth->{'dbh'};
22 
23 # Repair and optimize each table
24  foreach $table ($dbh->tables) {
25  unless ($dbh->do("REPAIR TABLE $table")) {
26  print "Skipped: $table\n";
27  next;
28  };
29  if ($dbh->do("OPTIMIZE TABLE $table")) {
30  print "Repaired/Optimized: $table\n";
31  }
32  if ($dbh->do("ANALYZE TABLE $table")) {
33  print "Analyzed: $table\n";
34  }
35  }
36