Merge pull request #45 from faceprint/master

add --quiet option
This commit is contained in:
Jim Salter 2016-08-17 14:26:58 -04:00 committed by GitHub
commit b4bed03742
1 changed files with 11 additions and 10 deletions

21
syncoid
View File

@ -22,6 +22,7 @@ if ($args{'version'}) {
my $rawsourcefs = $args{'source'}; my $rawsourcefs = $args{'source'};
my $rawtargetfs = $args{'target'}; my $rawtargetfs = $args{'target'};
my $debug = $args{'debug'}; my $debug = $args{'debug'};
my $quiet = $args{'quiet'};
my $zfscmd = '/sbin/zfs'; my $zfscmd = '/sbin/zfs';
my $sshcmd = '/usr/bin/ssh'; my $sshcmd = '/usr/bin/ssh';
@ -169,7 +170,7 @@ sub syncdataset {
my $disp_pvsize = readablebytes($pvsize); my $disp_pvsize = readablebytes($pvsize);
if ($pvsize == 0) { $disp_pvsize = 'UNKNOWN'; } if ($pvsize == 0) { $disp_pvsize = 'UNKNOWN'; }
my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot); my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot);
print "INFO: Sending oldest full snapshot $sourcefs\@$oldestsnap (~ $disp_pvsize) to new target filesystem:\n"; if (!$quiet) { print "INFO: Sending oldest full snapshot $sourcefs\@$oldestsnap (~ $disp_pvsize) to new target filesystem:\n"; }
if ($debug) { print "DEBUG: $synccmd\n"; } if ($debug) { print "DEBUG: $synccmd\n"; }
# make sure target is (still) not currently in receive. # make sure target is (still) not currently in receive.
@ -200,7 +201,7 @@ sub syncdataset {
die "Cannot sync now: $targetfs is already target of a zfs receive process.\n"; die "Cannot sync now: $targetfs is already target of a zfs receive process.\n";
} }
print "INFO: Updating new target filesystem with incremental $sourcefs\@$oldestsnap ... $newsyncsnap (~ $disp_pvsize):\n"; if (!$quiet) { print "INFO: Updating new target filesystem with incremental $sourcefs\@$oldestsnap ... $newsyncsnap (~ $disp_pvsize):\n"; }
if ($debug) { print "DEBUG: $synccmd\n"; } if ($debug) { print "DEBUG: $synccmd\n"; }
system($synccmd) == 0 system($synccmd) == 0
or die "CRITICAL ERROR: $synccmd failed: $?"; or die "CRITICAL ERROR: $synccmd failed: $?";
@ -246,7 +247,7 @@ sub syncdataset {
if ($pvsize == 0) { $disp_pvsize = "UNKNOWN"; } if ($pvsize == 0) { $disp_pvsize = "UNKNOWN"; }
my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot); my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot);
print "Sending incremental $sourcefs\@$matchingsnap ... $newsyncsnap (~ $disp_pvsize):\n"; if (!$quiet) { print "Sending incremental $sourcefs\@$matchingsnap ... $newsyncsnap (~ $disp_pvsize):\n"; }
if ($debug) { print "DEBUG: $synccmd\n"; } if ($debug) { print "DEBUG: $synccmd\n"; }
system("$synccmd") == 0 system("$synccmd") == 0
or die "CRITICAL ERROR: $synccmd failed: $?"; or die "CRITICAL ERROR: $synccmd failed: $?";
@ -270,14 +271,14 @@ sub getargs {
my %novaluearg; my %novaluearg;
my %validarg; my %validarg;
push my @validargs, ('debug','nocommandchecks','version','monitor-version','compress','source-bwlimit','target-bwlimit','dumpsnaps','recursive','r','sshkey','sshport'); push my @validargs, ('debug','nocommandchecks','version','monitor-version','compress','source-bwlimit','target-bwlimit','dumpsnaps','recursive','r','sshkey','sshport','quiet');
foreach my $item (@validargs) { $validarg{$item} = 1; } foreach my $item (@validargs) { $validarg{$item} = 1; }
push my @novalueargs, ('debug','nocommandchecks','version','monitor-version','dumpsnaps','recursive','r'); push my @novalueargs, ('debug','nocommandchecks','version','monitor-version','dumpsnaps','recursive','r','quiet');
foreach my $item (@novalueargs) { $novaluearg{$item} = 1; } foreach my $item (@novalueargs) { $novaluearg{$item} = 1; }
while (my $rawarg = shift(@args)) { while (my $rawarg = shift(@args)) {
my $arg = $rawarg; my $arg = $rawarg;
my $argvalue; my $argvalue = '';
if ($rawarg =~ /=/) { if ($rawarg =~ /=/) {
# user specified the value for a CLI argument with = # user specified the value for a CLI argument with =
# instead of with blank space. separate appropriately. # instead of with blank space. separate appropriately.
@ -586,13 +587,13 @@ sub buildsynccmd {
} }
if ($avail{'sourcembuffer'}) { $synccmd .= " $mbuffercmd $bwlimit $mbufferoptions |"; } if ($avail{'sourcembuffer'}) { $synccmd .= " $mbuffercmd $bwlimit $mbufferoptions |"; }
if ($avail{'localpv'}) { $synccmd .= " $pvcmd -s $pvsize |"; } if ($avail{'localpv'} && !$quiet) { $synccmd .= " $pvcmd -s $pvsize |"; }
$synccmd .= " $recvcmd"; $synccmd .= " $recvcmd";
} elsif ($sourcehost eq '') { } elsif ($sourcehost eq '') {
# local source, remote target. # local source, remote target.
#$synccmd = "$sendcmd | $pvcmd | $args{'compresscmd'} | $mbuffercmd | $sshcmd $targethost '$args{'decompresscmd'} | $mbuffercmd | $recvcmd'"; #$synccmd = "$sendcmd | $pvcmd | $args{'compresscmd'} | $mbuffercmd | $sshcmd $targethost '$args{'decompresscmd'} | $mbuffercmd | $recvcmd'";
$synccmd = "$sendcmd |"; $synccmd = "$sendcmd |";
if ($avail{'localpv'}) { $synccmd .= " $pvcmd -s $pvsize |"; } if ($avail{'localpv'} && !$quiet) { $synccmd .= " $pvcmd -s $pvsize |"; }
if ($avail{'compress'}) { $synccmd .= " $args{'compresscmd'} |"; } if ($avail{'compress'}) { $synccmd .= " $args{'compresscmd'} |"; }
if ($avail{'sourcembuffer'}) { $synccmd .= " $mbuffercmd $args{'source-bwlimit'} $mbufferoptions |"; } if ($avail{'sourcembuffer'}) { $synccmd .= " $mbuffercmd $args{'source-bwlimit'} $mbufferoptions |"; }
$synccmd .= " $sshcmd $targethost '"; $synccmd .= " $sshcmd $targethost '";
@ -608,7 +609,7 @@ sub buildsynccmd {
$synccmd .= "' | "; $synccmd .= "' | ";
if ($avail{'targetmbuffer'}) { $synccmd .= "$mbuffercmd $args{'target-bwlimit'} $mbufferoptions | "; } if ($avail{'targetmbuffer'}) { $synccmd .= "$mbuffercmd $args{'target-bwlimit'} $mbufferoptions | "; }
if ($avail{'compress'}) { $synccmd .= "$args{'decompresscmd'} | "; } if ($avail{'compress'}) { $synccmd .= "$args{'decompresscmd'} | "; }
if ($avail{'localpv'}) { $synccmd .= "$pvcmd -s $pvsize | "; } if ($avail{'localpv'} && !$quiet) { $synccmd .= "$pvcmd -s $pvsize | "; }
$synccmd .= "$recvcmd"; $synccmd .= "$recvcmd";
} else { } else {
#remote source, remote target... weird, but whatever, I'm not here to judge you. #remote source, remote target... weird, but whatever, I'm not here to judge you.
@ -618,7 +619,7 @@ sub buildsynccmd {
if ($avail{'sourcembuffer'}) { $synccmd .= " | $mbuffercmd $args{'source-bwlimit'} $mbufferoptions"; } if ($avail{'sourcembuffer'}) { $synccmd .= " | $mbuffercmd $args{'source-bwlimit'} $mbufferoptions"; }
$synccmd .= "' | "; $synccmd .= "' | ";
if ($avail{'compress'}) { $synccmd .= "$args{'decompresscmd'} | "; } if ($avail{'compress'}) { $synccmd .= "$args{'decompresscmd'} | "; }
if ($avail{'localpv'}) { $synccmd .= "$pvcmd -s $pvsize | "; } if ($avail{'localpv'} && !$quiet) { $synccmd .= "$pvcmd -s $pvsize | "; }
if ($avail{'compress'}) { $synccmd .= "$args{'compresscmd'} | "; } if ($avail{'compress'}) { $synccmd .= "$args{'compresscmd'} | "; }
if ($avail{'localmbuffer'}) { $synccmd .= "$mbuffercmd $mbufferoptions | "; } if ($avail{'localmbuffer'}) { $synccmd .= "$mbuffercmd $mbufferoptions | "; }
$synccmd .= "$sshcmd $targethost '"; $synccmd .= "$sshcmd $targethost '";