From 499382c2eb7b7d46b09157fd2367982db7202620 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 15 Aug 2016 00:09:01 +0200 Subject: borg-restore.pl: Implement restore testing code Signed-off-by: Florian Pritz --- borg-restore.pl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'borg-restore.pl') 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//; -- cgit v1.2.3-24-g4f1b