diff options
-rw-r--r-- | META.json | 3 | ||||
-rw-r--r-- | cpanfile | 3 | ||||
-rw-r--r-- | lib/App/BorgRestore/Borg.pm | 39 |
3 files changed, 33 insertions, 12 deletions
@@ -45,12 +45,14 @@ "requires" : { "DBD::SQLite" : "0", "DBI" : "0", + "Date::Parse" : "0", "File::Path" : "0", "File::Temp" : "0", "File::pushd" : "0", "Function::Parameters" : "0", "Getopt::Long" : "0", "IPC::Run" : "0", + "JSON" : "0", "List::Util" : "0", "Log::Any" : "0", "Log::Any::Adapter::Log4perl" : "0", @@ -60,6 +62,7 @@ "Log::Log4perl::Layout::PatternLayout" : "0", "Log::Log4perl::Level" : "0", "Pod::Usage" : "0", + "Version::Compare" : "0", "autodie" : "0", "perl" : "v5.14.0" } @@ -17,6 +17,9 @@ requires 'Log::Log4perl::Level'; requires 'Pod::Usage'; requires 'autodie'; requires 'perl', 'v5.14.0'; +requires 'Version::Compare'; +requires 'JSON'; +requires 'Date::Parse'; on configure => sub { requires 'Devel::CheckBin'; diff --git a/lib/App/BorgRestore/Borg.pm b/lib/App/BorgRestore/Borg.pm index 9807700..bd9ac3c 100644 --- a/lib/App/BorgRestore/Borg.pm +++ b/lib/App/BorgRestore/Borg.pm @@ -6,9 +6,12 @@ use strict; use App::BorgRestore::Helper; use autodie; +use Date::Parse; use Function::Parameters; use IPC::Run qw(run start new_chunker); +use JSON; use Log::Any qw($log); +use Version::Compare; =encoding utf-8 @@ -66,18 +69,30 @@ method borg_list() { method borg_list_time() { my @archives; - $log->debug("Getting archive list"); - run [qw(borg list), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n"; - - for (split/^/, $output) { - # example timestamp: "Wed, 2016-01-27 10:31:59" = 24 chars - if (m/^([^\s]+)\s+(.{24})/) { - my $time = App::BorgRestore::Helper::parse_borg_time($2); - if ($time) { - push @archives, { - "archive" => $1, - "modification_time" => $time, - }; + if (Version::Compare::version_compare($self->{borg_version}, "1.1") >= 0) { + $log->debug("Getting archive list via json"); + run [qw(borg list --json), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n"; + my $json = decode_json($output); + for my $archive (@{$json->{archives}}) { + push @archives, { + "archive" => $archive->{archive}, + "modification_time" => str2time($archive->{time}), + }; + } + } else { + $log->debug("Getting archive list"); + run [qw(borg list), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n"; + + for (split/^/, $output) { + # example timestamp: "Wed, 2016-01-27 10:31:59" = 24 chars + if (m/^([^\s]+)\s+(.{24})/) { + my $time = App::BorgRestore::Helper::parse_borg_time($2); + if ($time) { + push @archives, { + "archive" => $1, + "modification_time" => $time, + }; + } } } } |