Guest User

Untitled

a guest
Feb 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use Mojo::Base -base;
  4.  
  5. use lib 'lib';
  6.  
  7. use DateTime;
  8. use Mojo::URL;
  9. use Mojo::UserAgent;
  10. use Mojo::Util 'dumper';
  11. use Mutex;
  12. use RG::LibrariesConfig;
  13.  
  14. my $instance='charter_se';
  15.  
  16. my $config=RG::LibrariesConfig->new;
  17. my $ua = Mojo::UserAgent->new();
  18.  
  19. my $solr_config=$config->get('RG::Engine::Solr');
  20. INSTANCE: for my $instance (keys %{ $solr_config->{instance} }) {
  21. my $mutex = Mutex->new(path => "/tmp/".$instance.".flock");
  22. #unlock on ctrl-c/kill.
  23. $SIG{'INT'} = sub { $mutex->unlock; exit; };
  24.  
  25. $mutex->lock;
  26. warn "Backing up $instance";
  27. sleep(60);
  28. my $url=Mojo::URL->new($solr_config->{instance}{$instance}{url});
  29. $url->path('/admin/collections')->query(action => 'BACKUP', collection=>$instance, name => $instance.'-'. async => 1337);
  30. my $res=$ua->get($url)->res;
  31. if(!$res->is_success) {
  32. warn "Backup failed:" .$res->body;
  33. $mutex->unlock && exit 1;
  34. }
  35. my $attempts=0;
  36. $url->query(action=>'REQUESTSTATUS', requestid => 1337);
  37. my $reason='Unknown';
  38. ATTEMPT: while($attempts++) {
  39. sleep(30);
  40. my $status_res=$ua->get($url);
  41. if(!$res->is_success) {
  42. $reason=$status_res->body;
  43. last ATTEMPT;
  44. }
  45. if($attempts>240) {
  46. $reason="Took too long (more than 2 hours)";
  47. last ATTEMPT;
  48. }
  49. next INSTANCE if $status_res->dom('[name=state]')->text eq 'completed';
  50. }
  51.  
  52. warn "Backup failed: " .$reason;
  53. $mutex->unlock;
  54. exit 1;
  55. }
  56. exit 0;
Add Comment
Please, Sign In to add comment