aboutsummaryrefslogtreecommitdiff
path: root/lib/App/Beam/Restore.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App/Beam/Restore.pm')
-rw-r--r--lib/App/Beam/Restore.pm85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/App/Beam/Restore.pm b/lib/App/Beam/Restore.pm
new file mode 100644
index 0000000..7e3129a
--- /dev/null
+++ b/lib/App/Beam/Restore.pm
@@ -0,0 +1,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;
+
+
+

Return to:

Send suggestions and report system problems to the System administrator.