Subversion Repositories zfs_utils

Rev

Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 7
Line 156... Line 156...
156
      # Now, build the target command
156
      # Now, build the target command
157
      my $targetCommand = 'zfs receive ' . 
157
      my $targetCommand = 'zfs receive ' . 
158
                          ( ! $config->{'target'}->{'server'} && $config->{'verbose'} > 1 ? '-v ' : '') .
158
                          ( ! $config->{'target'}->{'server'} && $config->{'verbose'} > 1 ? '-v ' : '') .
159
                          $config->{'target'}->{'dataset'};
159
                          $config->{'target'}->{'dataset'};
160
      $targetCommand = "ssh $config->{target}->{server} '$targetCommand'" if  $config->{'target'}->{'server'};
160
      $targetCommand = "ssh $config->{target}->{server} '$targetCommand'" if  $config->{'target'}->{'server'};
-
 
161
      # if the command pv is installed
-
 
162
      if ( `which pv` ) {
-
 
163
         my $tags;
-
 
164
         # add bandwdith limits, if requested
-
 
165
         $tags = " --si -L $config->{bwlimit} " if $config->{'bwlimit'};
-
 
166
         # if interactive, or if we are in dry run, add thermometer
-
 
167
         $tags .= '-petrs ' . $config->{'report'}->{'Bytes Transferred'} if -t *STDOUT || $config->{'dryrun'};
-
 
168
         $sourceCommand .= " | pv $tags" if $tags;
-
 
169
      }
161
      # return the command
170
      # return the command
162
      return $sourceCommand . ' | ' . $targetCommand;
171
      return $sourceCommand . ' | ' . $targetCommand;
163
   } else { # source and target are in sync, so do nothing
172
   } else { # source and target are in sync, so do nothing
164
      return '# Nothing new to sync';
173
      return '# Nothing new to sync';
165
   }
174
   }
Line 233... Line 242...
233
         --target|t  - Alternate way to pass target dataset
242
         --target|t  - Alternate way to pass target dataset
234
         --filter|f  - Filter (regex) to limit source snapshots to process
243
         --filter|f  - Filter (regex) to limit source snapshots to process
235
         --dryrun|n  - Only displays command(s) to be run
244
         --dryrun|n  - Only displays command(s) to be run
236
         --recurse|r - Process dataset and all child datasets
245
         --recurse|r - Process dataset and all child datasets
237
         --verbose|v - increase verbosity of output
246
         --verbose|v - increase verbosity of output
-
 
247
         --bwlimit   - Limit the speed of the connect to # bytes/s. KMGT allowed 
238
      
248
      
239
      May use short flags with bundling, ie -nrvv is valid for 
249
      May use short flags with bundling, ie -nrvv is valid for 
240
      --dryrun --recurse --verbose --verbose
250
      --dryrun --recurse --verbose --verbose
241
      
251
      
242
      Either source or target must contain a DNS name or IP address of a remote
252
      Either source or target must contain a DNS name or IP address of a remote
Line 249... Line 259...
249
      that string will be used from the source dataset
259
      that string will be used from the source dataset
250
      
260
      
251
      By default, only error messages are displayed. verbose will display statistics
261
      By default, only error messages are displayed. verbose will display statistics
252
      on size and transfer time. Invoking twice will display entire output of
262
      on size and transfer time. Invoking twice will display entire output of
253
      send/receive (whichever is the local machine)
263
      send/receive (whichever is the local machine)
-
 
264
      
-
 
265
      Example:
-
 
266
         $me -r prod.example.org:pool/mydata -t pool/backup/mydata \
-
 
267
            --bwlimit=5M --filter='(\\d{4}.\\d{2}.\\d{2}.\\d{2}.\\d{2})'
-
 
268
 
-
 
269
         Would sync pool/mydata and all child datasets on prod.example.org to
-
 
270
         pool/backup/mydata on the local server. Only the snapshots which had a
-
 
271
         datetime stamp matching the --filter rule would be used. The transfer
-
 
272
         would not exceed 5MB/s (40Mb/s) if the pv app was installed
254
   EOF
273
   EOF
255
   # get rid of indentation
274
   # get rid of indentation
256
   $helpMessage =~ s/^      //;
275
   $helpMessage =~ s/^      //;
257
   $helpMessage =~ s/\n      /\n/g;
276
   $helpMessage =~ s/\n      /\n/g;
258
   print $helpMessage;
277
   print $helpMessage;
Line 264... Line 283...
264
   'source|s=s',
283
   'source|s=s',
265
   'target|t=s',
284
   'target|t=s',
266
   'filter|f=s',
285
   'filter|f=s',
267
   'dryrun|n',
286
   'dryrun|n',
268
   'recurse|r',
287
   'recurse|r',
-
 
288
   'bwlimit=i',
269
   'verbose|v+',
289
   'verbose|v+',
270
   'help|h'
290
   'help|h'
271
);
291
);
272
 
292
 
273
&help() if $config->{'help'};
293
&help() if $config->{'help'};
Line 314... Line 334...
314
$config->{'report'}->{'Elapsed Time'} = $config->{'report'}->{'End Time'} - $config->{'report'}->{'Start Time'};
334
$config->{'report'}->{'Elapsed Time'} = $config->{'report'}->{'End Time'} - $config->{'report'}->{'Start Time'};
315
if ( $config->{'verbose'} ) {
335
if ( $config->{'verbose'} ) {
316
   if ( $config->{'dryrun'} ) {
336
   if ( $config->{'dryrun'} ) {
317
      print "Would have transferred $config->{'report'}->{'Bytes Transferred'} bytes\n";
337
      print "Would have transferred $config->{'report'}->{'Bytes Transferred'} bytes\n";
318
   } else {
338
   } else {
319
      print "Transferred $config->{'report'}->{'Bytes Transferred'} bytes in $config->{'report'}->{'Elapsed Time'} seconds\n";
339
      print "bytes\t$config->{'report'}->{'Bytes Transferred'}\nseconds\t$config->{'report'}->{'Elapsed Time'}\n";
320
   }
340
   }
321
}
341
}
322
1;
342
1;