summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-11-21 19:53:31 +0100
committerFlorian Pritz <bluewind@xinu.at>2017-11-21 20:06:22 +0100
commit654740fd9cecce9921d274246791eb0cbc723af0 (patch)
tree09fd936ea1ce177f0ecbc56778a4bdef06c5a4b7 /lib
parentc97d2a9e42fcb74b05b1473c24f849e5e2e995d8 (diff)
downloadApp-BorgRestore-654740fd9cecce9921d274246791eb0cbc723af0.tar.gz
App-BorgRestore-654740fd9cecce9921d274246791eb0cbc723af0.tar.xz
borg_list_time: Use JSON when possible
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/App/BorgRestore/Borg.pm39
1 files changed, 27 insertions, 12 deletions
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,
+ };
+ }
}
}
}