From 672b807112fedaa0b8f3287a8d2a4790c787f622 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 15 Aug 2016 18:04:39 +0200 Subject: borg-restore.pl: Support multiple backup prefixes Signed-off-by: Florian Pritz --- borg-restore.pl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'borg-restore.pl') diff --git a/borg-restore.pl b/borg-restore.pl index 39f1048..116d9de 100755 --- a/borg-restore.pl +++ b/borg-restore.pl @@ -103,7 +103,11 @@ use Time::HiRes; my %opts; my %db; my $cache_path_base = "/home/flo/.cache/borg-restore.pl"; -my $backup_prefix = "/"; +my @backup_prefixes = ( + {regex => "^/home/", replacement => "mnt/snapshots/vg0-homeborg/"}, + {regex => "^/boot/", replacement => ""}, + {regex => "^/", replacement => "mnt/snapshots/vg0-rootborg/"}, +); sub debug { say STDERR @_ if $opts{debug}; @@ -640,7 +644,12 @@ sub main { $destination = dirname($abs_path); } my $backup_path = $abs_path; - $backup_path =~ s/^\Q$backup_prefix\E//; + for my $backup_prefix (@backup_prefixes) { + if ($backup_path =~ m/$backup_prefix->{regex}/) { + $backup_path =~ s/$backup_prefix->{regex}/$backup_prefix->{replacement}/; + last; + } + } debug("Asked to restore $backup_path to $destination"); -- cgit v1.2.3-24-g4f1b