Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Move a catalog database to a different database server
- use strict;
- use lib '/opt/platform/interchange_hosting';
- use lib '..';
- use ZesCatalog;
- use Data::Dumper;
- use Getopt::Long;
- my ($ignore_nomove);
- GetOptions( 'ignore-nomove' => \$ignore_nomove );
- my ($server, $user, $pass, $catalog) = @ARGV;
- die "Usage: $0 dest_server dest_server_admin_user dest_server_admin_pass catalog_name
- eg $0 zesdb3.zeald.com zeald xxxxxx mycatalog
- $0 <catalog>
- Note the script requires the ability to connect directly to the dest_server & the server on which the
- database is currently running , and that the catalog dir be accessable locally
- (ie you should run it from a node on the cluster the site is running on currently)
- You can mova site to the current server's db cluster by using the shorthand version:
- $0 <catalog>
- " unless $server;
- my $api = new ZealdCluster;
- my @servers = @{$api->get_cluster_resources($api->{cluster_id}, 'mysql')};
- if (!$user) {
- $user = $api->{db_user};
- $pass = $api->{db_pass};
- $catalog = $server;
- # $server = $api->get_database_server;
- $server = $servers[rand @servers]->{details};
- }
- my $catalog = new ZesCatalog $catalog;
- my $catalog_name = $catalog->{catalog_name};
- my $db_params = $catalog->get_database_params;
- if (!$ignore_nomove && ( $catalog->{no_move} )) {
- print qq|This site has the "no_move" flag set, indicating that it shouldn't be moved because of customisations
- The notes may explain more about why this is:
- $catalog->{notes}
- You can override this message with --ignore-nomove option
- |;
- die;
- }
- my $catdir = "/srv/ic-catalogs/$catalog_name";
- die "Catalog directory $catdir doesn't exist" if ! -e $catdir;
- #Is the database server in question this server?
- if ($server eq $db_params->{server} || grep {$_->{details} eq $db_params->{server}} @servers ) {
- print "comp1: $server \n";
- print "comp2: $db_params->{server} \n";
- print "comp3: $_->{details} \n";
- print "comp4: \n";
- print Dumper(@servers);
- print "This database $db_params->{database} from $db_params->{server} is already running on a server for this cluster, $server\n";
- exit(0);
- }
Add Comment
Please, Sign In to add comment