Handle hostnames with upper-case letters
[webmin.git] / fsdump / backup.cgi
1 #!/usr/local/bin/perl
2 # backup.cgi
3 # Run a filesystem backup, either in the background or foreground (and show
4 # the results)
5
6 require './fsdump-lib.pl';
7 &ReadParse();
8 $dump = &get_dump($in{'id'});
9 $dump->{'id'} || &error($text{'backup_egone'});
10 &can_edit_dir($dump) || &error($text{'backup_ecannot'});
11
12 if ($config{'run_mode'}) {
13         # Background
14         &ui_print_header(undef, $text{'backup_title'}, "");
15
16         print "<p>$text{'backup_bg'}<p>\n";
17         &clean_environment();
18         &system_logged("$cron_cmd ".quotemeta($dump->{'id'}).
19                " >/dev/null 2>&1 </dev/null &");
20         &reset_environment();
21         &webmin_log("bgbackup", undef, undef, $dump);
22         }
23 else {
24         # Foreground
25         &ui_print_unbuffered_header(undef, $text{'backup_title'}, "");
26
27         # Setup command to be called upon tape change (which is not
28         # supported in this mode)
29         $nfile = "$module_config_directory/$dump->{'id'}.notape";
30         unlink($nfile);
31         &create_wrappers();
32
33         print "<b>",&text('backup_desc',
34                              "<tt>".&html_escape($dump->{'dir'})."</tt>",
35                              &dump_dest($dump)),"</b><p>\n";
36         print "<pre>";
37         $bok = &execute_before($dump, STDOUT, 1);
38         if (!$bok && !$dump->{'beforefok'}) {
39                 # Before command failed
40                 print "</pre>\n";
41                 print "<b>$text{'backup_beforefailed'}</b><p>\n";
42                 }
43         else {
44                 # Do the dump
45                 $now = time();
46                 $ok = &execute_dump($dump, STDOUT, 1, 0, $now);
47                 print "</pre>\n";
48                 if (!$bok) {
49                         print "<b>$text{'backup_afterfailed'}</b><p>\n";
50                         }
51                 elsif ($ok) {
52                         # Worked .. but verify if asked
53                         if ($dump->{'reverify'}) {
54                                 print "<b>$text{'backup_reverify'}</b><p>\n";
55                                 print "<pre>";
56                                 $ok = &verify_dump($dump, STDOUT, 1, 0, $now);
57                                 print "</pre>";
58                                 }
59                         if ($ok) {
60                                 print "<b>$text{'backup_done'}</b><br>\n";
61                                 }
62                         else {
63                                 print "<b>$text{'backup_noverify'}</b><br>\n";
64                                 }
65                         }
66                 else {
67                         if (-r $nfile) {
68                                 print "<b>$text{'backup_notape'}</b><br>\n";
69                                 }
70                         else {
71                                 print "<b>$text{'backup_failed'}</b><br>\n";
72                                 }
73                         }
74
75                 # Execute the post-backup command, if any
76                 if ($ok) {
77                         print "<pre>";
78                         $bok = &execute_after($dump, STDOUT, 1);
79                         print "</pre>\n";
80                         }
81                 }
82         unlink($nfile);
83         delete($dump->{'pass'});
84         &webmin_log("backup", undef, undef, $dump);
85         }
86
87 &ui_print_footer($access{'edit'} ? ( "edit_dump.cgi?id=$in{'id'}",
88                              $text{'edit_return'} ) : ( ),
89         "", $text{'index_return'});
90