summaryrefslogtreecommitdiffstats
path: root/borg-restore.pl
diff options
context:
space:
mode:
Diffstat (limited to 'borg-restore.pl')
-rwxr-xr-xborg-restore.pl23
1 files changed, 15 insertions, 8 deletions
diff --git a/borg-restore.pl b/borg-restore.pl
index d3a02ba..27dea1f 100755
--- a/borg-restore.pl
+++ b/borg-restore.pl
@@ -76,7 +76,7 @@ package main;
use autodie;
use Carp::Assert;
-use Cwd qw(abs_path);
+use Cwd qw(abs_path getcwd chdir);
use Data::Dumper;
use DateTime;
use DB_File;
@@ -260,17 +260,24 @@ sub restore {
my $archive = shift;
my $destination = shift;
- printf "Restoring %s to %s from archive %s\n", $path, $destination, $archive->{archive};
-
$destination = untaint($destination, qr(.*));
$path = untaint($path, qr(.*));
- my $components_to_strip =()= dirname($destination) =~ /\//g;
+ printf "Restoring %s to %s from archive %s\n", $path, $destination, $archive->{archive};
+
+ my $basename = basename($path);
+
+ # FIXME this returns incorrect results for /home vs /home/flo
+ my $components_to_strip =()= dirname("/".$path) =~ /\//g;
+
+ debug(sprintf("CWD is %s", getcwd()));
+ debug(sprintf("Changing CWD to %s", $destination));
+ #mkdir($destination) unless -d $destination;
+ chdir($destination) or die "Failed to chdir: $!";
- chdir dirname($destination);
+ # FIXME this doesn't behave as per docs yet
+ debug("Removing ".abs_path($basename));
#File::Path::remove_tree("restore-test");
- #mkdir "restore-test";
- #chdir "restore-test";
system(qw(echo borg extract -v --strip-components), $components_to_strip, "::".$archive->{archive}, $path);
}
@@ -630,7 +637,7 @@ sub main {
}
if (!defined($destination)) {
- $destination = $abs_path;
+ $destination = dirname($abs_path);
}
my $backup_path = $abs_path;
$backup_path =~ s/^\Q$backup_prefix\E//;