btrbk: prepare for multiple pre-config commands

Preparatory for extents-diff command
extents-diff
Axel Burri 2019-05-23 15:36:34 +02:00
parent d9d3def390
commit 075fb8bfad
1 changed files with 79 additions and 72 deletions

43
btrbk
View File

@ -4842,7 +4842,7 @@ MAIN:
WARN 'Found option "--progress", but required executable "pv" does not exist on your system. Please install "pv".';
$show_progress = 0;
}
my ($action_run, $action_usage, $action_resolve, $action_diff, $action_origin, $action_config_print, $action_list, $action_clean, $action_archive);
my ($action_run, $action_usage, $action_resolve, $action_noconf, $action_origin, $action_config_print, $action_list, $action_clean, $action_archive);
my @filter_args;
my @subvol_args;
my $args_expected_min = 0;
@ -4883,7 +4883,7 @@ MAIN:
@filter_args = @ARGV;
}
elsif ($command eq "diff") {
$action_diff = 1;
$action_noconf = "diff";
$args_expected_min = $args_expected_max = 2;
@subvol_args = @ARGV;
}
@ -5003,28 +5003,33 @@ MAIN:
INFO "$VERSION_INFO (" . localtime($start_time) . ")";
action("startup", status => "v$VERSION", message => $VERSION_INFO, time => $start_time);
if($action_diff)
if($action_noconf)
{
#
# print snapshot diff
#
my $src_url = $subvol_args[0] || die;
my $target_url = $subvol_args[1] || die;
my $default_config = init_config();
# NOTE: ssh://{src,target} uses default config
my $default_config = init_config();
my $src_vol = vinfo($src_url, $default_config);
unless(vinfo_init_root($src_vol)) { ERROR "Failed to fetch subvolume detail for '$src_vol->{PRINT}'" . ($err ? ": $err" : ""); exit 1; }
if($src_vol->{node}{is_root}) { ERROR "Subvolume is btrfs root: $src_vol->{PRINT}"; exit 1; }
my $target_vol = vinfo($target_url, $default_config);
unless(vinfo_init_root($target_vol)) { ERROR "Failed to fetch subvolume detail for '$target_vol->{PRINT}'" . ($err ? ": $err" : ""); exit 1; }
if($target_vol->{node}{is_root}) { ERROR "Subvolume is btrfs root: $target_vol->{PRINT}"; exit 1; }
unless(_is_same_fs_tree($src_vol->{node}, $target_vol->{node})) {
my @diff_vol = map { vinfo($_, $default_config) } @subvol_args;
my $src_vol = $diff_vol[0];
foreach (@diff_vol) {
unless(vinfo_init_root($_)) {
ERROR "Failed to fetch subvolume detail for '$_->{PRINT}'" . ($err ? ": $err" : "");
exit 1;
}
if($_->{node}{is_root}) {
ERROR "Subvolume is btrfs root: $_->{PRINT}";
exit 1;
}
unless(_is_same_fs_tree($src_vol->{node}, $_->{node})) {
ERROR "Subvolumes are not on the same btrfs filesystem!";
exit 1;
}
}
if($action_noconf eq "diff") {
#
# print snapshot diff (btrfs find-new)
#
my $target_vol = $diff_vol[1];
# NOTE: in some cases "cgen" differs from "gen", even for read-only snapshots (observed: gen=cgen+1)
my $lastgen = $src_vol->{node}{gen} + 1;
@ -5084,6 +5089,8 @@ MAIN:
print " $name\n";
}
print "\nTotal size: $total_len bytes\n";
}
exit 0;
}