[Bio] / Sprout / ERDBTune.pl Repository:
ViewVC logotype

Annotation of /Sprout/ERDBTune.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     use strict;
21 :     use Tracer;
22 :     use ERDB;
23 :    
24 :     =head1 ERDBTune Script
25 :    
26 :     =head2 Introduction
27 :    
28 :     This script performs general utility operations on ERDB databases.
29 :    
30 :     =head2 Positional Parameters
31 :    
32 :     =over 4
33 :    
34 :     =item dbname
35 :    
36 :     Name of the database to process
37 :    
38 :     =back
39 :    
40 :     =head2 Command-Line Options
41 :    
42 :     =over 4
43 :    
44 :     =item trace
45 :    
46 :     Specifies the tracing level. The higher the tracing level, the more messages
47 :     will appear in the trace log. Use E to specify emergency tracing.
48 :    
49 :     =item analyze
50 :    
51 :     If specified, the database tables will be vacuum analyzed to improve
52 :     performance.
53 :    
54 : parrello 1.2 =item missing
55 :    
56 :     If specified, missing database tables will be created.
57 :    
58 : parrello 1.1 =item user
59 :    
60 :     Name suffix to be used for log files. If omitted, the PID is used.
61 :    
62 :     =item sql
63 :    
64 :     If specified, turns on tracing of SQL activity.
65 :    
66 :     =item background
67 :    
68 :     Save the standard and error output to files. The files will be created
69 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
70 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
71 :     B<user> option above.
72 :    
73 :     =item help
74 :    
75 :     Display this command's parameters and options.
76 :    
77 :     =item warn
78 :    
79 :     Create an event in the RSS feed when an error occurs.
80 :    
81 :     =item phone
82 :    
83 :     Phone number to message when the script is complete.
84 :    
85 :     =back
86 :    
87 :     =cut
88 :    
89 :     # Get the command-line options and parameters.
90 :     my ($options, @parameters) = StandardSetup([qw(ERDB DBKernel) ],
91 :     {
92 :     trace => ["", "tracing level"],
93 :     analyze => ["", "vacuum analyze the database tables"],
94 : parrello 1.3 missing => ["", "create missing tables"],
95 : parrello 1.1 phone => ["", "phone number (international format) to call when load finishes"]
96 :     },
97 :     "<dbname>",
98 :     @ARGV);
99 :     # Set a variable to contain return type information.
100 :     my $rtype;
101 :     # Insure we catch errors.
102 :     eval {
103 :     # Insure a database was specified.
104 :     Confess("No database name specified.") if ! scalar(@parameters);
105 :     # Get the target database.
106 :     my $erdb = ERDB::GetDatabase($parameters[0]);
107 : parrello 1.2 my $dbh = $erdb->{_dbh};
108 : parrello 1.1 # Loop through the tables.
109 :     for my $table ($erdb->GetTableNames()) {
110 :     Trace("Processing table $table.") if T(3);
111 :     # Process according to the options.
112 : parrello 1.2 if ($options->{missing}) {
113 :     if (! $dbh->table_exists($table)) {
114 :     Trace("Creating missing table $table.\n");
115 :     $erdb->CreateTable($table);
116 :     }
117 :     }
118 : parrello 1.1 if ($options->{analyze}) {
119 : parrello 1.2 Trace("Analyzing table $table.\n");
120 : parrello 1.1 $erdb->Analyze($table);
121 :     }
122 :     }
123 :     };
124 :     if ($@) {
125 :     Trace("Script failed with error: $@") if T(0);
126 :     $rtype = "error";
127 :     } else {
128 :     Trace("Script complete.") if T(2);
129 :     $rtype = "no error";
130 :     }
131 :     if ($options->{phone}) {
132 :     my $msgID = Tracer::SendSMS($options->{phone}, "ERDBTune terminated with $rtype.");
133 :     if ($msgID) {
134 :     Trace("Phone message sent with ID $msgID.") if T(2);
135 :     } else {
136 :     Trace("Phone message not sent.") if T(2);
137 :     }
138 :     }
139 :    
140 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3