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
|
package App::BorgRestore::Borg;
use v5.10;
use warnings;
use strict;
use IPC::Run qw(run start new_chunker);
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub borg_list {
my $self = shift;
my @archives;
run [qw(borg list)], '>', \my $output or die "borg list returned $?";
for (split/^/, $output) {
if (m/^([^\s]+)\s/) {
push @archives, $1;
}
}
return \@archives;
}
sub restore {
my $self = shift;
my $components_to_strip = shift;
my $archive_name = shift;
my $path = shift;
system(qw(borg extract -v --strip-components), $components_to_strip, "::".$archive_name, $path);
}
sub list_archive {
my $self = shift;
my $archive = shift;
my $cb = shift;
open (my $fh, '-|', 'borg', qw/list --list-format/, '{isomtime} {path}{NEWLINE}', "::".$archive);
while (<$fh>) {
$cb->($_);
}
# this is slow
#return start [qw(borg list --list-format), '{isomtime} {path}{NEWLINE}', "::".$archive], ">", new_chunker, $cb;
#$proc->finish() or die "borg list returned $?";
}
1;
__END__
|