btrbk: adaptions on vinfo_root: make sure a valid vinfo is in $config on each section

pull/30/head
Axel Burri 2015-04-23 15:30:33 +02:00
parent ea59d986d6
commit 8a99adf53f
1 changed files with 49 additions and 49 deletions

98
btrbk
View File

@ -168,7 +168,7 @@ sub run_cmd($;$)
} }
sub vinfo(@) sub vinfo($$)
{ {
my $url = shift // die; my $url = shift // die;
my $config = shift || die; my $config = shift || die;
@ -221,23 +221,6 @@ sub vinfo(@)
} }
sub vinfo_root($$)
{
my $vol = vinfo(@_);
my $detail = btr_subvolume_detail($vol);
return undef unless $detail;
vinfo_set_detail($vol, $detail);
# read (and cache) the subvolume list
return undef unless vinfo_subvol_list($vol);
TRACE "vinfo root created: $vol->{PRINT}";
return $vol;
}
sub vinfo_child($$) sub vinfo_child($$)
{ {
my $parent = shift || die; my $parent = shift || die;
@ -267,6 +250,22 @@ sub vinfo_child($$)
} }
sub vinfo_root($)
{
my $vol = shift;
my $detail = btr_subvolume_detail($vol);
return undef unless $detail;
vinfo_set_detail($vol, $detail);
# read (and cache) the subvolume list
return undef unless vinfo_subvol_list($vol);
TRACE "vinfo root created: $vol->{PRINT}";
return $vol;
}
sub vinfo_set_detail($$) sub vinfo_set_detail($$)
{ {
my $vol = shift || die; my $vol = shift || die;
@ -1336,13 +1335,13 @@ MAIN:
my $target_url = $subvol_args[1] || die; my $target_url = $subvol_args[1] || die;
# FIXME: allow ssh:// src/dest (does not work since the configuration is not yet read). # FIXME: allow ssh:// src/dest (does not work since the configuration is not yet read).
my $src_vol = vinfo_root($src_url, { CONTEXT => "cmdline" }); my $src_vol = vinfo($src_url, { CONTEXT => "cmdline" });
unless($src_vol) { exit 1; } unless(vinfo_root($src_vol)) { ERROR "Failed to fetch subvolume detail for: $src_vol->{PRINT}"; exit 1; }
if($src_vol->{is_root}) { ERROR "Subvolume at \"$src_url\" is btrfs root!"; exit 1; } if($src_vol->{is_root}) { ERROR "Subvolume at \"$src_url\" is btrfs root!"; exit 1; }
unless($src_vol->{cgen}) { ERROR "Subvolume at \"$src_url\" does not provide cgen"; exit 1; } unless($src_vol->{cgen}) { ERROR "Subvolume at \"$src_url\" does not provide cgen"; exit 1; }
my $target_vol = vinfo_root($target_url, { CONTEXT => "cmdline" }); my $target_vol = vinfo($target_url, { CONTEXT => "cmdline" });
unless($target_vol) { exit 1; } unless(vinfo_root($target_vol)) { ERROR "Failed to fetch subvolume detail for: $src_vol->{PRINT}"; exit 1; }
unless($src_vol->{cgen}) { ERROR "Subvolume at \"$src_url\" does not provide cgen"; exit 1; } unless($src_vol->{cgen}) { ERROR "Subvolume at \"$src_url\" does not provide cgen"; exit 1; }
my $uuid_list = vinfo_fs_list($src_vol); my $uuid_list = vinfo_fs_list($src_vol);
@ -1446,33 +1445,33 @@ MAIN:
my %processed; my %processed;
foreach my $config_vol (@{$config->{VOLUME}}) foreach my $config_vol (@{$config->{VOLUME}})
{ {
my $url = $config_vol->{url} || die; my $sroot = vinfo($config_vol->{url}, $config_vol);
unless($processed{$url}) unless($processed{$sroot->{URL}})
{ {
print "\n--------------------------------------------------------------------------------\n"; print "\n--------------------------------------------------------------------------------\n";
print "Source volume: $url\n"; print "Source volume: $sroot->{PRINT}\n";
print "--------------------------------------------------------------------------------\n"; print "--------------------------------------------------------------------------------\n";
print (btr_filesystem_usage(vinfo($url, $config_vol)) // ""); print (btr_filesystem_usage($sroot) // "");
print "\n"; print "\n";
$processed{$url} = 1; $processed{$sroot->{URL}} = 1;
} }
} }
foreach my $config_vol (@{$config->{VOLUME}}) { foreach my $config_vol (@{$config->{VOLUME}}) {
my $sroot_url = $config_vol->{url} || die; my $sroot = vinfo($config_vol->{url}, $config_vol);
foreach my $config_subvol (@{$config_vol->{SUBVOLUME}}) { foreach my $config_subvol (@{$config_vol->{SUBVOLUME}}) {
foreach my $config_target (@{$config_subvol->{TARGET}}) foreach my $config_target (@{$config_subvol->{TARGET}})
{ {
my $droot_url = $config_target->{url} || die; my $droot = vinfo($config_target->{url}, $config_target);
unless($processed{$droot_url}) unless($processed{$droot->{URL}})
{ {
print "\n--------------------------------------------------------------------------------\n"; print "\n--------------------------------------------------------------------------------\n";
print "Target volume: $droot_url\n"; print "Target volume: $droot->{PRINT}\n";
print " ^--- $sroot_url\n"; print " ^--- $sroot->{PRINT}\n";
print "--------------------------------------------------------------------------------\n"; print "--------------------------------------------------------------------------------\n";
print (btr_filesystem_usage(vinfo($droot_url, $config_target)) // ""); print (btr_filesystem_usage($droot) // "");
print "\n"; print "\n";
$processed{$droot_url} = 1; $processed{$droot->{URL}} = 1;
} }
} }
} }
@ -1524,10 +1523,10 @@ MAIN:
foreach my $config_vol (@{$config->{VOLUME}}) foreach my $config_vol (@{$config->{VOLUME}})
{ {
next if($config_vol->{ABORTED}); next if($config_vol->{ABORTED});
my $sroot = vinfo_root($config_vol->{url}, $config_vol); my $sroot = vinfo($config_vol->{url}, $config_vol);
unless($sroot) { unless(vinfo_root($sroot)) {
$config_vol->{ABORTED} = "Failed to fetch subvolume detail"; $config_vol->{ABORTED} = "Failed to fetch subvolume detail";
WARN "Skipping volume \"$config_vol->{url}\": $config_vol->{ABORTED}"; WARN "Skipping volume \"$sroot->{PRINT}\": $config_vol->{ABORTED}";
next; next;
} }
$config_vol->{sroot} = $sroot; $config_vol->{sroot} = $sroot;
@ -1579,12 +1578,13 @@ MAIN:
foreach my $config_target (@{$config_subvol->{TARGET}}) foreach my $config_target (@{$config_subvol->{TARGET}})
{ {
my $droot = vinfo_root($config_target->{url}, $config_target); my $droot = vinfo($config_target->{url}, $config_target);
unless($droot) { unless(vinfo_root($droot)) {
$config_target->{ABORTED} = "Failed to fetch subvolume detail"; $config_target->{ABORTED} = "Failed to fetch subvolume detail";
WARN "Skipping target \"$config_target->{url}\": $config_target->{ABORTED}"; WARN "Skipping target \"$droot->{PRINT}\": $config_target->{ABORTED}";
next; next;
} }
$config_target->{droot} = $droot;
# check for duplicate snapshot locations # check for duplicate snapshot locations
my $snapshot_backup_target = "$droot->{REAL_URL}/$snapshot_basename"; my $snapshot_backup_target = "$droot->{REAL_URL}/$snapshot_basename";
@ -1594,8 +1594,6 @@ MAIN:
exit 1; exit 1;
} }
$backup_check{$snapshot_backup_target} = $svol->{PRINT}; $backup_check{$snapshot_backup_target} = $svol->{PRINT};
$config_target->{droot} = $droot;
} }
} }
} }
@ -1613,9 +1611,9 @@ MAIN:
unless($vol) { unless($vol) {
# specified volume is not in config # specified volume is not in config
DEBUG "Subvolume not parsed yet, fetching info: $url"; DEBUG "Subvolume not parsed yet, fetching info: $url";
$vol = vinfo_root($url, { CONTEXT => "cmdline" }); $vol = vinfo($url, { CONTEXT => "cmdline" });
unless($vol) { unless(vinfo_root($vol)) {
ERROR "Failed to fetch subvolume detail: $url"; ERROR "Failed to fetch subvolume detail for: $url";
exit 1; exit 1;
} }
} }
@ -1984,15 +1982,17 @@ MAIN:
my $err_count = 0; my $err_count = 0;
foreach my $config_vol (@{$config->{VOLUME}}) foreach my $config_vol (@{$config->{VOLUME}})
{ {
my $sroot = $config_vol->{sroot} || vinfo($config_vol->{url}, $config_vol);
foreach my $config_subvol (@{$config_vol->{SUBVOLUME}}) foreach my $config_subvol (@{$config_vol->{SUBVOLUME}})
{ {
push @out, "$config_subvol->{url}"; my $svol = $config_subvol->{svol} || vinfo_child($sroot, $config_subvol->{rel_path});
push @out, "$svol->{PRINT}";
if($config_vol->{ABORTED}) { if($config_vol->{ABORTED}) {
push @out, "!!! $config_vol->{url}: ABORTED: $config_vol->{ABORTED}"; push @out, "!!! $sroot->{PRINT}: ABORTED: $config_vol->{ABORTED}";
$err_count++ unless($config_vol->{ABORTED_NOERR}); $err_count++ unless($config_vol->{ABORTED_NOERR});
} }
if($config_subvol->{ABORTED}) { if($config_subvol->{ABORTED}) {
push @out, "!!! Subvolume \"$config_subvol->{url}\" aborted: $config_subvol->{ABORTED}"; push @out, "!!! Subvolume \"$svol->{PRINT}\" aborted: $config_subvol->{ABORTED}";
$err_count++ unless($config_subvol->{ABORTED_NOERR}); $err_count++ unless($config_subvol->{ABORTED_NOERR});
} }
push @out, "+++ $config_subvol->{SNAPSHOT}->{PRINT}" if($config_subvol->{SNAPSHOT}); push @out, "+++ $config_subvol->{SNAPSHOT}->{PRINT}" if($config_subvol->{SNAPSHOT});
@ -2001,7 +2001,7 @@ MAIN:
} }
foreach my $config_target (@{$config_subvol->{TARGET}}) foreach my $config_target (@{$config_subvol->{TARGET}})
{ {
my $droot = $config_target->{droot}; my $droot = $config_target->{droot} || vinfo($config_target->{url}, $config_target);
foreach(@{$config_target->{SUBVOL_RECEIVED} // []}) { foreach(@{$config_target->{SUBVOL_RECEIVED} // []}) {
my $create_mode = "***"; my $create_mode = "***";
$create_mode = ">>>" if($_->{parent}); $create_mode = ">>>" if($_->{parent});