summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-08-15 00:09:01 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-08-15 00:09:01 +0200
commit499382c2eb7b7d46b09157fd2367982db7202620 (patch)
treed38f9b9ad9a92d3a95335bd22d54f16c28fc38b5
parenta269667d2b88fab10079a993e89114b7cefbfcfe (diff)
downloadbin-499382c2eb7b7d46b09157fd2367982db7202620.tar.gz
bin-499382c2eb7b7d46b09157fd2367982db7202620.tar.xz
borg-restore.pl: Implement restore testing code
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-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//;