summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-05-28 20:42:57 +0200
committerFlorian Pritz <bluewind@xinu.at>2017-05-28 20:42:57 +0200
commit636b361a019ab4e4b4f3960d2aeca33b7be7a8cb (patch)
tree568742918b653b5d0b084bd3be0ff53b4f08ca72 /lib
parent511041a2b76cea1f82686e221f28ce916e73ab4f (diff)
downloadApp-BorgRestore-636b361a019ab4e4b4f3960d2aeca33b7be7a8cb.tar.gz
App-BorgRestore-636b361a019ab4e4b4f3960d2aeca33b7be7a8cb.tar.xz
Add --adhoc
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/App/BorgRestore.pm23
-rw-r--r--lib/App/BorgRestore/Borg.pm23
-rw-r--r--lib/App/BorgRestore/Helper.pm9
3 files changed, 55 insertions, 0 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm
index fe4291f..87c1311 100644
--- a/lib/App/BorgRestore.pm
+++ b/lib/App/BorgRestore.pm
@@ -160,6 +160,28 @@ method find_archives($path) {
return \@ret;
}
+method get_all_archives() {
+ #my %seen_modtime;
+ my @ret;
+
+ $log->debugf("Fetching list of all archives");
+
+ my $archives = $self->{borg}->borg_list_time();
+
+ for my $archive (@$archives) {
+ push @ret, $archive;
+ }
+
+ if (!@ret) {
+ $log->errorf("No archives found.\n");
+ die "No archives found.\n";
+ }
+
+ @ret = sort { $a->{modification_time} <=> $b->{modification_time} } @ret;
+
+ return \@ret;
+}
+
method select_archive_timespec($archives, $timespec) {
my $seconds = $self->_timespec_to_seconds($timespec);
if (!defined($seconds)) {
@@ -323,6 +345,7 @@ method _handle_added_archives($borg_archives) {
my $line = shift;
# roll our own parsing of timestamps for speed since we will be parsing
# a huge number of lines here
+ # XXX: this also exists in BorgRestore::Helper::parse_borg_time()
# example timestamp: "Wed, 2016-01-27 10:31:59"
if ($line =~ m/^.{4} (?<year>....)-(?<month>..)-(?<day>..) (?<hour>..):(?<minute>..):(?<second>..) (?<path>.+)$/) {
my $time = POSIX::mktime($+{second},$+{minute},$+{hour},$+{day},$+{month}-1,$+{year}-1900);
diff --git a/lib/App/BorgRestore/Borg.pm b/lib/App/BorgRestore/Borg.pm
index c1774d7..660eb8e 100644
--- a/lib/App/BorgRestore/Borg.pm
+++ b/lib/App/BorgRestore/Borg.pm
@@ -3,6 +3,8 @@ use v5.10;
use warnings;
use strict;
+use App::BorgRestore::Helper;
+
use Function::Parameters;
use IPC::Run qw(run start new_chunker);
use Log::Any qw($log);
@@ -31,6 +33,27 @@ method borg_list() {
return \@archives;
}
+method borg_list_time() {
+ my @archives;
+
+ $log->debug("Getting archive list");
+ run [qw(borg list), $self->{borg_repo}], '>', \my $output or die "borg list returned $?";
+
+ for (split/^/, $output) {
+ if (m/^([^\s]+)\s+(.+)$/) {
+ my $time = App::BorgRestore::Helper::parse_borg_time($2);
+ if ($time) {
+ push @archives, {
+ "archive" => $1,
+ "modification_time" => $time,
+ };
+ }
+ }
+ }
+
+ return \@archives;
+}
+
method restore($components_to_strip, $archive_name, $path) {
$log->debugf("Restoring '%s' from archive %s, stripping %d components of the path", $path, $archive_name, $components_to_strip);
system(qw(borg extract -v --strip-components), $components_to_strip, $self->{borg_repo}."::".$archive_name, $path);
diff --git a/lib/App/BorgRestore/Helper.pm b/lib/App/BorgRestore/Helper.pm
index 976ef54..ec76926 100644
--- a/lib/App/BorgRestore/Helper.pm
+++ b/lib/App/BorgRestore/Helper.pm
@@ -19,6 +19,15 @@ fun format_timestamp($timestamp) {
return POSIX::strftime "%a. %F %H:%M:%S %z", localtime $timestamp;
}
+# XXX: this also exists in BorgRestore::_handle_added_archives()
+fun parse_borg_time($string) {
+ if ($string =~ m/^.{4} (?<year>....)-(?<month>..)-(?<day>..) (?<hour>..):(?<minute>..):(?<second>..)$/) {
+ my $time = POSIX::mktime($+{second},$+{minute},$+{hour},$+{day},$+{month}-1,$+{year}-1900);
+ return $time;
+ }
+ return;
+}
+
1;
__END__