ensembl-hive  2.7.0
db_cmd.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 
3 use strict;
4 use warnings;
5 
6  # Finding out own path in order to reference own components (including own modules):
7 use Cwd ();
8 use File::Basename ();
9 BEGIN {
10  $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) );
11  unshift @INC, $ENV{'EHIVE_ROOT_DIR'}.'/modules';
12 }
13 
14 use Getopt::Long qw(:config no_auto_abbrev);
15 use Pod::Usage;
16 
18 use Bio::EnsEMBL::Hive::Version ('report_versions');
19 
20 
21 sub main {
22  my ($reg_conf, $reg_type, $reg_alias, $executable, $url, @prepend, @append, $sqlcmd, $verbose, $help, $report_versions);
23 
24  GetOptions(
25  # connect to the database:
26  'reg_conf=s' => \$reg_conf,
27  'reg_type=s' => \$reg_type,
28  'reg_alias=s' => \$reg_alias,
29 
30  'exec|executable=s' => \$executable,
31  'url=s' => \$url,
32  'prepend=s@' => \@prepend,
33  'append|extra=s@' => \@append,
34  'sqlcmd|sql=s' => \$sqlcmd,
35 
36  'verbose!' => \$verbose,
37  'help!' => \$help,
38  'v|version|versions!' => \$report_versions,
39  ) or die "Error in command line arguments\n";
40 
41  my $dbc;
42 
43  if($help) {
44 
45  pod2usage({-exitvalue => 0, -verbose => 2});
46 
47  } elsif($report_versions) {
48 
49  report_versions();
50  exit(0);
51 
52  } elsif( not ($url xor $reg_alias) ) {
53  die "\nERROR: Connection parameters (url or reg_conf+reg_alias) need to be specified\n";
54 
55  } else {
57  -url => $url,
58  -reg_conf => $reg_conf,
59  -reg_type => $reg_type,
60  -reg_alias => $reg_alias,
61  -no_sql_schema_version_check => 1,
62  );
63 
64  $dbc = $dba->dbc;
65  }
66 
67  if (@append) {
68  warn qq{In db_cmd.pl, final arguments don't have to be declared with --append any more. All the remaining arguments are considered to be appended.\n};
69  }
70 
71  my @cmd = @{ $dbc->to_cmd( $executable, \@prepend, [@append, @ARGV], $sqlcmd ) };
72  $dbc->disconnect_if_idle;
73 
74  if( $verbose ) {
75  my $flat_cmd = join(' ', map { ($_=~/^-?\w+$/) ? $_ : "\"$_\"" } @cmd);
76 
77  warn "\nThe actual command I am running is:\n\t$flat_cmd\n\n";
78  }
79 
80  exec(@cmd);
81 }
82 
83 
84 main();
85 
86 __DATA__
87 
88 =pod
89 
90 =head1 NAME
91 
92 db_cmd.pl
93 
94 =head1 SYNOPSIS
95 
96  db_cmd.pl {-url <url> | [-reg_conf <reg_conf>] -reg_alias <reg_alias> [-reg_type <reg_type>] } [ -exec <alt_executable> ] [ -prepend <prepend_params> ] [ -sql <sql_command> ] [ -verbose ] [other arguments to append to the command line]
97 
98 =head1 DESCRIPTION
99 
100 db_cmd.pl is a generic script that connects you interactively to your database using either URL or Registry and optionally runs an SQL command.
101 
102 =head1 OPTIONS
103 
104 =over
105 
106 =item --url <url>
107 
108 URL defining where eHive database is located
109 
110 =item --reg_conf <path>
111 
112 path to a Registry configuration file
113 
114 =item --reg_alias <str>
115 
116 species/alias name for the eHive DBAdaptor
117 
118 =item --executable <name|path>
119 
120 The executable to run instead of the driver's default (which is the command-line client)
121 
122 =item --prepend <string>
123 
124 Argument that has to be prepended to the connection details. This option can be repeated
125 
126 =item --sql <string>
127 
128 SQL command to execute
129 
130 =item --verbose
131 
132 Print the command before running it.
133 
134 =item --help
135 
136 Print this help message
137 
138 =back
139 
140 All the remaining arguments are passed on to the command to be run.
141 If some of them start with a dash, first use a double-dash to indicate the end of db_cmd.pl's options and the start of the arguments that have to be passed as is (see the example below with --html)
142 
143 =head1 USAGE EXAMPLES
144 
145  db_cmd.pl -url "mysql://ensadmin:${ENSADMIN_PSW}@localhost:3306/" -sql 'CREATE DATABASE lg4_long_mult'
146  db_cmd.pl -url "mysql://ensadmin:${ENSADMIN_PSW}@localhost:3306/lg4_long_mult"
147  db_cmd.pl -url "mysql://ensadmin:${ENSADMIN_PSW}@localhost:3306/lg4_long_mult" -sql 'SELECT * FROM analysis_base' -- --html
148  db_cmd.pl -url "mysql://ensadmin:${ENSADMIN_PSW}@localhost/lg4_long_mult" -exec mysqldump -prepend -t analysis_base job
149 
150  db_cmd.pl -reg_conf ${ENSEMBL_CVS_ROOT_DIR}/ensembl-compara/scripts/pipeline/production_reg_conf.pl -reg_alias compara_master
151  db_cmd.pl -reg_conf ${ENSEMBL_CVS_ROOT_DIR}/ensembl-compara/scripts/pipeline/production_reg_conf.pl -reg_alias mus_musculus -reg_type core
152  db_cmd.pl -reg_conf ${ENSEMBL_CVS_ROOT_DIR}/ensembl-compara/scripts/pipeline/production_reg_conf.pl -reg_alias squirrel -reg_type core -sql 'SELECT * FROM coord_system'
153 
154 =head1 LICENSE
155 
156  See the NOTICE file distributed with this work for additional information
157  regarding copyright ownership.
158 
159  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
160  You may obtain a copy of the License at
161 
162  http://www.apache.org/licenses/LICENSE-2.0
163 
164  Unless required by applicable law or agreed to in writing, software distributed under the License
165  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166  See the License for the specific language governing permissions and limitations under the License.
167 
168 =head1 CONTACT
169 
170 Please subscribe to the eHive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss eHive-related questions or to be notified of our updates
171 
172 =cut
173 
Bio::EnsEMBL::Hive::DBSQL::DBAdaptor::new
public new()
Bio::EnsEMBL::Hive::Version
Definition: Version.pm:19
main
public main()
BEGIN
public BEGIN()
run
public run()
Bio::EnsEMBL::Hive::DBSQL::DBAdaptor
Definition: DBAdaptor.pm:31