Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use Mojo::Base -base;
- use lib 'lib';
- use DateTime;
- use Mojo::URL;
- use Mojo::UserAgent;
- use Mojo::Util 'dumper';
- use Mutex;
- use RG::LibrariesConfig;
- my $instance='charter_se';
- my $config=RG::LibrariesConfig->new;
- my $ua = Mojo::UserAgent->new();
- my $solr_config=$config->get('RG::Engine::Solr');
- INSTANCE: for my $instance (keys %{ $solr_config->{instance} }) {
- my $mutex = Mutex->new(path => "/tmp/".$instance.".flock");
- #unlock on ctrl-c/kill.
- $SIG{'INT'} = sub { $mutex->unlock; exit; };
- $mutex->lock;
- warn "Backing up $instance";
- sleep(60);
- my $url=Mojo::URL->new($solr_config->{instance}{$instance}{url});
- $url->path('/admin/collections')->query(action => 'BACKUP', collection=>$instance, name => $instance.'-'. async => 1337);
- my $res=$ua->get($url)->res;
- if(!$res->is_success) {
- warn "Backup failed:" .$res->body;
- $mutex->unlock && exit 1;
- }
- my $attempts=0;
- $url->query(action=>'REQUESTSTATUS', requestid => 1337);
- my $reason='Unknown';
- ATTEMPT: while($attempts++) {
- sleep(30);
- my $status_res=$ua->get($url);
- if(!$res->is_success) {
- $reason=$status_res->body;
- last ATTEMPT;
- }
- if($attempts>240) {
- $reason="Took too long (more than 2 hours)";
- last ATTEMPT;
- }
- next INSTANCE if $status_res->dom('[name=state]')->text eq 'completed';
- }
- warn "Backup failed: " .$reason;
- $mutex->unlock;
- exit 1;
- }
- exit 0;
Add Comment
Please, Sign In to add comment