Guest User

Untitled

a guest
Aug 10th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # Move a catalog database to a different database server
  3. use strict;
  4. use lib '/opt/platform/interchange_hosting';
  5. use lib '..';
  6. use ZesCatalog;
  7. use Data::Dumper;
  8. use Getopt::Long;
  9.  
  10. my ($ignore_nomove);
  11. GetOptions( 'ignore-nomove' => \$ignore_nomove );
  12.  
  13.  
  14. my ($server, $user, $pass, $catalog) = @ARGV;
  15. die "Usage: $0 dest_server dest_server_admin_user dest_server_admin_pass catalog_name
  16. eg $0 zesdb3.zeald.com zeald xxxxxx mycatalog
  17.  
  18. $0 <catalog>
  19. Note the script requires the ability to connect directly to the dest_server & the server on which the
  20. database is currently running , and that the catalog dir be accessable locally
  21. (ie you should run it from a node on the cluster the site is running on currently)
  22.  
  23.  
  24. You can mova site to the current server's db cluster by using the shorthand version:
  25. $0 <catalog>
  26.  
  27. " unless $server;
  28.  
  29. my $api = new ZealdCluster;
  30. my @servers = @{$api->get_cluster_resources($api->{cluster_id}, 'mysql')};
  31.  
  32. if (!$user) {
  33. $user = $api->{db_user};
  34. $pass = $api->{db_pass};
  35. $catalog = $server;
  36. # $server = $api->get_database_server;
  37. $server = $servers[rand @servers]->{details};
  38. }
  39.  
  40. my $catalog = new ZesCatalog $catalog;
  41. my $catalog_name = $catalog->{catalog_name};
  42.  
  43. my $db_params = $catalog->get_database_params;
  44.  
  45. if (!$ignore_nomove && ( $catalog->{no_move} )) {
  46. print qq|This site has the "no_move" flag set, indicating that it shouldn't be moved because of customisations
  47.  
  48. The notes may explain more about why this is:
  49. $catalog->{notes}
  50.  
  51. You can override this message with --ignore-nomove option
  52. |;
  53. die;
  54. }
  55.  
  56. my $catdir = "/srv/ic-catalogs/$catalog_name";
  57. die "Catalog directory $catdir doesn't exist" if ! -e $catdir;
  58.  
  59. #Is the database server in question this server?
  60. if ($server eq $db_params->{server} || grep {$_->{details} eq $db_params->{server}} @servers ) {
  61. print "comp1: $server \n";
  62. print "comp2: $db_params->{server} \n";
  63. print "comp3: $_->{details} \n";
  64. print "comp4: \n";
  65. print Dumper(@servers);
  66. print "This database $db_params->{database} from $db_params->{server} is already running on a server for this cluster, $server\n";
  67. exit(0);
  68. }
Add Comment
Please, Sign In to add comment