Pre and post backup commands

This commit is contained in:
Jamie Cameron
2010-03-08 17:04:40 -08:00
parent 55ff07e067
commit cda10fd82d
5 changed files with 69 additions and 12 deletions

View File

@ -9,11 +9,31 @@ require './backup-config-lib.pl';
$backup = &get_backup($ARGV[0]);
$backup || die "Failed to find backup $ARGV[0]";
# Run the pre-backup command, if any
if ($backup->{'pre'}) {
$preout = &backquote_command("($backup->{'pre'}) 2>&1 </dev/null");
$premsg = &text('email_pre', $backup->{'pre'})."\n".
$preout."\n";
if ($?) {
$err = $text{'email_prefailed'};
}
}
# Do it
@mods = split(/\s+/, $backup->{'mods'});
$err = &execute_backup(\@mods, $backup->{'dest'}, \$size, undef,
$backup->{'configfile'}, $backup->{'nofiles'},
[ split(/\t+/, $backup->{'others'}) ]);
if (!$err) {
$err = &execute_backup(\@mods, $backup->{'dest'}, \$size, undef,
$backup->{'configfile'}, $backup->{'nofiles'},
[ split(/\t+/, $backup->{'others'}) ]);
}
# Run the post-backup command, if any
if (!$err) {
$postout = &backquote_command("($backup->{'post'}) 2>&1 </dev/null");
$postmsg = "\n".
&text('email_post', $backup->{'post'})."\n".
$postout."\n";
}
# Send off the results
if (($err || $backup->{'emode'} == 0) && $backup->{'email'}) {
@ -26,7 +46,8 @@ if (($err || $backup->{'emode'} == 0) && $backup->{'email'}) {
$nice =~ s/<[^>]+>//g;
$err =~ s/<[^>]+>//g;
if ($err) {
$msg = $text{'email_mods'}."\n".
$msg = $premsg.
$text{'email_mods'}."\n".
$mlist.
"\n".
&text('email_failed', $nice)."\n\n".
@ -34,13 +55,16 @@ if (($err || $backup->{'emode'} == 0) && $backup->{'email'}) {
$subject = &text('email_sfailed', $host);
}
else {
$msg = $text{'email_mods'}."\n".
$msg = $premsg.
$text{'email_mods'}."\n".
$mlist.
"\n".
&text('email_ok', $nice)."\n".
&text('email_final', &nice_size($size))."\n";
&text('email_final', &nice_size($size))."\n".
$postmsg;
$subject = &text('email_sok', $host);
}
print STDERR $msg,"\n";
&mailboxes::send_text_mail($config{'from_addr'} ||
&mailboxes::get_from_address(),
$backup->{'email'},