/
optimize_mythdb.pl
executable file
·49 lines (43 loc) · 1.26 KB
/
optimize_mythdb.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w
#
# Connects to the mythtv database and repairs/optimizes the tables that it
# finds. Suggested use is to cron it to run once per day.
#
# @url $URL$
# @date $Date$
# @version $Revision$
# @author $Author$
# @license GPL
#
# Includes
use DBI;
use MythTV;
# Connect to mythbackend
my $Myth = new MythTV({'connect' => 0});
# Connect to the database
$dbh = $Myth->{'dbh'};
# Repair and optimize each table
foreach $table ($dbh->tables) {
unless ($dbh->do("REPAIR TABLE $table")) {
print "Skipped: $table\n";
next;
};
if ($dbh->do("OPTIMIZE TABLE $table")) {
print "Repaired/Optimized: $table\n";
}
if ($dbh->do("ANALYZE TABLE $table")) {
print "Analyzed: $table\n";
}
}
# Defragement seek table
if ($dbh->do("ALTER TABLE `recordedseek` ORDER BY chanid, starttime, type")) {
print "Defragmented: recordedseek\n";
}
# Defragement program table
if ($dbh->do("ALTER TABLE `program` ORDER BY starttime, chanid")) {
print "Defragmented: program\n";
}
# Defragement video seek table
if ($dbh->do("ALTER TABLE `filemarkup` ORDER BY filename")) {
print "Defragmented: filemarkup\n";
}