aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2017-03-13 08:12:59 +0200
committerSergey Poznyakoff <gray@gnu.org>2017-03-13 08:12:59 +0200
commita80525354251593ba4b6830a5da32b0b04b1d518 (patch)
tree6a1664ff99dca1420c38b5eac1d7b2610c9b121a
parent128581c81abe27cc204e7373822dcb7afd560fb3 (diff)
downloadbeam-a80525354251593ba4b6830a5da32b0b04b1d518.tar.gz
beam-a80525354251593ba4b6830a5da32b0b04b1d518.tar.bz2
Keep file names in the history.
Each backup method takes an additional argument - a history item object - and is supposed to store there the names of the files it created. This information will then be used when expiring backups and, eventually, when restoring from them. * lib/App/Beam/Backend/Tar.pm (backup): Take Item object as the 2nd parameter. Add names of the created file to it. * lib/App/Beam/Backup.pm (run): Pass the Item object to the backend method. * lib/App/Beam/History/Item.pm: New file. * lib/App/Beam/History/Record.pm (begin_entry): Rename to begin_item (entries): Rename to items. (entry_names): Rename to item_names. (finish_entry): Rename to finish_item. * lib/App/Beam/List.pm (run): List file names in verbose mode.
-rw-r--r--lib/App/Beam/Backend/Tar.pm21
-rw-r--r--lib/App/Beam/Backup.pm16
-rw-r--r--lib/App/Beam/History/Item.pm36
-rw-r--r--lib/App/Beam/History/Record.pm30
-rw-r--r--lib/App/Beam/List.pm5
5 files changed, 75 insertions, 33 deletions
diff --git a/lib/App/Beam/Backend/Tar.pm b/lib/App/Beam/Backend/Tar.pm
index f469485..92011b0 100644
--- a/lib/App/Beam/Backend/Tar.pm
+++ b/lib/App/Beam/Backend/Tar.pm
@@ -122,35 +122,38 @@ sub mksnapshot {
}
sub backup {
- my ($self, $item) = @_;
+ my ($self, $name, $item) = @_;
- my $basename = $self->{beam}->format_name($item);
+ my $basename = $self->{beam}->format_name($name);
croak "undefined basename" unless defined $basename;
my $archive = $self->get('core', 'archivedir')
. '/'
. $basename
. '.'
. $self->get('backend', 'tar', 'suffix');
-
+
my $cmd = new App::Beam::Command($self->get('backend', 'tar', 'binary'));
$cmd->set_logger(CHAN_STDERR, sub { $self->logger('err', $_) });
if ($self->isset('backend', 'tar', 'options')) {
$cmd->add($self->get('backend', 'tar', 'options'));
}
- if ($self->isset('item', $item, 'options')) {
- $cmd->add($self->get('item', $item, 'options'));
+ if ($self->isset('item', $name, 'options')) {
+ $cmd->add($self->get('item', $name, 'options'));
}
$cmd->add('-c');
$cmd->add('-f', $archive);
- $cmd->add('-C', $self->get('item', $item, 'directory'));
- $cmd->add('--listed', $self->mksnapshot($item));
+ $cmd->add('-C', $self->get('item', $name, 'directory'));
+ my $snar = $self->mksnapshot($name);
+ $cmd->add('--listed', $snar);
- if ($self->isset('item', $item, 'files')) {
- $cmd->add($self->get('item', $item, 'files'));
+ if ($self->isset('item', $name, 'files')) {
+ $cmd->add($self->get('item', $name, 'files'));
} else {
$cmd->add('.');
}
+ $item->add($archive, $snar);
+
$self->debug(2, "running ".$cmd->command_line);
my $ret = STATE_SUCCESS;
unless ($self->dry_run) {
diff --git a/lib/App/Beam/Backup.pm b/lib/App/Beam/Backup.pm
index e10fd2a..668db1e 100644
--- a/lib/App/Beam/Backup.pm
+++ b/lib/App/Beam/Backup.pm
@@ -62,18 +62,18 @@ sub run {
$self->{history}->drop;
$self->{history}->top->reset;
}
- my @items = $self->check_items(@_);
+ my @item_names = $self->check_items(@_);
$self->debug(1,
($redo ? "recreating backup " : "creating backup ")
. $self->format_name);
- foreach my $item (@items) {
- $self->debug(1, "backing up $item");
- my $backend = $self->{backend}{$self->get("item.$item.backend")};
- $self->{history}->top->begin_entry($item);
- my $ret = $backend->backup($item);
- $self->{history}->top->finish_entry($item, $ret);
+ foreach my $name (@item_names) {
+ $self->debug(1, "backing up $name");
+ my $backend = $self->{backend}{$self->get("item.$name.backend")};
+ my $item = $self->{history}->top->begin_item($name);
+ my $ret = $backend->backup($name, $item);
+ $self->{history}->top->finish_item($name, $ret);
$self->update_status($ret);
- $self->debug(1, "$item: " . state_string($ret));
+ $self->debug(1, "$name: " . state_string($ret));
}
}
diff --git a/lib/App/Beam/History/Item.pm b/lib/App/Beam/History/Item.pm
new file mode 100644
index 0000000..3a30f61
--- /dev/null
+++ b/lib/App/Beam/History/Item.pm
@@ -0,0 +1,36 @@
+package App::Beam::History::Item;
+
+require App::Beam::History::Entry;
+our @ISA = qw(App::Beam::History::Entry);
+
+use strict;
+use Carp;
+
+sub new {
+ my $class = shift;
+ my $self = $class->SUPER::new;
+ $self->{files} = [];
+ return $self;
+}
+
+sub add {
+ my $self = shift;
+ push @{$self->{files}}, @_;
+}
+
+sub del {
+ my $self = shift;
+ my %h;
+ @h{@_} = 1 x @_;
+ @{$self->{files}} = grep { ! exists $h{$_} } @{$self->{files}};
+}
+
+sub files {
+ my $self = shift;
+ return @{$self->{files}};
+}
+
+sub is_empty {
+ my $self = shift;
+ return $#{$self->{files}} == -1;
+}
diff --git a/lib/App/Beam/History/Record.pm b/lib/App/Beam/History/Record.pm
index 2754e04..ce940fe 100644
--- a/lib/App/Beam/History/Record.pm
+++ b/lib/App/Beam/History/Record.pm
@@ -3,6 +3,7 @@ package App::Beam::History::Record;
use strict;
use Carp;
use App::Beam::History::Entry qw(:state);
+use App::Beam::History::Item;
our @ISA = qw(App::Beam::History::Entry);
@@ -109,37 +110,38 @@ sub end_time {
return $self->SUPER::end_time;
}
-sub begin_entry {
+sub begin_item {
my ($self, $name) = @_;
- croak "can't add entry to a finished record"
+ croak "can't add item to a finished record"
unless $self->{state} == STATE_PENDING;
- my $entry = new App::Beam::History::Entry;
- $self->{detail}{$name} = $entry;
- if ($entry->start_time > $self->{end_time}) {
- $self->{end_time} = $entry->start_time;
+ my $item = new App::Beam::History::Item;
+ $self->{detail}{$name} = $item;
+ if ($item->start_time > $self->{end_time}) {
+ $self->{end_time} = $item->start_time;
}
+ return $item;
}
-sub entries {
+sub items {
my ($self) = @_;
return %{$self->{detail}};
}
-sub entry_names {
+sub item_names {
my ($self) = @_;
return keys %{$self->{detail}};
}
-sub finish_entry {
+sub finish_item {
my ($self, $name, $state) = @_;
croak "can't modify item in a finished record"
unless $self->{state} == STATE_PENDING;
- croak "no such entry"
+ croak "no such item"
unless exists $self->{detail}{$name};
- my $entry = $self->{detail}{$name};
- $entry->state($state);
- if ($entry->end_time > $self->{end_time}) {
- $self->{end_time} = $entry->end_time;
+ my $item = $self->{detail}{$name};
+ $item->state($state);
+ if ($item->end_time > $self->{end_time}) {
+ $self->{end_time} = $item->end_time;
}
}
diff --git a/lib/App/Beam/List.pm b/lib/App/Beam/List.pm
index 018f7e3..fefbfa0 100644
--- a/lib/App/Beam/List.pm
+++ b/lib/App/Beam/List.pm
@@ -84,10 +84,11 @@ sub run {
$rec->state_name);
print "\n";
if ($verbose) {
- my %ent = $rec->entries;
+ my %ent = $rec->items;
foreach my $item (split /\s+/, $self->get('core.items')) {
if (exists($ent{$item})) {
- printf("# %-24s %s\n", $item, $ent{$item}->state_name);
+ printf("# %-24s %s %s\n", $item, $ent{$item}->state_name,
+ join(',', $ent{$item}->files));
delete $ent{$item};
}
}

Return to:

Send suggestions and report system problems to the System administrator.