CreateFile4CopyDBoverServer.pl 3 KB
Newer Older
1
#!/usr/bin/env perl
2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright [1999-2013] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

16 17 18 19 20 21
##########################################
#
# Simple but handy script that generate the input file
# neded by the script CopyDBoverServer.pl
#
# Please post comments/questions to the Ensembl development list
Magali Ruffier's avatar
Magali Ruffier committed
22
# <http://lists.ensembl.org/mailman/listinfo/dev>
23 24 25
#
#########################################
use strict;
26
use warnings;
27 28 29 30 31 32 33 34 35 36 37
use DBI;
use Getopt::Long;

my $help= 0;
my $sourceHost="ens-staging";
my $sourcePort="3306";
my $sourceUser="";
my $sourcePwd="";
my $destinationHost="mart2";
my $destinationPort="3306";
my $limit='';
38
my $target_location = '';
39 40 41 42 43 44 45 46 47

my $usage = "\nUsage: $0 -sourceHost mart1 -sourceUser xxx -destinationHost mart2  -limit %42%\n
  -help or -h      [for help]

  -sourceHost      [default: ens-staging]
  -sourcePort      [default: 3306       ]
  -sourceUser      [default:            ]
  -destinationHost [default: mart2      ]
  -destinationPort [default: 3306       ]
48 49
  -limit           [eg. %core_42%       ]
  -target_location [default: blank if you want standard data locations]\n
50 51 52 53 54 55 56 57 58 59 60 61

The limit option will limit the databases being copied according to your limit criteria. 
With   -limit %core_42%   only ensembl core 42 databases will be copied\n\n
";

GetOptions('help|h' => \$help,
			 'sourceHost=s' => \$sourceHost,
			 'sourcePort=s' => \$sourcePort,
			 'sourceUser=s' => \$sourceUser,
			 'sourcePwd=s' => \$sourcePwd,
			 'destinationHost=s' => \$destinationHost,
			 'destinationPort=s' => \$destinationPort,
62
			 'target_location=s' => \$target_location,
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
			 'limit=s' => \$limit);

if ($help || scalar @ARGV == 0 ) {
#if ($help) {
    print $usage;
  exit 0;
}
#--------------connect to MySQL Source Host
my $dbh   = DBI->connect ("DBI:mysql:host=$sourceHost:port=$sourcePort",
                          $sourceUser,
                          $sourcePwd)
    or die "Can\'t connect to database: $DBI::errstr\n";

#--------------prepare and execute the query
my $sql;
if (!$limit){
    $sql = "show databases ;";
}else {
    $sql = "show databases like \"".$limit."\" ;";
}

my $sth = $dbh->prepare( $sql);

$sth->execute( );
while ( my @row = $sth->fetchrow ){
    
    my $result = sprintf ("%s %d %50s %s %d %s",$sourceHost.".internal.sanger.ac.uk", $sourcePort, $row[0], $destinationHost.".internal.sanger.ac.uk ", $destinationPort, $row[0]);
90
    $result .= "  $target_location" if $target_location;
91 92 93 94 95
    print $result . "\n";
    
}

$sth->finish( );