btrbk: fix "resolve targets" for btrfs_progs_compat=yes; cleanup

pull/57/head
Axel Burri 2015-10-20 16:33:23 +02:00
parent fef691aa04
commit 32028850bd
1 changed files with 39 additions and 24 deletions

63
btrbk
View File

@ -2754,12 +2754,13 @@ MAIN:
if($action_resolve) if($action_resolve)
{ {
if($action_resolve eq "snapshots") { my @data;
my %droot_compat;
if($action_resolve eq "snapshots")
{
# #
# print all snapshots and their receive targets # print all snapshots and their receive targets
# #
my @data;
my %droot_compat;
foreach my $config_vol (@{$config->{VOLUME}}) { foreach my $config_vol (@{$config->{VOLUME}}) {
next if($config_vol->{ABORTED}); next if($config_vol->{ABORTED});
my $sroot = $config_vol->{sroot} || die; my $sroot = $config_vol->{sroot} || die;
@ -2791,17 +2792,12 @@ MAIN:
} }
} }
} }
if(keys %droot_compat) {
WARN "Received subvolumes (backups) are guessed by subvolume name for targets (btrfs_progs_compat=yes)";
WARN " - target: $_" foreach(sort keys %droot_compat);
}
print_formatted("resolved", \@data);
} }
elsif($action_resolve eq "targets") { elsif($action_resolve eq "targets")
{
# #
# print all targets and their corresponding source snapshots # print all targets and their corresponding source snapshots
# #
my @data;
foreach my $config_vol (@{$config->{VOLUME}}) { foreach my $config_vol (@{$config->{VOLUME}}) {
next if($config_vol->{ABORTED}); next if($config_vol->{ABORTED});
my $sroot = $config_vol->{sroot} || die; my $sroot = $config_vol->{sroot} || die;
@ -2812,12 +2808,20 @@ MAIN:
foreach my $config_target (@{$config_subvol->{TARGET}}) { foreach my $config_target (@{$config_subvol->{TARGET}}) {
next if($config_target->{ABORTED}); next if($config_target->{ABORTED});
my $droot = $config_target->{droot} || die; my $droot = $config_target->{droot} || die;
$droot_compat{$droot->{URL}} = 1 if($droot->{BTRFS_PROGS_COMPAT});
foreach my $target_vol (sort { $a->{SUBVOL_PATH} cmp $b->{SUBVOL_PATH} } values %{vinfo_subvol_list($droot)}) { foreach my $target_vol (sort { $a->{SUBVOL_PATH} cmp $b->{SUBVOL_PATH} } values %{vinfo_subvol_list($droot)}) {
my $parent_snapshot; my $parent_snapshot;
foreach (get_snapshot_children($sroot, $svol)) { foreach (get_snapshot_children($sroot, $svol)) {
if($_->{uuid} eq $target_vol->{received_uuid}) { if($droot->{BTRFS_PROGS_COMPAT}) {
$parent_snapshot = $_; if($_->{NAME} eq $target_vol->{NAME}) {
last; $parent_snapshot = $_;
last;
}
} else {
if($_->{uuid} eq $target_vol->{received_uuid}) {
$parent_snapshot = $_;
last;
}
} }
} }
if($parent_snapshot) { if($parent_snapshot) {
@ -2829,23 +2833,28 @@ MAIN:
}; };
} }
else { else {
push @data, { type => "received", # don't display all subvolumes in $droot, only the ones matching snapshot_name
vinfo_prefixed_keys("target", $target_vol), if(parse_filename($target_vol->{SUBVOL_PATH}, $snapshot_name, ($config_target->{target_type} eq "raw"))) {
vinfo_prefixed_keys("source", $svol), push @data, { type => "received",
}; status => "orphaned",
vinfo_prefixed_keys("target", $target_vol),
vinfo_prefixed_keys("source", $svol),
};
}
else {
DEBUG "ignoring subvolume with non-matching snapshot_name";
}
} }
} }
} }
} }
} }
print_formatted("resolved", \@data);
} }
elsif($action_resolve eq "latest") elsif($action_resolve eq "latest")
{ {
# #
# print latest common # print latest common
# #
my @data;
foreach my $config_vol (@{$config->{VOLUME}}) { foreach my $config_vol (@{$config->{VOLUME}}) {
next if($config_vol->{ABORTED}); next if($config_vol->{ABORTED});
my $sroot = $config_vol->{sroot} || die; my $sroot = $config_vol->{sroot} || die;
@ -2877,11 +2886,17 @@ MAIN:
} }
} }
} }
print_formatted("resolved", \@data);
} }
else { else {
die; die;
} }
if(keys %droot_compat) {
WARN "Received subvolumes (backups) are guessed by subvolume name for targets (btrfs_progs_compat=yes):";
WARN " - target: $_" foreach(sort keys %droot_compat);
}
print_formatted("resolved", \@data);
exit exit_status($config); exit exit_status($config);
} }
@ -3020,7 +3035,7 @@ MAIN:
{ {
my $filename_info = parse_filename($child->{SUBVOL_PATH}, $snapdir . $snapshot_basename); my $filename_info = parse_filename($child->{SUBVOL_PATH}, $snapdir . $snapshot_basename);
unless($filename_info) { unless($filename_info) {
DEBUG "Receive target does not match btrbk filename scheme, skipping: $child->{PRINT}"; DEBUG "Resume candidate does not match btrbk filename scheme, skipping: $child->{PRINT}";
next; next;
} }
@ -3050,7 +3065,7 @@ MAIN:
foreach my $vol (values %{vinfo_subvol_list($droot)}) { foreach my $vol (values %{vinfo_subvol_list($droot)}) {
my $filename_info = parse_filename($vol->{SUBVOL_PATH}, $snapshot_basename, ($config_target->{target_type} eq "raw")); my $filename_info = parse_filename($vol->{SUBVOL_PATH}, $snapshot_basename, ($config_target->{target_type} eq "raw"));
unless($filename_info) { unless($filename_info) {
DEBUG "Resume candidate does not match btrbk filename scheme, skipping: $vol->{PRINT}"; TRACE "Receive target does not match btrbk filename scheme, skipping: $vol->{PRINT}";
next; next;
} }
push(@schedule, { value => undef, push(@schedule, { value => undef,
@ -3175,7 +3190,7 @@ MAIN:
foreach my $vol (values %{vinfo_subvol_list($droot)}) { foreach my $vol (values %{vinfo_subvol_list($droot)}) {
my $filename_info = parse_filename($vol->{SUBVOL_PATH}, $snapshot_basename, ($config_target->{target_type} eq "raw")); my $filename_info = parse_filename($vol->{SUBVOL_PATH}, $snapshot_basename, ($config_target->{target_type} eq "raw"));
unless($filename_info) { unless($filename_info) {
DEBUG "Receive target does not match btrbk filename scheme, skipping: $vol->{PRINT}"; TRACE "Receive target does not match btrbk filename scheme, skipping: $vol->{PRINT}";
next; next;
} }
@ -3228,7 +3243,7 @@ MAIN:
foreach my $vol (values %{vinfo_subvol_list($sroot)}) { foreach my $vol (values %{vinfo_subvol_list($sroot)}) {
my $filename_info = parse_filename($vol->{SUBVOL_PATH}, $snapdir . $snapshot_basename); my $filename_info = parse_filename($vol->{SUBVOL_PATH}, $snapdir . $snapshot_basename);
unless($filename_info) { unless($filename_info) {
DEBUG "Snapshot does not match btrbk filename scheme, skipping: $vol->{PRINT}"; TRACE "Snapshot does not match btrbk filename scheme, skipping: $vol->{PRINT}";
next; next;
} }
push(@schedule, { value => $vol, push(@schedule, { value => $vol,