mirror of https://github.com/digint/btrbk
btrbk: cleanup: btrfs_send_to_file() takes no more additional options (all info is fetched directly from source/target config)
parent
28c65e4675
commit
358a2b1169
75
btrbk
75
btrbk
|
@ -1131,13 +1131,12 @@ sub btrfs_subvolume_delete($@)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub btrfs_send_receive($$$$;@)
|
sub btrfs_send_receive($$$$)
|
||||||
{
|
{
|
||||||
my $snapshot = shift || die;
|
my $snapshot = shift || die;
|
||||||
my $target = shift || die;
|
my $target = shift || die;
|
||||||
my $parent = shift;
|
my $parent = shift;
|
||||||
my $ret_vol_received = shift;
|
my $ret_vol_received = shift;
|
||||||
# my %opts = @_;
|
|
||||||
my $snapshot_path = $snapshot->{PATH} // die;
|
my $snapshot_path = $snapshot->{PATH} // die;
|
||||||
my $target_path = $target->{PATH} // die;
|
my $target_path = $target->{PATH} // die;
|
||||||
my $parent_path = $parent ? $parent->{PATH} : undef;
|
my $parent_path = $parent ? $parent->{PATH} : undef;
|
||||||
|
@ -1273,13 +1272,12 @@ sub btrfs_send_receive($$$$;@)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub btrfs_send_to_file($$$$;@)
|
sub btrfs_send_to_file($$$$)
|
||||||
{
|
{
|
||||||
my $source = shift || die;
|
my $source = shift || die;
|
||||||
my $target = shift || die;
|
my $target = shift || die;
|
||||||
my $parent = shift;
|
my $parent = shift;
|
||||||
my $ret_vol_received = shift;
|
my $ret_vol_received = shift;
|
||||||
my %opts = @_;
|
|
||||||
my $source_path = $source->{PATH} // die;
|
my $source_path = $source->{PATH} // die;
|
||||||
my $target_path = $target->{PATH} // die;
|
my $target_path = $target->{PATH} // die;
|
||||||
my $parent_path = $parent ? $parent->{PATH} : undef;
|
my $parent_path = $parent ? $parent->{PATH} : undef;
|
||||||
|
@ -1293,6 +1291,10 @@ sub btrfs_send_to_file($$$$;@)
|
||||||
$target_filename .= '@' . $parent_uuid if($parent_uuid);
|
$target_filename .= '@' . $parent_uuid if($parent_uuid);
|
||||||
$target_filename .= ".btrfs";
|
$target_filename .= ".btrfs";
|
||||||
|
|
||||||
|
my $compress = config_compress_hash($target, "raw_target_compress");
|
||||||
|
my $encrypt = config_encrypt_hash($target, "raw_target_encrypt");
|
||||||
|
my $split = config_key($target, "raw_target_split");
|
||||||
|
|
||||||
my @send_options;
|
my @send_options;
|
||||||
push(@send_options, '-v') if($loglevel >= 3);
|
push(@send_options, '-v') if($loglevel >= 3);
|
||||||
push(@send_options, '-p', $parent_path) if($parent_path);
|
push(@send_options, '-p', $parent_path) if($parent_path);
|
||||||
|
@ -1300,17 +1302,17 @@ sub btrfs_send_to_file($$$$;@)
|
||||||
my @cmd_pipe;
|
my @cmd_pipe;
|
||||||
push @cmd_pipe, {
|
push @cmd_pipe, {
|
||||||
cmd => vinfo_cmd($source, "btrfs send", @send_options, { unsafe => $source_path } ),
|
cmd => vinfo_cmd($source, "btrfs send", @send_options, { unsafe => $source_path } ),
|
||||||
rsh => vinfo_rsh($source, disable_compression => $opts{compress} || config_compress_hash($source, "stream_compress")),
|
rsh => vinfo_rsh($source, disable_compression => $compress || config_compress_hash($source, "stream_compress")),
|
||||||
name => "btrfs send",
|
name => "btrfs send",
|
||||||
rsh_compress_out => $opts{compress} || config_compress_hash($source, "stream_compress"),
|
rsh_compress_out => $compress || config_compress_hash($source, "stream_compress"),
|
||||||
rsh_rate_limit_out => config_key($source, "rate_limit"),
|
rsh_rate_limit_out => config_key($source, "rate_limit"),
|
||||||
};
|
};
|
||||||
add_progress_command(\@cmd_pipe);
|
add_progress_command(\@cmd_pipe);
|
||||||
if($opts{compress}) {
|
if($compress) {
|
||||||
$target_filename .= '.' . $compression{$opts{compress}->{key}}->{format};
|
$target_filename .= '.' . $compression{$compress->{key}}->{format};
|
||||||
push @cmd_pipe, { compress => $opts{compress} }; # does nothing if already compressed by rsh_compress_out
|
push @cmd_pipe, { compress => $compress }; # does nothing if already compressed by rsh_compress_out
|
||||||
}
|
}
|
||||||
if($opts{encrypt}) {
|
if($encrypt) {
|
||||||
# NOTE: We set "--no-random-seed-file" since one of the btrbk
|
# NOTE: We set "--no-random-seed-file" since one of the btrbk
|
||||||
# design principles is to never create any files unasked. Enabling
|
# design principles is to never create any files unasked. Enabling
|
||||||
# "--no-random-seed-file" creates ~/.gnupg/random_seed, and as
|
# "--no-random-seed-file" creates ~/.gnupg/random_seed, and as
|
||||||
|
@ -1321,29 +1323,28 @@ sub btrfs_send_to_file($$$$;@)
|
||||||
# generation faster; however sometimes write operations are not
|
# generation faster; however sometimes write operations are not
|
||||||
# desired. This option can be used to achieve that with the cost
|
# desired. This option can be used to achieve that with the cost
|
||||||
# of slower random generation.
|
# of slower random generation.
|
||||||
die unless($opts{encrypt}->{type} eq "gpg");
|
die unless($encrypt->{type} eq "gpg");
|
||||||
$target_filename .= '.gpg';
|
$target_filename .= '.gpg';
|
||||||
my @gpg_options = ( '--batch', '--no-tty', '--no-random-seed-file', '--trust-model', 'always' );
|
my @gpg_options = ( '--batch', '--no-tty', '--no-random-seed-file', '--trust-model', 'always' );
|
||||||
push @gpg_options, ( '--compress-algo', 'none' ) if($opts{compress}); # NOTE: if --compress-algo is not set, gpg might still compress according to OpenPGP standard.
|
push @gpg_options, ( '--compress-algo', 'none' ) if($compress); # NOTE: if --compress-algo is not set, gpg might still compress according to OpenPGP standard.
|
||||||
push(@gpg_options, ( '--no-default-keyring', '--keyring', $opts{encrypt}->{keyring} )) if($opts{encrypt}->{keyring});
|
push(@gpg_options, ( '--no-default-keyring', '--keyring', $encrypt->{keyring} )) if($encrypt->{keyring});
|
||||||
push(@gpg_options, ( '--default-recipient', $opts{encrypt}->{recipient} )) if($opts{encrypt}->{recipient});
|
push(@gpg_options, ( '--default-recipient', $encrypt->{recipient} )) if($encrypt->{recipient});
|
||||||
push @cmd_pipe, {
|
push @cmd_pipe, {
|
||||||
cmd => [ 'gpg', @gpg_options, '--encrypt' ],
|
cmd => [ 'gpg', @gpg_options, '--encrypt' ],
|
||||||
name => 'gpg',
|
name => 'gpg',
|
||||||
compressed_ok => ($opts{compress} ? 1 : 0),
|
compressed_ok => ($compress ? 1 : 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $split = config_key($target, "raw_target_split");
|
|
||||||
if($split) {
|
if($split) {
|
||||||
$target_filename .= '.split';
|
$target_filename .= '.split';
|
||||||
push @cmd_pipe, {
|
push @cmd_pipe, {
|
||||||
cmd => [ 'split', '-b', uc($split), '-', "${target_path}/${target_filename}_" ],
|
cmd => [ 'split', '-b', uc($split), '-', "${target_path}/${target_filename}_" ],
|
||||||
check_unsafe => [ { unsafe => "${target_path}/${target_filename}_" } ],
|
check_unsafe => [ { unsafe => "${target_path}/${target_filename}_" } ],
|
||||||
rsh => vinfo_rsh($target, disable_compression => $opts{compress} || config_compress_hash($target, "stream_compress")),
|
rsh => vinfo_rsh($target, disable_compression => $compress || config_compress_hash($target, "stream_compress")),
|
||||||
rsh_compress_in => $opts{compress} || config_compress_hash($target, "stream_compress"),
|
rsh_compress_in => $compress || config_compress_hash($target, "stream_compress"),
|
||||||
rsh_rate_limit_in => config_key($target, "rate_limit"),
|
rsh_rate_limit_in => config_key($target, "rate_limit"),
|
||||||
compressed_ok => ($opts{compress} ? 1 : 0),
|
compressed_ok => ($compress ? 1 : 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1360,10 +1361,10 @@ sub btrfs_send_to_file($$$$;@)
|
||||||
cmd => [ 'dd', 'status=none', 'bs=' . config_key($target, "raw_target_block_size"), "of=${target_path}/${target_filename}.part" ],
|
cmd => [ 'dd', 'status=none', 'bs=' . config_key($target, "raw_target_block_size"), "of=${target_path}/${target_filename}.part" ],
|
||||||
check_unsafe => [ { unsafe => "${target_path}/${target_filename}.part" } ],
|
check_unsafe => [ { unsafe => "${target_path}/${target_filename}.part" } ],
|
||||||
#redirect_to_file => { unsafe => "${target_path}/${target_filename}.part" }, # alternative (use shell redirection), less overhead on local filesystems (barely measurable):
|
#redirect_to_file => { unsafe => "${target_path}/${target_filename}.part" }, # alternative (use shell redirection), less overhead on local filesystems (barely measurable):
|
||||||
rsh => vinfo_rsh($target, disable_compression => $opts{compress} || config_compress_hash($target, "stream_compress")),
|
rsh => vinfo_rsh($target, disable_compression => $compress || config_compress_hash($target, "stream_compress")),
|
||||||
rsh_compress_in => $opts{compress} || config_compress_hash($target, "stream_compress"),
|
rsh_compress_in => $compress || config_compress_hash($target, "stream_compress"),
|
||||||
rsh_rate_limit_in => config_key($target, "rate_limit"),
|
rsh_rate_limit_in => config_key($target, "rate_limit"),
|
||||||
compressed_ok => ($opts{compress} ? 1 : 0),
|
compressed_ok => ($compress ? 1 : 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2549,6 +2550,21 @@ sub config_compress_hash($$)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub config_encrypt_hash($$)
|
||||||
|
{
|
||||||
|
my $config = shift || die;
|
||||||
|
my $config_key = shift || die;
|
||||||
|
my $encrypt_type = config_key($config, $config_key);
|
||||||
|
return undef unless($encrypt_type);
|
||||||
|
die unless($encrypt_type eq "gpg");
|
||||||
|
return {
|
||||||
|
type => $encrypt_type,
|
||||||
|
keyring => config_key($config, "gpg_keyring"),
|
||||||
|
recipient => config_key($config, "gpg_recipient"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub config_dump_keys($;@)
|
sub config_dump_keys($;@)
|
||||||
{
|
{
|
||||||
my $config = shift || die;
|
my $config = shift || die;
|
||||||
|
@ -2981,20 +2997,7 @@ sub macro_send_receive(@)
|
||||||
$uuid_cache{$detail->{uuid}} = $source->{node};
|
$uuid_cache{$detail->{uuid}} = $source->{node};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$ret = btrfs_send_to_file($source, $target, $parent, \$vol_received);
|
||||||
my $encrypt = undef;
|
|
||||||
my $encrypt_type = config_key($config_target, "raw_target_encrypt");
|
|
||||||
if($encrypt_type) {
|
|
||||||
die unless($encrypt_type eq "gpg");
|
|
||||||
$encrypt = { type => $encrypt_type,
|
|
||||||
keyring => config_key($config_target, "gpg_keyring"),
|
|
||||||
recipient => config_key($config_target, "gpg_recipient"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$ret = btrfs_send_to_file($source, $target, $parent, \$vol_received,
|
|
||||||
compress => config_compress_hash($config_target, "raw_target_compress"),
|
|
||||||
encrypt => $encrypt,
|
|
||||||
);
|
|
||||||
ABORTED($config_target, "Failed to send subvolume to raw file") unless($ret);
|
ABORTED($config_target, "Failed to send subvolume to raw file") unless($ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue