summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--META.json3
-rw-r--r--cpanfile3
-rw-r--r--lib/App/BorgRestore/Borg.pm39
3 files changed, 33 insertions, 12 deletions
diff --git a/META.json b/META.json
index be02fbb..cba2f5d 100644
--- a/META.json
+++ b/META.json
@@ -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"
}
diff --git a/cpanfile b/cpanfile
index f1c0770..548434a 100644
--- a/cpanfile
+++ b/cpanfile
@@ -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,
+ };
+ }
}
}
}