2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 cleanup_tmp_tables.pl -
delete temporary and backup tables from a database
24 ./cleanup_tmp_tables.pl [arguments]
26 ./cleanup_tmp_tables.pl --nolog --host localhost --port 3306 --user user --dbname DB --dry_run
28 ./cleanup_tmp_tables.pl --nolog --host localhost --port 3306 --user user --dbname
'%mydbs%' --dry_run
30 ./cleanup_tmp_tables.pl --nolog --host localhost --port 3306 --user user --dbname DB --interactive 0
34 --dbname, db_name=NAME database name NAME (can be a pattern)
35 --host, --dbhost, --db_host=HOST database host HOST
36 --port, --dbport, --db_port=PORT database port PORT
37 --user, --dbuser, --db_user=USER database username USER
38 --pass, --dbpass, --db_pass=PASS database passwort PASS
42 --mart Indicates we wish to search
for mart
43 temporary tables which are normally
45 ONLY RUN IF YOU ARE A MEMBER OF
48 --conffile, --conf=FILE read parameters from FILE
49 (
default: conf/Conversion.ini)
51 --logfile, --log=FILE log to FILE (
default: *STDOUT)
52 --logpath=PATH write logfile to PATH (
default: .)
53 --logappend, --log_append append to logfile (
default: truncate)
55 -v, --verbose=0|1 verbose logging (
default:
false)
56 -i, --interactive=0|1
run script interactively (
default:
true)
57 -n, --dry_run, --dry=0|1 don
't write results to database
58 -h, --help, -? print help (this message)
62 A script which looks for any table which we believe could be a temporary
63 table. This means any table which contains
71 =item MTMP_ (only used when --mart is specified)
75 You can run this over multiple DBs but caution is advised
84 Please post comments/questions to the Ensembl development list
85 <http://lists.ensembl.org/mailman/listinfo/dev>
91 no warnings 'uninitialized
';
94 use vars qw($SERVERROOT);
97 $SERVERROOT = "$Bin/../..";
98 unshift(@INC, "$SERVERROOT/ensembl/modules");
99 unshift(@INC, "$SERVERROOT/bioperl-live");
104 use Bio::EnsEMBL::Utils::ConversionSupport;
108 my $support = new Bio::EnsEMBL::Utils::ConversionSupport($SERVERROOT);
111 $support->parse_common_options(@_);
112 $support->parse_extra_options(qw/mart!/);
113 $support->allowed_params(
114 $support->get_common_params, 'mart
'
117 if ($support->param('help
') or $support->error) {
118 warn $support->error if $support->error;
122 # ask user to confirm parameters to proceed
123 $support->confirm_params;
125 # get log filehandle and print heading and parameters to logfile
128 $support->check_required_params;
132 # connect to database
134 my $original_dbname = $support->param('dbname
');
135 if($original_dbname =~ /%/) {
136 $support->param('dbname
', q{});
137 $dbh = $support->get_dbconnection('');
138 my $ref = $dbh->selectall_arrayref('show databases like ?
', {}, $original_dbname);
139 push(@databases, map {$_->[0]} @{$ref})
142 $dbh = $support->get_dbconnection('');
143 push(@databases, $original_dbname);
146 my @patterns = map { '%\\_
'.$_.'%
' } qw/bak backup/;
147 if($support->param('mart
')) {
148 if($support->user_proceed('--mart was specified on the command line. Do not
run this during a mart build. Do you wish to
continue?
')) {
149 push(@patterns, 'MTMP\\_%
');
153 foreach my $db (@databases) {
155 $support->log('Switching to
'.$db."\n");
156 $dbh->do('use
'.$db);
157 foreach my $pattern (@patterns) {
158 my $ref = $dbh->selectall_arrayref('show tables like ?
', {}, $pattern);
159 $tables{$_->[0]} = 1 for @{$ref};
162 my @tables = sort keys %tables;
164 if ($support->param('dry_run
')) {
165 # for a dry run, only show which databases would be deleted
166 if(scalar(@tables) > 0) {
167 $support->log("Temporary and backup tables found:\n");
168 foreach my $table (@tables) {
169 $support->log("$table\n", 1);
175 foreach my $table (@tables) {
176 if ($support->user_proceed("Drop table $table?")) {
177 $support->log("Dropping table $table...\n");
178 $dbh->do("DROP TABLE $table");
179 $support->log("Done.\n");
185 $support->finish_log;