summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-04-02 13:39:47 +0200
committerFlorian Pritz <bluewind@xinu.at>2017-04-02 13:42:15 +0200
commit1af7a6a76a0cbfda953828b9bd5c0834553e6b24 (patch)
tree859cf7ff1906f9ad3d7e1d4b2c71670f952e7fbc
parent44441d8c67f155284af4e5f39f29368dd374fdbd (diff)
downloadApp-BorgRestore-1af7a6a76a0cbfda953828b9bd5c0834553e6b24.tar.gz
App-BorgRestore-1af7a6a76a0cbfda953828b9bd5c0834553e6b24.tar.xz
Move backup path mapping to main package
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--lib/App/BorgRestore.pm16
-rwxr-xr-xscript/borg-restore.pl12
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm
index d072a31..d5bb56b 100644
--- a/lib/App/BorgRestore.pm
+++ b/lib/App/BorgRestore.pm
@@ -120,6 +120,22 @@ sub resolve_relative_path {
return $abs_path;
}
+sub map_path_to_backup_path {
+ my $self = shift;
+ my $abs_path = shift;
+
+ my $backup_path = $abs_path;
+
+ for my $backup_prefix (@App::BorgRestore::Settings::backup_prefixes) {
+ if ($backup_path =~ m/$backup_prefix->{regex}/) {
+ $backup_path =~ s/$backup_prefix->{regex}/$backup_prefix->{replacement}/;
+ last;
+ }
+ }
+
+ return $backup_path;
+}
+
sub find_archives {
my $self = shift;
my $path = shift;
diff --git a/script/borg-restore.pl b/script/borg-restore.pl
index 2beb306..b30549f 100755
--- a/script/borg-restore.pl
+++ b/script/borg-restore.pl
@@ -262,16 +262,8 @@ sub main {
my $abs_path = $app->resolve_relative_path($path);
return 1 unless defined $abs_path;
- if (!defined($destination)) {
- $destination = dirname($abs_path);
- }
- my $backup_path = $abs_path;
- for my $backup_prefix (@App::BorgRestore::Settings::backup_prefixes) {
- if ($backup_path =~ m/$backup_prefix->{regex}/) {
- $backup_path =~ s/$backup_prefix->{regex}/$backup_prefix->{replacement}/;
- last;
- }
- }
+ $destination = dirname($abs_path) unless defined($destination);
+ my $backup_path = $app->map_path_to_backup_path($abs_path);
$log->debug("Asked to restore $backup_path to $destination");