summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-02-27 10:33:55 +0100
committerFlorian Pritz <bluewind@xinu.at>2017-02-27 10:33:55 +0100
commitdf777475af4694cfc5489ccb29a75a7789a29df6 (patch)
treed43f79380b4ebbc1e633660b2be0e39fcd15f01c /lib
parent82bdef1a323fc46ad8499ccd17d3c255200696d4 (diff)
downloadApp-BorgRestore-df777475af4694cfc5489ccb29a75a7789a29df6.tar.gz
App-BorgRestore-df777475af4694cfc5489ccb29a75a7789a29df6.tar.xz
Extract borg related methods into dedicated package
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/App/BorgRestore/Borg.pm39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/App/BorgRestore/Borg.pm b/lib/App/BorgRestore/Borg.pm
new file mode 100644
index 0000000..426f809
--- /dev/null
+++ b/lib/App/BorgRestore/Borg.pm
@@ -0,0 +1,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__