btrbk: clone target subvolume tree if same url as other target (less btrfs calls, shared SUBVOL_LIST)

pull/73/head
Axel Burri 2016-03-08 16:41:02 +01:00
parent eba08f2ca3
commit c1b27c744b
1 changed files with 14 additions and 9 deletions

23
btrbk
View File

@ -2926,6 +2926,7 @@ MAIN:
# fill vinfo hash, basic checks on configuration # fill vinfo hash, basic checks on configuration
# #
foreach my $sroot (vinfo_subsection($config, 'volume')) { foreach my $sroot (vinfo_subsection($config, 'volume')) {
DEBUG "Initializing volume section: $sroot->{PRINT}";
unless(vinfo_root($sroot)) { unless(vinfo_root($sroot)) {
ABORTED($sroot, "Failed to fetch subvolume detail" . ($err ? ": $err" : "")); ABORTED($sroot, "Failed to fetch subvolume detail" . ($err ? ": $err" : ""));
WARN "Skipping volume \"$sroot->{PRINT}\": $abrt"; WARN "Skipping volume \"$sroot->{PRINT}\": $abrt";
@ -2933,14 +2934,15 @@ MAIN:
} }
foreach my $svol (vinfo_subsection($sroot, 'subvolume')) { foreach my $svol (vinfo_subsection($sroot, 'subvolume')) {
my $svol_check = vinfo_subvol($sroot, $svol->{CONFIG}->{rel_path}); DEBUG "Initializing subvolume section: $svol->{PRINT}";
if($svol_check) { if(my $svol_check = vinfo_subvol($sroot, $svol->{CONFIG}->{rel_path})) {
DEBUG "Found \"$svol->{CONFIG}->{rel_path}\" in btrfs subtree of: $sroot->{PRINT}";
vinfo_set_detail($svol, $svol_check); vinfo_set_detail($svol, $svol_check);
} }
else { else {
# configured subvolume is not present in btrfs subvolume list. # configured subvolume is not present in btrfs subvolume list.
# try to read subvolume detail, as configured subvolume could be a symlink. # try to read subvolume detail, as configured subvolume could be a symlink.
DEBUG "Subvolume \"$svol->{CONFIG}->{rel_path}\" not present in btrfs subvolume list for \"$sroot->{PRINT}\""; DEBUG "Missing \"$svol->{CONFIG}->{rel_path}\" in btrfs subtree of \"$sroot->{PRINT}\", checking details";
my $detail = btrfs_subvolume_detail($svol); my $detail = btrfs_subvolume_detail($svol);
unless($detail) { unless($detail) {
ABORTED($svol, "Failed to fetch subvolume detail" . ($err ? ": $err" : "")); ABORTED($svol, "Failed to fetch subvolume detail" . ($err ? ": $err" : ""));
@ -2964,10 +2966,16 @@ MAIN:
foreach my $droot (vinfo_subsection($svol, 'target')) { foreach my $droot (vinfo_subsection($svol, 'target')) {
DEBUG "Initializing target section: $droot->{PRINT}";
my $target_type = $droot->{CONFIG}->{target_type} || die; my $target_type = $droot->{CONFIG}->{target_type} || die;
if($target_type eq "send-receive") if($target_type eq "send-receive")
{ {
unless(vinfo_root($droot)) { if(my $vinfo_clone = $vinfo_cache{$droot->{URL}}) {
DEBUG "Found previously initialized target with same url, cloning dataset from: $droot->{PRINT}";
vinfo_set_detail($droot, $vinfo_clone);
$droot->{SUBVOL_LIST} = $vinfo_clone->{SUBVOL_LIST};
}
elsif(! vinfo_root($droot)) {
ABORTED($droot, "Failed to fetch subvolume detail" . ($err ? ": $err" : "")); ABORTED($droot, "Failed to fetch subvolume detail" . ($err ? ": $err" : ""));
WARN "Skipping target \"$droot->{PRINT}\": $abrt"; WARN "Skipping target \"$droot->{PRINT}\": $abrt";
next; next;
@ -3539,14 +3547,11 @@ 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 "Resume candidate does not match btrbk filename scheme, skipping: $child->{PRINT}"; TRACE "Resume candidate does not match btrbk filename scheme, skipping: $child->{PRINT}";
next; next;
} }
if(scalar get_receive_targets($droot, $child)) { unless(scalar get_receive_targets($droot, $child)) {
DEBUG "Found matching receive target, skipping: $child->{PRINT}";
}
else {
DEBUG "No matching receive targets found, adding resume candidate: $child->{PRINT}"; DEBUG "No matching receive targets found, adding resume candidate: $child->{PRINT}";
if(my $err_vol = vinfo_subvol($droot, $child->{NAME})) { if(my $err_vol = vinfo_subvol($droot, $child->{NAME})) {