1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
package App::Beam::Restore;
use strict;
use Carp;
require App::Beam;
our @ISA = qw(App::Beam);
use Unix::Sysexits;
use App::Beam;
use App::Beam::History::Entry qw(:state);
use Getopt::Long qw(GetOptionsFromArray);
=head1 NAME
beam restore - restore from a backup
=head1 SYNOPSIS
B<beam> [I<OPTIONS>] B<restore> [I<ITEM>...]
=head1 DESCRIPTION
To be written...
=cut
sub find_index {
my ($self, $cycle, $round, $level) = @_;
my @comp;
push @comp, sub { $_->cycle == $cycle } if defined $cycle;
push @comp, sub { $_->round == $round } if defined $round;
push @comp, sub { $_->level == $level } if defined $level;
my $index = 1;
return $index unless @comp;
OUTER:
for (; my $rec = $self->{history}->top($index); $index++) {
local $_ = $rec;
foreach my $c (@comp) {
next OUTER unless &{$c};
}
return $index;
}
return undef;
}
sub run {
my $self = shift;
my ($index, $cycle, $round, $level);
my $force;
GetOptionsFromArray(\@_,
"number|N=n" => \$index,
"level|l=n" => \$level,
"round|r=n" => \$round,
"cycle|c=n" => \$cycle,
"force|f" => \$force
) or exit(EX_USAGE);
my @items = $self->check_items(@_);
if (defined($index)) {
$self->abend(EX_USAGE,
"--index can't be used together with --cycle, --round, or --level")
if defined($cycle) || defined($round) || defined($level);
} else {
$index = $self->find_index($cycle, $round, $level);
$self->abend(EX_USAGE, "matching backup not found")
unless defined $index;
}
$self->debug(1, "restoring from backup $index");
$self->abend(EX_UNAVAILABLE, "backup $index was not successful")
unless $self->{history}->top($index)->state == STATE_SUCCESS;
foreach my $item (@items) {
my $backend = $self->{backend}{$self->get("item.$item.backend")};
$backend->restore($index, $item);
}
}
1;
|