Subversion Repositories zfs_utils

Rev

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

Rev 14 Rev 16
Line 71... Line 71...
71
}
71
}
72
   
72
   
73
# grabs the encryption key from the remote server, and uses it to unlock the 
73
# grabs the encryption key from the remote server, and uses it to unlock the 
74
# datasets, then mount the drives.
74
# datasets, then mount the drives.
75
# a return of '' is success, anything else is an error
75
# a return of '' is success, anything else is an error
76
# THIS IS SERIOUSLY BROKEN. DON'T USE
-
 
77
sub mountDrives {
76
sub mountDrives {
78
   my $configuration = shift;
77
   my $configuration = shift;
79
   return (0, 'No encrypted target found' ) unless defined( $configuration->{'target'}->{'encryptionKeyPath'} ) && $configuration->{'target'}->{'encryptionKeyPath'};
78
   return (0, 'No encrypted target found' ) unless defined( $configuration->{'target'}->{'encryptionKeyPath'} ) && $configuration->{'target'}->{'encryptionKeyPath'};
80
   # try to grab the file from the remote machine
79
   # try to grab the file from the remote machine
81
   &runCommand( "scp $configuration->{remoteMachine}->{ip}:$configuration->{remoteMachine}->{encryptionKeyPath} $configuration->{localMachine}->{encryptionKeyPath}" );
80
   &runCommand( "scp $configuration->{remoteMachine}->{ip}:$configuration->{remoteMachine}->{encryptionKeyPath} $configuration->{localMachine}->{encryptionKeyPath}" );
Line 113... Line 112...
113
# checks to see if we should be in maintenance mode
112
# checks to see if we should be in maintenance mode
114
# if $remoteMachine->{'maintenanceMode'} exists, set mode
113
# if $remoteMachine->{'maintenanceMode'} exists, set mode
115
# otherwise, wait localMachine->{'waittime'} minutes, then check
114
# otherwise, wait localMachine->{'waittime'} minutes, then check
116
# $localMachine->{'maintenanceMode'}.
115
# $localMachine->{'maintenanceMode'}.
117
# if neither exists, begin sync
116
# if neither exists, begin sync
118
# THIS IS BROKEN, DON'T USE
-
 
119
sub checkMaintenance {
117
sub checkMaintenance {
120
   my $configuration = shift;
118
   my $configuration = shift;
121
   return 0 unless # exit if maintenanceFlag has not been set at all
119
   return 0 unless # exit if maintenanceFlag has not been set at all
122
     ( defined( $configuration->{'target'}->{'maintenanceFlag'} ) && $configuration->{'target'}->{'maintenanceFlag'} ) ||
120
     ( defined( $configuration->{'target'}->{'maintenanceFlag'} ) && $configuration->{'target'}->{'maintenanceFlag'} ) ||
123
     ( defined( $configuration->{'source'}->{'maintenanceFlag'} ) && $configuration->{'source'}->{'maintenanceFlag'} );
121
     ( defined( $configuration->{'source'}->{'maintenanceFlag'} ) && $configuration->{'source'}->{'maintenanceFlag'} );
Line 153... Line 151...
153
 
151
 
154
# returns the current time as a string
152
# returns the current time as a string
155
sub currentTime {
153
sub currentTime {
156
   my $format = shift;
154
   my $format = shift;
157
   # default to YY-MM-DD HH-MM-SS
155
   # default to YY-MM-DD HH-MM-SS
158
   $format = '%Y-%m-%d %H-%M-%S' unless $format;
156
   $format = '%Y-%m-%d %H:%M:%S' unless $format;
159
   use POSIX;
157
   use POSIX;
160
   return POSIX::strftime( $format, localtime() );
158
   return POSIX::strftime( $format, localtime() );
161
}
159
}
162
 
160
 
163
# verify a remote machine is up and running
161
# verify a remote machine is up and running
Line 179... Line 177...
179
   my ( $label, $filename, $output ) = @_;
177
   my ( $label, $filename, $output ) = @_;
180
   if ( $output =~ m/bytes\t(\d+).*seconds\t(\d+)/gms ) { # global, multiline, . matches newlines
178
   if ( $output =~ m/bytes\t(\d+).*seconds\t(\d+)/gms ) { # global, multiline, . matches newlines
181
      my $seconds = $2;
179
      my $seconds = $2;
182
      my $bytes = $1;
180
      my $bytes = $1;
183
      open STATS,">>$filename" or warn "Could not create file $filename: $!\n";
181
      open STATS,">>$filename" or warn "Could not create file $filename: $!\n";
184
      print STATS &currentTime . "\t$label\t$seconds\t$bytes\n";
182
      print STATS &currentTime('') . "\t$label\t$seconds\t$bytes\n";
185
      close STATS
183
      close STATS
186
   } else {
184
   } else {
187
      warn "updateStats called with invalid report\n";
185
      warn "updateStats called with invalid report\n";
188
   }
186
   }
189
}
187
}
Line 234... Line 232...
234
$configuration->{'target'}->{'server'} = $configuration->{'target'}->{'server'} ? $configuration->{'target'}->{'server'} . ':' : '';
232
$configuration->{'target'}->{'server'} = $configuration->{'target'}->{'server'} ? $configuration->{'target'}->{'server'} . ':' : '';
235
 
233
 
236
my @flags;
234
my @flags;
237
push @flags, '--dryrun' if $configuration->{'dryrun'};
235
push @flags, '--dryrun' if $configuration->{'dryrun'};
238
push @flags, '--recurse' if $configuration->{'recurse'};
236
push @flags, '--recurse' if $configuration->{'recurse'};
239
push @flags, '--verbose' if $configuration->{'verbose'};
237
push @flags, '-' . 'v'x$configuration->{verbose} if $configuration->{'verbose'};
240
push @flags, '--verbose' if $configuration->{'verbose'} > 1;
-
 
241
push @flags, "--bwlimit=$configuration->{bandwidth}" if $configuration->{'bandwidth'};
238
push @flags, "--bwlimit=$configuration->{bandwidth}" if $configuration->{'bandwidth'};
242
push @flags, "--filter='$configuration->{filter}'" if $configuration->{'filter'};
239
push @flags, "--filter='$configuration->{filter}'" if $configuration->{'filter'};
243
 
240
 
-
 
241
# die join( ' ', @flags ) . "\n";
-
 
242
 
244
# prepend the current working directory to stats if it does not have a path
243
# prepend the current working directory to stats if it does not have a path
245
$configuration->{'stats'} = $cwd . "/" . $configuration->{'stats'}
244
$configuration->{'stats'} = $cwd . "/" . $configuration->{'stats'}
246
   if $configuration->{'stats'} && $configuration->{'stats'} !~ m/\//;
245
   if $configuration->{'stats'} && $configuration->{'stats'} !~ m/\//;
247
 
246
 
248
# For each dataset, let's find the snapshots we need
247
# For each dataset, let's find the snapshots we need
Line 259... Line 258...
259
                 $configuration->{'target'}->{'dataset'} . '/' . $sourceDir;
258
                 $configuration->{'target'}->{'dataset'} . '/' . $sourceDir;
260
   #print "Command is $command\n";
259
   #print "Command is $command\n";
261
   push @status, &currentTime() . " Running $command";
260
   push @status, &currentTime() . " Running $command";
262
   if ( ! $configuration->{'testing'} ) {
261
   if ( ! $configuration->{'testing'} ) {
263
      ($error, $output) = &runCommand( $command );
262
      ($error, $output) = &runCommand( $command );
264
      push @status, $output;
263
      push @status, "Dataset\t$sourceDir\n$output";
265
      # update stats file if they have requested it
264
      # update stats file if they have requested it
266
      &updateStats( $sourceDir, $configuration->{'stats'}, $output ) if $configuration->{'stats'};
265
      &updateStats( $sourceDir, $configuration->{'stats'}, $output ) if $configuration->{'stats'};
267
   }
266
   }
268
   push @status, &currentTime() . " Completed command, with status $error";
267
   push @status, &currentTime() . " Completed command, with status $error";
269
}
268
}