diff --git a/lib/Simba/CA.pm b/lib/Simba/CA.pm index 8459dfc..cd159ac 100644 --- a/lib/Simba/CA.pm +++ b/lib/Simba/CA.pm @@ -207,7 +207,9 @@ sub run { sub backup2disk { my ($self, $target) = @_; - $self->reserve_fileset($target); + unless ($self->reserve_fileset($target)) { + return; + } $self->log(3, "starting backup for target host " . $target->{host} . " dir " . $target->{dir}); $self->{target} = $target; @@ -291,9 +293,10 @@ sub backup2disk { sub reserve_fileset { my ($self, $target) = @_; - for (;;) { + my $start = time(); + while (time() - $start < 3600) { my $rows = $self->{dbh}->do(q{update filesets set pid=? where id = ? and pid is null}, {}, $$, $target->{id}); - return if $rows == 1; + return 1 if $rows == 1; my $pid = $self->{dbh}->selectrow_array(q{select pid from filesets where id = ?}, {}, $target->{id}); $self->log(3, "fileset $target->{id} appears to be in use by pid $pid"); if (!kill(0, $pid) && $!{ESRCH}) { @@ -302,6 +305,8 @@ sub reserve_fileset { } sleep 60; } + $self->log(2, "fileset $target->{id} appears to be still in use by pid $pid after grace perion - giving up"); + return 0; }