Subversion Repositories zfs_utils

Rev

Rev 21 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 22
Line 46... Line 46...
46
# remove it.
46
# remove it.
47
# NOTE: this will not work on ZFS, since ZFS is CopyOnWrite (COW)
47
# NOTE: this will not work on ZFS, since ZFS is CopyOnWrite (COW)
48
# so assuming file is on a ramdisk
48
# so assuming file is on a ramdisk
49
sub shredFile {
49
sub shredFile {
50
   my $filename = shift;
50
   my $filename = shift;
-
 
51
   if ( `which gshred` ) {
51
   `/usr/local/bin/gshred -u -f -s 32 $filename`;
52
      `/usr/local/bin/gshred -u -f $filename`;
-
 
53
   } else {
-
 
54
      warn "gshred not installed, simply deleting $filename\n";
-
 
55
      unlink $filename;
-
 
56
   }
52
}
57
}
53
 
58
 
54
 
59
 
55
# runs a command, redirecting stderr to stdout (which it ignores)
60
# runs a command, redirecting stderr to stdout (which it ignores)
56
# then returns 0 on success.
61
# then returns 0 on success.
Line 83... Line 88...
83
 
88
 
84
    # Check if the zpool is available
89
    # Check if the zpool is available
85
    my ($error, $output) = runCommand("zpool list $zpool");
90
    my ($error, $output) = runCommand("zpool list $zpool");
86
    return 0 unless $error; # zpool is available
91
    return 0 unless $error; # zpool is available
87
 
92
 
-
 
93
    #die "zpool=$zpool\nlocalKey=$local_key\nserver=$remote_server\nremotekey=$remote_key\n" . Dumper( $drives_ref ) . "\n";
88
    # Retrieve geli key from remote server
94
    # Retrieve geli key from remote server
89
    ($error, $output) = runCommand("scp $remote_server:$remote_key $local_key");
95
    ($error, $output) = runCommand("scp $remote_server:$remote_key $local_key");
90
    return ($error, "Failed to retrieve geli key from $remote_server:$remote_key" ) if $error;
96
    return ($error, "Failed to retrieve geli key from $remote_server:$remote_key" ) if $error;
91
 
97
 
92
    # Attach geli key to each drive
98
    # Attach geli key to each drive
93
    foreach my $drive (@$drives_ref) {
99
    foreach my $drive (@$drives_ref) {
94
        ($error, $output) = runCommand("geli attach -k $local_key $drive");
100
        ($error, $output) = runCommand("geli attach -k $local_key -p $drive");
95
         return ($error, "Failed to attach geli key to $drive: $output" ) if $error;
101
         return ($error, "Failed to attach geli key to $drive: $output" ) if $error;
96
    }
102
    }
97
 
103
 
98
    # Import the zpool
104
    # Import the zpool
99
    ($error, $output) = runCommand("zpool import $zpool");
105
    ($error, $output) = runCommand("zpool import $zpool");
Line 147... Line 153...
147
      }
153
      }
148
   }
154
   }
149
   # not on remote machine, so give them waitTime seconds to put it here
155
   # not on remote machine, so give them waitTime seconds to put it here
150
   # we'll loop, checking every $sleepTime seconds until our wait time
156
   # we'll loop, checking every $sleepTime seconds until our wait time
151
   # ($configuration->{'target'}->{'waitTime'}) has expired
157
   # ($configuration->{'target'}->{'waitTime'}) has expired
-
 
158
   my $sleepTime = 60; # time between checks
152
   # set default of 3 minutes if waitTime not set
159
   # default one minute if waitTime not set
153
   $configuration->{'target'}->{'waitTime'} = 300 unless $configuration->{'target'}->{'waitTime'};
160
   $configuration->{'target'}->{'waitTime'} = 60 unless $configuration->{'target'}->{'waitTime'};
154
   # we will check every $sleepTime seconds (ie, every minute)
-
 
155
   my $sleepTime = 60;
-
 
156
   for ( my $i = $configuration->{'target'}->{'waitTime'}; $i > 0; $i -= $sleepTime ) {
161
   for ( my $i = $configuration->{'target'}->{'waitTime'}; $i > 0; $i -= $sleepTime ) {
157
      sleep $sleepTime;
162
      sleep $sleepTime;
158
      # then look for the maintenance flag file on the local machine
163
      # then look for the maintenance flag file on the local machine
159
      return "Maintenance Flag found on local machine" if -f $configuration->{'target'}->{'maintenanceFlag'};
164
      return "Maintenance Flag found on local machine" if -f $configuration->{'target'}->{'maintenanceFlag'};
160
   }
165
   }
Line 238... Line 243...
238
   &sendMail( join( "\n", @status), $configuration, "Maintenance Mode" );
243
   &sendMail( join( "\n", @status), $configuration, "Maintenance Mode" );
239
   exit 1;
244
   exit 1;
240
}
245
}
241
 
246
 
242
# if the zpool is encrypted with geli, make sure it is available
247
# if the zpool is encrypted with geli, make sure it is available
243
($error, $output) = &mountGeliZpool {(
248
($error, $output) = &mountGeliZpool (
244
   $configuration->{'geli'}->{'zpool'},
249
   $configuration->{'geli'}->{'zpool'},
245
   $configuration->{'geli'}->{'localKey'},
250
   $configuration->{'geli'}->{'keyPath'},
246
   $configuration->{'geli'}->{'server'},
251
   $configuration->{'geli'}->{'server'},
247
   $configuration->{'geli'}->{'remoteKey'},
252
   $configuration->{'geli'}->{'remoteKeyPath'},
248
   split( ' ', $configuration->{'geli'}->{'drives'} ) )
253
   [ split( /\s+/, $configuration->{'geli'}->{'drives'} ) ]
-
 
254
   ) 
249
   if exists ( $configuration->{'geli'} );
255
   if exists ( $configuration->{'geli'} );
250
   
256
   
251
if ( $error) { # could not mount datasets
257
if ( $error) { # could not mount datasets
252
   push @status, $output;
258
   push @status, $output;
253
   &sendMail( join( "\n", @status ), $configuration, "Mount Drive Error: [$output]" );
259
   &sendMail( join( "\n", @status ), $configuration, "Mount Drive Error: [$output]" );