3 # Perform a backup and send the results to someone
6 require './fsdump-lib.pl';
7 $dump = &get_dump($ARGV[0]);
8 $dump->{'id'} || die "Dump $ARGV[0] does not exist!";
10 # Check if this backup is already running
11 &foreign_require("proc", "proc-lib.pl");
12 @procs = &proc::list_processes();
13 @running = &running_dumps(\@procs);
14 ($running) = grep { $_->{'id'} eq $dump->{'id'} &&
15 $_->{'pid'} != $$ } @running;
17 $sfile = "$module_config_directory/$dump->{'id'}.$$.status";
19 # Already running! Do nothing ..
21 $out = &text('email_already', $running->{'pid'})."\n";
25 %status = ( 'status' => 'running',
28 &write_file($sfile, \%status);
30 if ($dump->{'email'}) {
31 # Save output for mailing
37 open(OUT, ">/dev/null");
40 # Create tape change wrapper
43 $bok = &execute_before($dump, OUT, 0);
44 if (!$bok && !$dump->{'beforefok'}) {
45 # Before command failed!
46 print OUT "\n$text{'email_ebefore'}\n";
47 $status{'status'} = 'failed';
52 $ok = &execute_dump($dump, OUT, 0, 1, $now);
54 # Re-update the status file
56 # Worked .. but verify if asked
57 if ($dump->{'reverify'}) {
58 print OUT "\n$text{'email_verify'}\n";
59 $ok = &verify_dump($dump, OUT, 0, 1, $now);
62 $status{'status'} = 'complete';
65 $status{'status'} = 'verifyfailed';
69 $status{'status'} = 'failed';
72 $status{'end'} = time();
73 &write_file($sfile, \%status);
75 if ($status{'status'} eq 'complete') {
76 # Execute the post-backup script
77 $bok = &execute_after($dump, OUT, 0);
78 if (!$bok && !$dump->{'afterfok'}) {
79 print OUT "\n$text{'email_eafter'}\n";
80 $status{'status'} = 'failed';
98 if ($out && $dump->{'email'} && &foreign_check("mailboxes")) {
100 &foreign_require("mailboxes", "mailboxes-lib.pl");
101 $host = &get_system_hostname();
102 @dirs = &dump_directories($dump);
103 $dirs = join(", ", @dirs);
104 %hash = ( %$dirs, 'dirs' => $dirs );
105 local $subject = &substitute_template($dump->{'subject'}, \%hash) ||
106 &text('email_subject', $dirs, $host);
107 local $data = &text('email_subject', $dirs, $host)."\n\n";
111 $data .= $text{'email_ok'}."\n";
114 $data .= $text{'email_failed'}."\n";
118 if (!$ok || !$config{'error_email'}) {
119 # Only send email upon failure, or it requested always
120 &mailboxes::send_text_mail(&mailboxes::get_from_address(),
125 $config{'smtp_server'});
129 # Check for any dumps scheduled to run after this one
130 foreach $follow (&list_dumps()) {
131 if ($follow->{'follow'} eq $dump->{'id'} && $follow->{'enabled'} == 2) {
132 system("$cron_cmd $follow->{'id'}");