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.
18 # this script will lokk through all listed databases for
19 # database names which match given regexp.
20 # This version should be ok if one or more of the given database
21 # servers is not available.
29 # seconds before we give up on database
32 my @all_locators = qw {
33 genebuild1:3306:ensro::
34 genebuild2:3306:ensro::
35 genebuild3:3306:ensro::
36 genebuild4:3306:ensro::
37 genebuild5:3306:ensro::
38 genebuild6:3306:ensro::
39 genebuild6:3307:ensro::
48 ens-genomics1:3306:ensro::
49 ens-genomics2:3306:ensro::
51 ens-research:3306:ensro::
52 ens-research:3309:ensro::
54 ensdb-1-11:3319:ensro::
55 ensdb-1-11:3317:ensro::
57 ens-staging:3306:ensro::
58 ens-livemirror:3306:ensro::
72 printf(
"You need to supply a regexp as argument.\n" );
73 printf(
"Use -list if you want to see which databases are configured.\n" );
74 printf(
"If you have any parameters after the regexp, the program will print\n" );
75 printf(
" database sizes as well.\n" );
76 printf(
"\nExample: search_dbs.pl \"^stabenau\" -sizes | sort -knr3\n" );
82 if( $pattern eq
"-list" ) {
87 for my $loc ( @all_locators ) {
88 my @elems = split(
":", $loc );
91 my $dsn = sprintf(
"DBI:mysql:host=%s;port=%s", $elems[0], $elems[1] );
93 $SIG{ALRM} = sub{die(
"timeout");};
97 my $db = DBI->connect( $dsn, $elems[2], $elems[3], { RaiseError => 1 } );
98 my $res = $db->selectall_arrayref(
"show databases" );
99 @dbnames =
map { $_->[0] } @$res;
105 print STDERR
"$loc NOT OK\n";
108 for my $dbname ( @dbnames ) {
109 if( $dbname =~ /$pattern/ ) {
112 my $db = DBI->connect( $dsn, $elems[2], $elems[3], { RaiseError => 1, PrintError=> 0 } );
113 $db->do(
"use $dbname" );
114 my $t_status = $db->selectall_arrayref(
"show table status" );
116 map { $size += $_->[6]; $size += $_->[8] } @$t_status;
117 print
"$loc $dbname $size\n";
122 print(
"Problem on $loc $dbname.\n ", $@ );
128 print STDERR
"$loc ok\n";
130 for my $dbname ( @dbnames ) {
131 if( $dbname =~ /$pattern/ ) {
132 print
"$loc $dbname\n";