Subversion Repositories zfs_utils

Rev

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

Rev 11 Rev 12
Line 13... Line 13...
13
   use lib dirname( abs_path( __FILE__ ) );
13
   use lib dirname( abs_path( __FILE__ ) );
14
}
14
}
15
 
15
 
16
use YAML::Tiny; # pkg install p5-YAML-Tiny-1.74
16
use YAML::Tiny; # pkg install p5-YAML-Tiny-1.74
17
use Data::Dumper;
17
use Data::Dumper;
18
#use Email::Simple; # cpan install Email::Simple
-
 
19
 
18
 
20
my $cwd = $FindBin::RealBin;
19
my $cwd = $FindBin::RealBin;
21
my $configFileName = $cwd . '/sync.yaml';
20
my $configFileName = $cwd . '/sync.yaml';
22
my $replicateScript = $cwd . '/replicate';
21
my $replicateScript = $cwd . '/replicate';
23
 
22
 
Line 172... Line 171...
172
#   $message = "Checking IP $ip\n"  . $message;
171
#   $message = "Checking IP $ip\n"  . $message;
173
   #die "error is $error, message is $message for $ip\n";
172
   #die "error is $error, message is $message for $ip\n";
174
   return ($error, $message);
173
   return ($error, $message);
175
}
174
}
176
 
175
 
-
 
176
sub updateStats {
-
 
177
   my ( $label, $filename, $output ) = @_;
-
 
178
   if ( $output =~ m/bytes\t(\d+).*seconds\t(\d+)/gms ) { # global, multiline, . matches newlines
-
 
179
      my $seconds = $2;
-
 
180
      my $bytes = $1;
-
 
181
      open STATS,">>$filename" or warn "Could not create file $filename: $!\n";
-
 
182
      print STATS &currentTime . "\t$label\t$seconds\t$bytes\n";
-
 
183
      close STATS
-
 
184
   } else {
-
 
185
      warn "updateStats called with invalid report\n";
-
 
186
   }
-
 
187
}
-
 
188
 
177
my @status;   
189
my @status;   
178
my $error = 0;
190
my $error = 0;
179
my $output = '';
191
my $output = '';
180
 
192
 
181
$configuration = &readConfig($configFileName);
193
$configuration = &readConfig($configFileName);
Line 225... Line 237...
225
push @flags, '--verbose' if $configuration->{'verbose'};
237
push @flags, '--verbose' if $configuration->{'verbose'};
226
push @flags, '--verbose' if $configuration->{'verbose'} > 1;
238
push @flags, '--verbose' if $configuration->{'verbose'} > 1;
227
push @flags, "--bwlimit=$configuration->{bandwidth}" if $configuration->{'bandwidth'};
239
push @flags, "--bwlimit=$configuration->{bandwidth}" if $configuration->{'bandwidth'};
228
push @flags, "--filter='$configuration->{filter}'" if $configuration->{'filter'};
240
push @flags, "--filter='$configuration->{filter}'" if $configuration->{'filter'};
229
 
241
 
-
 
242
# prepend the current working directory to stats if it does not have a path
-
 
243
$configuration->{'stats'} = $cwd . "/" . $configuration->{'stats'}
-
 
244
   if $configuration->{'stats'} && $configuration->{'stats'} !~ m/\//;
-
 
245
 
230
# For each dataset, let's find the snapshots we need
246
# For each dataset, let's find the snapshots we need
231
foreach my $sourceDir ( keys %{$configuration->{'source'}->{'dataset'}} ) {
247
foreach my $sourceDir ( keys %{$configuration->{'source'}->{'dataset'}} ) {
232
   #print "Working on $sourceDir\n";
248
   #print "Working on $sourceDir\n";
233
   print "Looking for $sourceDir\n" if $configuration->{'testing'} > 2;
249
   print "Looking for $sourceDir\n" if $configuration->{'testing'} > 2;
234
   print "syncing to $configuration->{target}->{dataset}\n" if $configuration->{'testing'} > 2;
250
   print "syncing to $configuration->{target}->{dataset}\n" if $configuration->{'testing'} > 2;
Line 242... Line 258...
242
   #print "Command is $command\n";
258
   #print "Command is $command\n";
243
   push @status, &currentTime() . " Running $command";
259
   push @status, &currentTime() . " Running $command";
244
   if ( ! $configuration->{'testing'} ) {
260
   if ( ! $configuration->{'testing'} ) {
245
      ($error, $output) = &runCommand( $command );
261
      ($error, $output) = &runCommand( $command );
246
      push @status, $output;
262
      push @status, $output;
-
 
263
      # update stats file if they have requested it
-
 
264
      &updateStats( $sourceDir, $configuration->{'stats'}, $output ) if $configuration->{'stats'};
247
   }
265
   }
248
   push @status, &currentTime() . " Completed command, with status $error";
266
   push @status, &currentTime() . " Completed command, with status $error";
249
}
267
}
250
 
268
 
251
#print "Finished processing\n";
269
#print "Finished processing\n";