Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncoid: Allow hostid as argument #959

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions syncoid
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GetOptions(\%args, "no-command-checks", "monitor-version", "compress=s", "dumpsn
"no-clone-handling", "no-privilege-elevation", "force-delete", "no-rollback", "create-bookmark", "use-hold",
"pv-options=s" => \$pvoptions, "keep-sync-snap", "preserve-recordsize", "mbuffer-size=s" => \$mbuffer_size,
"delete-target-snapshots", "insecure-direct-connection=s", "preserve-properties",
"include-snaps=s@", "exclude-snaps=s@", "exclude-datasets=s@")
"include-snaps=s@", "exclude-snaps=s@", "exclude-datasets=s@", "hostid=s")
or pod2usage(2);

my %compressargs = %{compressargset($args{'compress'} || 'default')}; # Can't be done with GetOptions arg, as default still needs to be set
Expand Down Expand Up @@ -140,6 +140,17 @@ if (length $args{'identifier'}) {
$identifier = "$args{'identifier'}_";
}

my $hostid = hostname();
if (length $args{'hostid'}) {
if ($args{'hostid'} !~ /^[a-zA-Z0-9-_:.]+$/) {
# invalid extra hostid
writelog('WARN', "hostid contains invalid chars!");
pod2usage(2);
exit 127;
}
$hostid = "$args{'hostid'}";
}

# figure out if source and/or target are remote.
$sshcmd = "$sshcmd $args{'sshconfig'} $args{'sshcipher'} $sshoptions $args{'sshport'} $args{'sshkey'}";
writelog('DEBUG', "SSHCMD: $sshcmd");
Expand Down Expand Up @@ -377,7 +388,6 @@ sub syncdataset {
writelog('INFO', "Skipping dataset (syncoid:sync=false): $sourcefs...");
return 0;
} else {
my $hostid = hostname();
my @hosts = split(/,/,$sync);
if (!(grep $hostid eq $_, @hosts)) {
writelog('INFO', "Skipping dataset (syncoid:sync doesn't include $hostid): $sourcefs...");
Expand Down Expand Up @@ -795,7 +805,6 @@ sub syncdataset {
if (defined $args{'use-hold'}) {
my $holdcmd;
my $holdreleasecmd;
my $hostid = hostname();
my $matchingsnapescaped = escapeshellparam($matchingsnap);
my $holdname = "syncoid\_$identifier$hostid";
if ($sourcehost ne '') {
Expand Down Expand Up @@ -1677,8 +1686,6 @@ sub pruneoldsyncsnaps {

if ($rhost ne '') { $rhost = "$sshcmd $rhost"; }

my $hostid = hostname();

my $mysudocmd;
if ($isroot) { $mysudocmd=''; } else { $mysudocmd = $sudocmd; }

Expand Down Expand Up @@ -1754,7 +1761,6 @@ sub newsyncsnap {
}
my $mysudocmd;
if ($isroot) { $mysudocmd = ''; } else { $mysudocmd = $sudocmd; }
my $hostid = hostname();
my %date = getdate();
my $snapname = "syncoid\_$identifier$hostid\_$date{'stamp'}";
my $snapcmd = "$rhost $mysudocmd $zfscmd snapshot $fsescaped\@$snapname\n";
Expand Down