| Line 146... |
Line 146... |
| 146 |
my $subject = shift;
|
146 |
my $subject = shift;
|
| 147 |
push @_, "Shutting down" if $configuration->{'shutdown'};
|
147 |
push @_, "Shutting down" if $configuration->{'shutdown'};
|
| 148 |
&sendMail( join( "\n", @_), $configuration, $subject );
|
148 |
&sendMail( join( "\n", @_), $configuration, $subject );
|
| 149 |
# do not actually shut down the server unless we are told to
|
149 |
# do not actually shut down the server unless we are told to
|
| 150 |
exit unless $configuration->{'shutdown'};
|
150 |
exit unless $configuration->{'shutdown'};
|
| 151 |
&runCommand( "poweroff" ) unless $configuration->{'testing'};
|
- |
|
| 152 |
die "Shutting down machine now\n";
|
151 |
die "Shutting down machine now\n";
|
| - |
|
152 |
&runCommand( "poweroff" ) unless $configuration->{'testing'};
|
| 153 |
}
|
153 |
}
|
| 154 |
|
154 |
|
| 155 |
# returns the current time as a string
|
155 |
# returns the current time as a string
|
| 156 |
sub currentTime {
|
156 |
sub currentTime {
|
| 157 |
my $format = shift;
|
157 |
my $format = shift;
|
| Line 159... |
Line 159... |
| 159 |
$format = '%Y-%m-%d %H-%M-%S' unless $format;
|
159 |
$format = '%Y-%m-%d %H-%M-%S' unless $format;
|
| 160 |
use POSIX;
|
160 |
use POSIX;
|
| 161 |
return POSIX::strftime( $format, localtime() );
|
161 |
return POSIX::strftime( $format, localtime() );
|
| 162 |
}
|
162 |
}
|
| 163 |
|
163 |
|
| - |
|
164 |
# verify a remote machine is up and running
|
| 164 |
sub checkRemoteUp {
|
165 |
sub checkRemoteUp {
|
| 165 |
my $configuration = shift;
|
166 |
my $configuration = shift;
|
| 166 |
my $ip;
|
167 |
my $ip;
|
| 167 |
if ( defined( $configuration->{'target'}->{'server'} ) && $configuration->{'target'}->{'server'} ) {
|
168 |
if ( defined( $configuration->{'target'}->{'server'} ) && $configuration->{'target'}->{'server'} ) {
|
| 168 |
$ip = $configuration->{'target'}->{'server'};
|
169 |
$ip = $configuration->{'target'}->{'server'};
|
| 169 |
} else {
|
170 |
} else {
|
| 170 |
$ip = $configuration->{'source'}->{'server'};
|
171 |
$ip = $configuration->{'source'}->{'server'};
|
| 171 |
}
|
172 |
}
|
| 172 |
my ($error, $message ) = $ip ? &runCommand( "ping -c 1 -t 5 $ip" ) : (0,'No address defined for either target or server' );
|
173 |
my ($error, $message ) = $ip ? &runCommand( "ping -c 1 -t 5 $ip" ) : (0,'No address defined for either target or server' );
|
| 173 |
$message = "Checking IP $ip\n" . $message;
|
174 |
# $message = "Checking IP $ip\n" . $message;
|
| 174 |
#die "error is $error, message is $message for $ip\n";
|
175 |
#die "error is $error, message is $message for $ip\n";
|
| 175 |
return ($error, $message);
|
176 |
return ($error, $message);
|
| 176 |
}
|
177 |
}
|
| 177 |
|
178 |
|
| 178 |
my @status;
|
179 |
my @status;
|
| Line 184... |
Line 185... |
| 184 |
# die Dumper( $configuration ) . "\n";
|
185 |
# die Dumper( $configuration ) . "\n";
|
| 185 |
|
186 |
|
| 186 |
my $servername = `hostname`;
|
187 |
my $servername = `hostname`;
|
| 187 |
chomp $servername;
|
188 |
chomp $servername;
|
| 188 |
|
189 |
|
| - |
|
190 |
push @status, "Replication on $servername has been started at " . ¤tTime();
|
| 189 |
&sendMail( "Replication on $servername has been started, " . ¤tTime(), $configuration, "Replication on $servername started" );
|
191 |
&sendMail( "Replication on $servername has been started, " . ¤tTime(), $configuration, "Replication on $servername started" );
|
| 190 |
|
192 |
|
| 191 |
# see if remote machine is up by sending one ping. Expect response in 5 seconds
|
193 |
# see if remote machine is up by sending one ping. Expect response in 5 seconds
|
| 192 |
( $error,$output) = &checkRemoteUp( $configuration );
|
194 |
( $error,$output) = &checkRemoteUp( $configuration );
|
| 193 |
$configuration->{'up'} = ! $error;
|
195 |
$configuration->{'up'} = ! $error;
|
| 194 |
push @status, "remote machine is " . ( $configuration->{'up'} ? 'Up' : 'Down' ) . "\n";
|
196 |
push @status, "remote machine is " . ( $configuration->{'up'} ? 'Up' : 'Down' ) . "\n";
|
| 195 |
# we can not connect to the remote server, so just shut down
|
197 |
# we can not connect to the remote server, so just shut down
|
| 196 |
&shutdownMachine( $configuration, "No connection to remote machine", @status ) unless $configuration->{'up'};
|
198 |
&shutdownMachine( $configuration, "No connection to remote machine", @status ) unless $configuration->{'up'};
|
| 197 |
|
199 |
|
| 198 |
|
- |
|
| 199 |
# check for maintenance flags, exit if we should go into mainteance mode
|
200 |
# check for maintenance flags, exit if we should go into mainteance mode
|
| 200 |
if ( my $result = &checkMaintenance( $configuration ) ) {
|
201 |
if ( my $result = &checkMaintenance( $configuration ) ) {
|
| 201 |
push @status,$result;
|
202 |
push @status,$result;
|
| 202 |
&sendMail( join( "\n", @status), $configuration, "Maintenance Mode" );
|
203 |
&sendMail( join( "\n", @status), $configuration, "Maintenance Mode" );
|
| 203 |
die;
|
204 |
die;
|
| Line 209... |
Line 210... |
| 209 |
push @status, $error;
|
210 |
push @status, $error;
|
| 210 |
&shutdownMachine( $configuration, "Mount Drive Error: [$output]", @status );
|
211 |
&shutdownMachine( $configuration, "Mount Drive Error: [$output]", @status );
|
| 211 |
}
|
212 |
}
|
| 212 |
|
213 |
|
| 213 |
&sendMail( "Backup has been started at " . ¤tTime(), $configuration, "Backup Starting" );
|
214 |
&sendMail( "Backup has been started at " . ¤tTime(), $configuration, "Backup Starting" );
|
| 214 |
push @status, "Backup started at: " . ¤tTime();
|
215 |
push @status, ¤tTime() . ' Backup started';
|
| 215 |
|
216 |
|
| 216 |
$configuration->{'source'}->{'server'} = $configuration->{'source'}->{'server'} ? $configuration->{'source'}->{'server'} . ':' : '';
|
217 |
$configuration->{'source'}->{'server'} = $configuration->{'source'}->{'server'} ? $configuration->{'source'}->{'server'} . ':' : '';
|
| 217 |
$configuration->{'target'}->{'server'} = $configuration->{'target'}->{'server'} ? $configuration->{'target'}->{'server'} . ':' : '';
|
218 |
$configuration->{'target'}->{'server'} = $configuration->{'target'}->{'server'} ? $configuration->{'target'}->{'server'} . ':' : '';
|
| 218 |
|
219 |
|
| - |
|
220 |
my @flags;
|
| - |
|
221 |
push @flags, '--dryrun' if $configuration->{'dryrun'};
|
| - |
|
222 |
push @flags, '--recurse' if $configuration->{'recurse'};
|
| - |
|
223 |
push @flags, '--verbose' if $configuration->{'verbose'};
|
| - |
|
224 |
push @flags, '--verbose' if $configuration->{'verbose'} > 1;
|
| - |
|
225 |
push @flags, "--bwlimit=$configuration->{bandwidth}" if $configuration->{'bandwidt'};
|
| - |
|
226 |
push @flags, "--filter='$configuration->{filter}'" if $configuration->{'filter'};
|
| - |
|
227 |
|
| 219 |
# For each dataset, let's find the snapshots we need
|
228 |
# For each dataset, let's find the snapshots we need
|
| 220 |
foreach my $sourceDir ( keys %{$configuration->{'source'}->{'dataset'}} ) {
|
229 |
foreach my $sourceDir ( keys %{$configuration->{'source'}->{'dataset'}} ) {
|
| 221 |
print "Looking for $sourceDir\n";
|
230 |
print "Looking for $sourceDir\n" if $configuration->{'testing'} > 2;
|
| 222 |
print "syncing to $configuration->{target}->{targetDataset}\n";
|
231 |
print "syncing to $configuration->{target}->{dataset}\n" if $configuration->{'testing'} > 2;
|
| 223 |
my $command = $replicateScript . ' ' .
|
232 |
my $command = $replicateScript . ' ' . join( ' ', @flags ) . ' ' .
|
| - |
|
233 |
'--source=' .
|
| 224 |
$configuration->{'source'}->{'server'} .
|
234 |
$configuration->{'source'}->{'server'} .
|
| 225 |
$configuration->{'source'}->{'dataset'}->{$sourceDir} . '/' . $sourceDir . ' ' .
|
235 |
$configuration->{'source'}->{'dataset'}->{$sourceDir} . '/' . $sourceDir . ' ' .
|
| - |
|
236 |
'--target=' .
|
| 226 |
$configuration->{'target'}->{'server'} .
|
237 |
$configuration->{'target'}->{'server'} .
|
| 227 |
$configuration->{'target'}->{'targetDataset'} . '/' . $sourceDir;
|
238 |
$configuration->{'target'}->{'dataset'} . '/' . $sourceDir;
|
| 228 |
push @status, "=== Running $command at " . ¤tTime();
|
239 |
push @status, ¤tTime() . " Running $command";
|
| - |
|
240 |
if ( ! $configuration->{'testing'} ) {
|
| 229 |
($error, $output) = &runCommand( $command ) unless $configuration->{'testing'};
|
241 |
($error, $output) = &runCommand( $command );
|
| 230 |
push @status, $output;
|
242 |
push @status, $output;
|
| - |
|
243 |
}
|
| 231 |
push @status, "=== Completed $command with status $error at " . ¤tTime();
|
244 |
push @status, ¤tTime() . " Completed command, with status $error";
|
| 232 |
}
|
245 |
}
|
| 233 |
|
246 |
|
| 234 |
push @status, "==== Backup finished at: " . ¤tTime();
|
247 |
push @status, ¤tTime() . ' Backup finished';
|
| 235 |
|
248 |
|
| 236 |
if ($configuration->{'testing'}) {
|
249 |
if ($configuration->{'testing'}) {
|
| 237 |
print join( "\n", @status ) . "\n";
|
250 |
print join( "\n", @status ) . "\n";
|
| 238 |
} else {
|
251 |
} else {
|
| 239 |
&shutdownMachine( $configuration, "Backup Complete", @status );
|
252 |
&shutdownMachine( $configuration, "Backup Complete", @status );
|