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

Annotation of /Sprout/ERDBDumper.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (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 : parrello 1.2 =item dbName
97 :    
98 :     SQL name of the target database. If not specified, the default name is used.
99 :     This option allows you to specify dumping a backup or alternate database.
100 :    
101 : parrello 1.1 =back
102 :    
103 :     =cut
104 :    
105 :     # Get the command-line options and parameters.
106 :     my ($options, @parameters) = StandardSetup([qw(ERDB) ],
107 :     {
108 :     trace => ["2", "tracing level"],
109 :     loadDirectory => ["", "alternate load directory"],
110 : parrello 1.2 dbName => ["", "if specified, the SQL name of the target database"],
111 : parrello 1.1 phone => ["", "phone number (international format) to call when load finishes"]
112 :     },
113 :     "<database> <group1> <group2> ...",
114 :     @ARGV);
115 :     # Set a variable to contain return type information.
116 :     my $rtype;
117 :     # Create the statistics object.
118 :     my $stats = Stats->new();
119 :     my $myStartTime = time();
120 :     # Insure we catch errors.
121 :     eval {
122 :     # Get the positional parameters.
123 :     my ($database, @groups) = @parameters;
124 :     # Get the database.
125 :     Trace("Connecting to $database.") if T(2);
126 : parrello 1.2 my $erdb = ERDB::GetDatabase($database, undef, %$options);
127 : parrello 1.1 # Fix the group list.
128 :     my @realGroups = ERDBLoadGroup::ComputeGroups($erdb, \@groups);
129 :     # Compute the location of the load directory.
130 :     my $loadDirectory = $options->{loadDirectory} || $erdb->LoadDirectory();
131 :     # Loop through the groups.
132 :     for my $group (@realGroups) {
133 :     Trace("Processing load group $group.") if T(2);
134 :     # Get the list of tables for this group.
135 :     my @tables = ERDBLoadGroup::GetTables($erdb, $group);
136 :     # Loop through them.
137 :     for my $table (sort @tables) {
138 :     # Dump this table.
139 :     Trace("Dumping $table.") if T(3);
140 :     my $count = $erdb->DumpTable($table, $loadDirectory);
141 :     # Record its statistics.
142 :     $stats->Add($table => $count);
143 :     $stats->Add(records => $count);
144 :     $stats->Add(tables => 1);
145 :     }
146 :     # Record this group.
147 :     $stats->Add(groups => 1);
148 :     }
149 :     Trace("All groups processed.") if T(2);
150 :     };
151 :     if ($@) {
152 :     Trace("Script failed with error: $@") if T(0);
153 :     $rtype = "error";
154 :     } else {
155 :     Trace("Script complete.") if T(2);
156 :     $rtype = "no error";
157 :     }
158 :     # Display the run statistics.
159 :     $stats->Add(duration => (time() - $myStartTime));
160 :     Trace("Statistics for this run:\n" . $stats->Show()) if T(2);
161 :     if ($options->{phone}) {
162 :     my $msgID = Tracer::SendSMS($options->{phone}, "ERDBDumper terminated with $rtype.");
163 :     if ($msgID) {
164 :     Trace("Phone message sent with ID $msgID.") if T(2);
165 :     } else {
166 :     Trace("Phone message not sent.") if T(2);
167 :     }
168 :     }
169 :    
170 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3