Do not require user to be specified for syncoid

This brings the behavior of syncoid into line with the documentation,
which suggests that :, rather than @, is required when specifying a
remote dataset. The behavior of a TARGET or SOURCE that begins with :
is altered to allow for local dataset names with colons in them.

The name of the control socket is changed slightly.
This commit is contained in:
Antonio Russo 2018-04-29 19:13:13 -04:00
parent 979cb8bc3d
commit e94fb332ea
1 changed files with 15 additions and 7 deletions

22
syncoid
View File

@ -930,20 +930,22 @@ sub getssh {
my $isroot; my $isroot;
my $socket; my $socket;
# if we got passed something with an @ in it, we assume it's an ssh connection, eg root@myotherbox # if we got passed something with an : in it, but not at the beginning,
if ($fs =~ /\@/) { # we assume it's an ssh connection, eg root@myotherbox:pool/dataset
if ($fs =~ /^[^:]+:/) {
$rhost = $fs; $rhost = $fs;
$fs =~ s/^\S*\@\S*://; # host and usernames must not have colons
$fs =~ s/^[^:]*://;
$rhost =~ s/:\Q$fs\E$//; $rhost =~ s/:\Q$fs\E$//;
my $remoteuser = $rhost; if ($rhost =~ /^root\@/ ) { $isroot = 1; } else { $isroot = 0; }
$remoteuser =~ s/\@.*$//;
if ($remoteuser eq 'root') { $isroot = 1; } else { $isroot = 0; }
# now we need to establish a persistent master SSH connection # now we need to establish a persistent master SSH connection
$socket = "/tmp/syncoid-$remoteuser-$rhost-" . time(); $socket = "/tmp/syncoid-$rhost-" . time();
open FH, "$sshcmd -M -S $socket -o ControlPersist=1m $args{'sshport'} $rhost exit |"; open FH, "$sshcmd -M -S $socket -o ControlPersist=1m $args{'sshport'} $rhost exit |";
close FH; close FH;
$rhost = "-S $socket $rhost"; $rhost = "-S $socket $rhost";
} else { } else {
# remove a leading :, if any
$fs =~ s/^://;
my $localuid = $<; my $localuid = $<;
if ($localuid == 0) { $isroot = 1; } else { $isroot = 0; } if ($localuid == 0) { $isroot = 1; } else { $isroot = 0; }
} }
@ -1131,6 +1133,12 @@ syncoid - ZFS snapshot replication tool
SOURCE Source ZFS dataset. Can be either local or remote SOURCE Source ZFS dataset. Can be either local or remote
TARGET Target ZFS dataset. Can be either local or remote TARGET Target ZFS dataset. Can be either local or remote
Notes:
If HOST is empty, a local dataset is assumed. This is required to specify a
local dataset that has a colon (:) in it, e.g.,
:poolname/dataset:name
Options: Options:
--compress=FORMAT Compresses data during transfer. Currently accepted options are gzip, pigz-fast, pigz-slow, lzo (default) & none --compress=FORMAT Compresses data during transfer. Currently accepted options are gzip, pigz-fast, pigz-slow, lzo (default) & none