btrbk: fixed action "tree"

pull/30/head
Axel Burri 2015-04-20 17:47:48 +02:00
parent 19c0733471
commit e25312223d
1 changed files with 21 additions and 12 deletions

33
btrbk
View File

@ -1714,43 +1714,52 @@ MAIN:
# print snapshot tree # print snapshot tree
# #
# TODO: reverse tree: print all backups from $droot and their corresponding source snapshots # TODO: reverse tree: print all backups from $droot and their corresponding source snapshots
my @out;
foreach my $config_vol (@{$config->{VOLUME}}) foreach my $config_vol (@{$config->{VOLUME}})
{ {
my %droot_compat; my %droot_compat;
my $sroot = vinfo($config_vol->{url}); my $sroot = vinfo($config_vol->{url});
print "$sroot->{URL}\n"; push @out, "$sroot->{PRINT}";
next unless $sroot->{ERROR}; # !!! TODO: check this
foreach my $config_subvol (@{$config_vol->{SUBVOLUME}}) foreach my $config_subvol (@{$config_vol->{SUBVOLUME}})
{ {
my $svol = vinfo($sroot, $config_subvol->{rel_path}) || die; my $svol = vinfo($sroot, $config_subvol->{rel_path}) || die;
print "|-- $svol->{URL}\n"; push @out, "|-- $svol->{PRINT}";
unless(vinfo($sroot, $config_subvol->{rel_path})) { # !!! TODO: maybe check uuid here? unless(vinfo($sroot, $config_subvol->{rel_path})) { # !!! TODO: maybe check uuid here?
print " !!! error: no subvolume \"$config_subvol->{rel_path}\" found in \"$sroot->{URL}\"\n"; push @out, " !!! error: no subvolume \"$config_subvol->{rel_path}\" found in \"$sroot->{PRINT}\"";
next; next;
} }
foreach my $snapshot (sort { $a->{PATH} cmp $b->{PATH} } (values %{$sroot->{SUBVOL_INFO}}))
foreach my $snapshot (sort { $a->{SUBVOL_PATH} cmp $b->{SUBVOL_PATH} } (values %{$sroot->{SUBVOL_INFO}}))
{ {
next unless($snapshot->{parent_uuid} eq $svol->{uuid}); next unless($snapshot->{parent_uuid} eq $svol->{uuid});
# next unless($snapshot->{SUBVOL_PATH} =~ /^$snapdir/); # don't print non-btrbk snapshots # next unless($snapshot->{SUBVOL_PATH} =~ /^$snapdir/); # don't print non-btrbk snapshots
print "| ^-- $snapshot->{SUBVOL_PATH}\n"; push @out, "| ^-- $snapshot->{PATH}";
foreach my $config_target (@{$config_subvol->{TARGET}}) foreach my $config_target (@{$config_subvol->{TARGET}})
{ {
my $droot = vinfo($config_target->{url}); my $droot = vinfo($config_target->{url});
next unless $droot->{SUBVOL_INFO}; next unless $droot->{SUBVOL_INFO};
$droot_compat{$droot} = 1 if($droot->{BTRFS_PROGS_COMPAT}); $droot_compat{$droot->{URL}} = 1 if($droot->{BTRFS_PROGS_COMPAT});
foreach (sort { $a->{SUBVOL_PATH} cmp $b->{SUBVOL_PATH} } get_receive_targets($droot, $snapshot)) { foreach (sort { $a->{SUBVOL_PATH} cmp $b->{SUBVOL_PATH} } get_receive_targets($droot, $snapshot)) {
print "| | ^== $_->{URL}\n"; push @out, "| | ^== $_->{PRINT}";
} }
} }
} }
} }
if(keys %droot_compat) { if(keys %droot_compat) {
print "\nNOTE: Received subvolumes (backups) are guessed by subvolume name for targets:\n"; push @out, "\nNOTE: Received subvolumes (backups) are guessed by subvolume name for targets:";
print " - " . join("\n - ", (sort keys %droot_compat)); push @out, " - " . join("\n - ", (sort keys %droot_compat));
} }
print "\n"; push @out, "";
} }
print "--------------------------------------------------------------------------------\n";
print "Backup Tree\n\n";
print " Date: " . localtime($start_time) . "\n";
print " Config: $config->{SRC_FILE}\n";
print "\nLegend:\n";
print " ^--- snapshot\n";
print " ^=== received subvolume (backup)\n";
print "--------------------------------------------------------------------------------\n";
print join("\n", @out);
exit 0; exit 0;
} }