summaryrefslogtreecommitdiffstats
path: root/lib/App/BorgRestore/Borg.pm
blob: 426f8090c0a403602751f47707dcfc9d39c6cae2 (plain)
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
package App::BorgRestore::Borg;
use v5.10;
use warnings;
use strict;

use IPC::Run qw(run start);

sub borg_list {
	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 $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 $archive = shift;
	my $fh = shift;

	return start [qw(borg list --list-format), '{isomtime} {path}{NEWLINE}', "::".$archive], ">pipe", $fh;
}

1;

__END__