From 5030d54318b3ea36426b97d30fb9ae2d347ec947 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Sun, 6 Mar 2016 17:46:46 +0100 Subject: [PATCH] btrbk: split "check for duplicate snapshot locations" from "fill vinfo hash" --- btrbk | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/btrbk b/btrbk index a9caebd..0c44320 100755 --- a/btrbk +++ b/btrbk @@ -2848,8 +2848,6 @@ MAIN: # # fill vinfo hash, basic checks on configuration # - my %snapshot_check; - my %backup_check; foreach my $config_vol (@{$config->{VOLUME}}) { next if($config_vol->{ABORTED}); @@ -2892,16 +2890,6 @@ MAIN: } $config_subvol->{svol} = $svol; - # check for duplicate snapshot locations - my $snapdir = config_key($config_subvol, "snapshot_dir", postfix => '/') // ""; - my $snapshot_basename = config_key($config_subvol, "snapshot_name") // die; - my $snapshot_target = "$sroot->{REAL_URL}/$snapdir$snapshot_basename"; - if(my $prev = $snapshot_check{$snapshot_target}) { - ERROR "Subvolume \"$prev\" and \"$svol->{PRINT}\" will create same snapshot: $snapshot_target"; - ERROR "Please fix \"snapshot_name\" configuration options!"; - exit 1; - } - $snapshot_check{$snapshot_target} = $svol->{PRINT}; foreach my $config_target (@{$config_subvol->{TARGET}}) { @@ -2947,6 +2935,7 @@ MAIN: ABORTED($config_target, "Unexpected result from 'find': file \"$file\" is not under \"$droot->{PATH}\""); last; } + my $snapshot_basename = config_key($config_subvol, "snapshot_name") // die; my $filename_info = parse_filename($file, $snapshot_basename, 1); unless($filename_info) { DEBUG "Skipping file (not btrbk raw): \"$file\""; @@ -3007,6 +2996,37 @@ MAIN: # TRACE(Data::Dumper->Dump([\%subvol_list], ["vinfo_raw_subvol_list{$droot}"])); } $config_target->{droot} = $droot; + } + } + } + + # check for duplicate snapshot locations + my %snapshot_check; + my %backup_check; + foreach my $config_vol (@{$config->{VOLUME}}) + { + next if($config_vol->{ABORTED}); + my $sroot = $config_vol->{sroot} || die; + foreach my $config_subvol (@{$config_vol->{SUBVOLUME}}) + { + next if($config_subvol->{ABORTED}); + my $svol = $config_subvol->{svol} || die; + + # check for duplicate snapshot locations + my $snapdir = config_key($config_subvol, "snapshot_dir", postfix => '/') // ""; + my $snapshot_basename = config_key($config_subvol, "snapshot_name") // die; + my $snapshot_target = "$sroot->{REAL_URL}/$snapdir$snapshot_basename"; + if(my $prev = $snapshot_check{$snapshot_target}) { + ERROR "Subvolume \"$prev\" and \"$svol->{PRINT}\" will create same snapshot: $snapshot_target"; + ERROR "Please fix \"snapshot_name\" configuration options!"; + exit 1; + } + $snapshot_check{$snapshot_target} = $svol->{PRINT}; + + foreach my $config_target (@{$config_subvol->{TARGET}}) + { + next if($config_target->{ABORTED}); + my $droot = $config_target->{droot} || die; # check for duplicate snapshot locations my $snapshot_backup_target = "$droot->{REAL_URL}/$snapshot_basename";