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

Annotation of /Sprout/ERDBDumper.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (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 Stats;
23 :     use ERDB;
24 :     use ERDBLoadGroup;
25 :    
26 :     =head1 ERDBDumper Script
27 :    
28 :     =head2 Introduction
29 :    
30 :     ERDBDumper [options] <database> <group1> <group2> ...
31 :    
32 :     Dump ERDB Tables
33 :    
34 :     This is a simple script that will dump all the tables in one or more ERDB load
35 :     groups. The script can be used to save changes to the database content so that
36 :     copies of the database can be reloaded with the same data. Alternatively, it can
37 :     be used to back up part of a database for restoration later.
38 :    
39 :     =head2 Positional Parameters
40 :    
41 :     =over 4
42 :    
43 :     =item database
44 :    
45 :     Name of the database to be dumped (e.g. C<Sprout>, C<Sapling>).
46 :    
47 :     =item group1 group2 ...
48 :    
49 :     Space-delimited list of groups to dump. If C<+> is used, then all groups after
50 :     the previously-named group are included. If C<+> is used by itself, then all
51 :     groups are dumped.
52 :    
53 :     =back
54 :    
55 :     =head2 Command-Line Options
56 :    
57 :     =over 4
58 :    
59 :     =item trace
60 :    
61 :     Specifies the tracing level. The higher the tracing level, the more messages
62 :     will appear in the trace log. Use E to specify emergency tracing.
63 :    
64 :     =item loadDirectory
65 :    
66 :     Directory in which the load files should be created. This option allows you to
67 :     dump the database to somewhere other than the default load directory.
68 :    
69 :     =item user
70 :    
71 :     Name suffix to be used for log files. If omitted, the PID is used.
72 :    
73 :     =item sql
74 :    
75 :     If specified, turns on tracing of SQL activity.
76 :    
77 :     =item background
78 :    
79 :     Save the standard and error output to files. The files will be created
80 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
81 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
82 :     B<user> option above.
83 :    
84 :     =item help
85 :    
86 :     Display this command's parameters and options.
87 :    
88 :     =item warn
89 :    
90 :     Create an event in the RSS feed when an error occurs.
91 :    
92 :     =item phone
93 :    
94 :     Phone number to message when the script is complete.
95 :    
96 :     =back
97 :    
98 :     =cut
99 :    
100 :     # Get the command-line options and parameters.
101 :     my ($options, @parameters) = StandardSetup([qw(ERDB) ],
102 :     {
103 :     trace => ["2", "tracing level"],
104 :     loadDirectory => ["", "alternate load directory"],
105 :     phone => ["", "phone number (international format) to call when load finishes"]
106 :     },
107 :     "<database> <group1> <group2> ...",
108 :     @ARGV);
109 :     # Set a variable to contain return type information.
110 :     my $rtype;
111 :     # Create the statistics object.
112 :     my $stats = Stats->new();
113 :     my $myStartTime = time();
114 :     # Insure we catch errors.
115 :     eval {
116 :     # Get the positional parameters.
117 :     my ($database, @groups) = @parameters;
118 :     # Get the database.
119 :     Trace("Connecting to $database.") if T(2);
120 :     my $erdb = ERDB::GetDatabase($database);
121 :     # Fix the group list.
122 :     my @realGroups = ERDBLoadGroup::ComputeGroups($erdb, \@groups);
123 :     # Compute the location of the load directory.
124 :     my $loadDirectory = $options->{loadDirectory} || $erdb->LoadDirectory();
125 :     # Loop through the groups.
126 :     for my $group (@realGroups) {
127 :     Trace("Processing load group $group.") if T(2);
128 :     # Get the list of tables for this group.
129 :     my @tables = ERDBLoadGroup::GetTables($erdb, $group);
130 :     # Loop through them.
131 :     for my $table (sort @tables) {
132 :     # Dump this table.
133 :     Trace("Dumping $table.") if T(3);
134 :     my $count = $erdb->DumpTable($table, $loadDirectory);
135 :     # Record its statistics.
136 :     $stats->Add($table => $count);
137 :     $stats->Add(records => $count);
138 :     $stats->Add(tables => 1);
139 :     }
140 :     # Record this group.
141 :     $stats->Add(groups => 1);
142 :     }
143 :     Trace("All groups processed.") if T(2);
144 :     };
145 :     if ($@) {
146 :     Trace("Script failed with error: $@") if T(0);
147 :     $rtype = "error";
148 :     } else {
149 :     Trace("Script complete.") if T(2);
150 :     $rtype = "no error";
151 :     }
152 :     # Display the run statistics.
153 :     $stats->Add(duration => (time() - $myStartTime));
154 :     Trace("Statistics for this run:\n" . $stats->Show()) if T(2);
155 :     if ($options->{phone}) {
156 :     my $msgID = Tracer::SendSMS($options->{phone}, "ERDBDumper terminated with $rtype.");
157 :     if ($msgID) {
158 :     Trace("Phone message sent with ID $msgID.") if T(2);
159 :     } else {
160 :     Trace("Phone message not sent.") if T(2);
161 :     }
162 :     }
163 :    
164 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3