| Line 112... |
Line 112... |
| 112 |
$config->{'source'}->{'lastSnap'}
|
112 |
$config->{'source'}->{'lastSnap'}
|
| 113 |
);
|
113 |
);
|
| 114 |
# prepend 'zfs send' and the flags. Note that verbose is only for the one which is local
|
114 |
# prepend 'zfs send' and the flags. Note that verbose is only for the one which is local
|
| 115 |
$sourceCommand = 'zfs send -' .
|
115 |
$sourceCommand = 'zfs send -' .
|
| 116 |
( $config->{'recurse'} ? 'R' : '' ) . # recurse if they asked for it
|
116 |
( $config->{'recurse'} ? 'R' : '' ) . # recurse if they asked for it
|
| 117 |
# turn on verbose if they asked for level 2 AND if source is local
|
117 |
# Tell it to give us the size in bytes
|
| 118 |
'Pn' .
|
118 |
'Pn' .
|
| 119 |
# this is the part that asks for incremental
|
119 |
# this is the part that asks for incremental
|
| 120 |
'I ' .
|
120 |
'I ' .
|
| 121 |
$sourceCommand;
|
121 |
$sourceCommand;
|
| 122 |
# wrap the ssh call if this is remote
|
122 |
# wrap the ssh call if this is remote
|
| 123 |
$sourceCommand = "ssh $config->{source}->{server} '$sourceCommand'" if $config->{'source'}->{'server'};
|
123 |
$sourceCommand = "ssh $config->{source}->{server} '$sourceCommand'" if $config->{'source'}->{'server'};
|
| 124 |
print "Checking Size with\n$sourceCommand\n" if $config->{'verbose'} > 2;
|
124 |
print "Checking Size with\n$sourceCommand\n" if $config->{'verbose'} > 3;
|
| 125 |
my ( $error, $output ) = &run( $sourceCommand );
|
125 |
my ( $error, $output ) = &run( $sourceCommand );
|
| 126 |
return -1 if $error;
|
126 |
return -1 if $error;
|
| 127 |
# the size is the second column (tab separated) of the last line (\n separated) in $output
|
127 |
# the size is the second column (tab separated) of the last line (\n separated) in $output
|
| 128 |
return (
|
128 |
return (
|
| 129 |
split(
|
129 |
split(
|
| Line 152... |
Line 152... |
| 152 |
);
|
152 |
);
|
| 153 |
# prepend 'zfs send' and the flags. Note that verbose is only for the one which is local
|
153 |
# prepend 'zfs send' and the flags. Note that verbose is only for the one which is local
|
| 154 |
$sourceCommand = 'zfs send -' .
|
154 |
$sourceCommand = 'zfs send -' .
|
| 155 |
( $config->{'recurse'} ? 'R' : '' ) . # recurse if they asked for it
|
155 |
( $config->{'recurse'} ? 'R' : '' ) . # recurse if they asked for it
|
| 156 |
# turn on verbose if they asked for level 2 AND if source is local
|
156 |
# turn on verbose if they asked for level 2 AND if source is local
|
| 157 |
( $config->{'verbose'} > 1 && ! $config->{'source'}->{'server'} ? 'v' : '' ) .
|
157 |
( $config->{'verbose'} > 2 && ! $config->{'source'}->{'server'} ? 'v' : '' ) .
|
| 158 |
# this is the part that asks for incremental
|
158 |
# this is the part that asks for incremental
|
| 159 |
'I ' .
|
159 |
'I ' .
|
| 160 |
$sourceCommand;
|
160 |
$sourceCommand;
|
| 161 |
# wrap the ssh call if this is remote
|
161 |
# wrap the ssh call if this is remote
|
| 162 |
$sourceCommand = "ssh $config->{source}->{server} '$sourceCommand'" if $config->{'source'}->{'server'};
|
162 |
$sourceCommand = "ssh $config->{source}->{server} '$sourceCommand'" if $config->{'source'}->{'server'};
|
| 163 |
# Now, build the target command
|
163 |
# Now, build the target command
|
| 164 |
my $targetCommand = 'zfs receive ' .
|
164 |
my $targetCommand = 'zfs receive ' .
|
| 165 |
( ! $config->{'target'}->{'server'} && $config->{'verbose'} > 1 ? '-v ' : '') .
|
165 |
( ! $config->{'target'}->{'server'} && $config->{'verbose'} > 2 ? '-v ' : '') .
|
| 166 |
$config->{'target'}->{'dataset'};
|
166 |
$config->{'target'}->{'dataset'};
|
| 167 |
$targetCommand = "ssh $config->{target}->{server} '$targetCommand'" if $config->{'target'}->{'server'};
|
167 |
$targetCommand = "ssh $config->{target}->{server} '$targetCommand'" if $config->{'target'}->{'server'};
|
| 168 |
# if the command pv is installed
|
168 |
# if the command pv is installed
|
| 169 |
if ( `which pv` ) {
|
169 |
if ( `which pv` ) {
|
| 170 |
my $tags;
|
170 |
my $tags;
|
| Line 264... |
Line 264... |
| 264 |
|
264 |
|
| 265 |
filter is a string which is a valid regular expression. Only snapshots matching
|
265 |
filter is a string which is a valid regular expression. Only snapshots matching
|
| 266 |
that string will be used from the source dataset
|
266 |
that string will be used from the source dataset
|
| 267 |
|
267 |
|
| 268 |
By default, only error messages are displayed. verbose will display statistics
|
268 |
By default, only error messages are displayed. verbose will display statistics
|
| 269 |
on size and transfer time. Invoking twice will display entire output of
|
269 |
on size and transfer time. Twice will give the commands, and three times will
|
| 270 |
send/receive (whichever is the local machine)
|
270 |
display entire output of send/receive (whichever is the local machine)
|
| 271 |
|
271 |
|
| 272 |
Example:
|
272 |
Example:
|
| 273 |
$me -r prod.example.org:pool/mydata -t pool/backup/mydata \
|
273 |
$me -r prod.example.org:pool/mydata -t pool/backup/mydata \
|
| 274 |
--bwlimit=5M --filter='(\\d{4}.\\d{2}.\\d{2}.\\d{2}.\\d{2})'
|
274 |
--bwlimit=5M --filter='(\\d{4}.\\d{2}.\\d{2}.\\d{2}.\\d{2})'
|
| 275 |
|
275 |
|
| Line 328... |
Line 328... |
| 328 |
# to calculate, we won't run it unless they want a report
|
328 |
# to calculate, we won't run it unless they want a report
|
| 329 |
$config->{'report'}->{'Bytes Transferred'} = &findSize( $config ) if $config->{'verbose'};
|
329 |
$config->{'report'}->{'Bytes Transferred'} = &findSize( $config ) if $config->{'verbose'};
|
| 330 |
|
330 |
|
| 331 |
# actually creates the commands to do the replicate
|
331 |
# actually creates the commands to do the replicate
|
| 332 |
my $commands = &createCommands( $config );
|
332 |
my $commands = &createCommands( $config );
|
| 333 |
print "$commands\n" if $config->{'verbose'} or $config->{'dryrun'};
|
333 |
print "$commands\n" if $config->{'verbose'} > 1 or $config->{'dryrun'};
|
| 334 |
if ( $config->{'dryrun'} ) {
|
334 |
if ( $config->{'dryrun'} ) {
|
| 335 |
print "Dry Run\n";
|
335 |
print "Dry Run\n";
|
| 336 |
} else {
|
336 |
} else {
|
| 337 |
print qx/$commands/ if $commands =~ m/^[a-zA-Z]/;
|
337 |
print qx/$commands/ if $commands =~ m/^[a-zA-Z]/;
|
| 338 |
}
|
338 |
}
|
| 339 |
|
339 |
|
| 340 |
$config->{'report'}->{'End Time'} = time;
|
340 |
$config->{'report'}->{'End Time'} = time;
|
| 341 |
$config->{'report'}->{'Elapsed Time'} = $config->{'report'}->{'End Time'} - $config->{'report'}->{'Start Time'};
|
341 |
$config->{'report'}->{'Elapsed Time'} = $config->{'report'}->{'End Time'} - $config->{'report'}->{'Start Time'};
|
| 342 |
if ( $config->{'verbose'} ) {
|
342 |
if ( $config->{'verbose'} ) {
|
| 343 |
if ( $config->{'dryrun'} ) {
|
343 |
if ( $config->{'dryrun'} ) {
|
| 344 |
print "Would have transferred $config->{'report'}->{'Bytes Transferred'} bytes\n";
|
344 |
print "Would have transferred $config->{'report'}->{'Bytes Transferred'} bytes\n";
|
| 345 |
} else {
|
345 |
} else {
|
| 346 |
print "bytes\t$config->{'report'}->{'Bytes Transferred'}\nseconds\t$config->{'report'}->{'Elapsed Time'}\n";
|
346 |
print "bytes\t$config->{'report'}->{'Bytes Transferred'}\nseconds\t$config->{'report'}->{'Elapsed Time'}\n";
|
| 347 |
}
|
347 |
}
|