Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / restore_form.cgi
1 #!/usr/local/bin/perl
2 # Show a form for restoring an old backup job
3
4 require './bacula-backup-lib.pl';
5 &ui_print_header(undef,  $text{'restore_title'}, "", "restore");
6
7 $conf = &get_director_config();
8 @jobs = &find("Job", $conf);
9 $backup = &find_by("Type", "Restore", \@jobs);
10
11 print &ui_form_start("restore.cgi", "post");
12 print &ui_table_start($text{'restore_header'}, undef, 2);
13
14 # Old job to restore
15 $dbh = &connect_to_database();
16 $cmd = $dbh->prepare("select JobId,Name,SchedTime,Level from Job where Name not like 'Restore%' order by SchedTime desc") ||
17                 &error("prepare failed : ",$dbh->errstr);
18 $cmd->execute();
19 while(my ($id, $name, $when, $level) = $cmd->fetchrow()) {
20         $level = $text{'restore_level_'.$level} || $level;
21         ($j, $c) = &is_oc_object($name);
22         if (!$j) {
23                 # Normal backup
24                 push(@opts, [ $id, "$id - $name ($when) - $level" ]);
25                 }
26         elsif ($j && $c) {
27                 # Backup of one node
28                 push(@opts, [ $id, "$id - $j on $c ($when) - $level" ]);
29
30                 # Save the job ID to a list of those for this particular node
31                 # group backup
32                 $stime = &date_to_unix($when);
33                 $found = 0;
34                 foreach $nj (@nodejobs) {
35                         $diff = abs($stime - $nj->{'stime'});
36                         if ($nj->{'job'} eq $j && $diff < 30) {
37                                 push(@{$nj->{'clients'}}, [ $id, $c ]);
38                                 $found = 1;
39                                 last;
40                                 }
41                         }
42                 if (!$found) {
43                         push(@nodejobs, { 'job' => $j,
44                                           'stime' => $stime,
45                                           'when' => $when,
46                                           'clients' => [ [ $id, $c ] ]});
47                         }
48                 }
49         }
50 # Add entries for entire node group restores
51 if (@nodejobs) {
52         @opts = ( [ undef, $text{'restore_jlist'} ], @opts,
53                   [ undef, $text{'restore_njlist'} ] );
54         foreach $nj (@nodejobs) {
55                 push(@opts, [ "nj_".$nj->{'job'}."_".$nj->{'stime'}."_".
56                                 $nj->{'clients'}->[0]->[0],
57                               "$nj->{'job'} ($nj->{'when'}" ]);
58                 }
59         }
60 $cmd->finish();
61 print &ui_table_row($text{'restore_job'},
62                     &ui_select("job", undef, \@opts));
63
64 # Files to restore
65 print &ui_table_row($text{'restore_files'},
66                     &ui_textarea("files", undef, 8, 50)."\n".
67                     &bacula_file_button("files", "job"));
68
69 # Storage device
70 @storages = sort { lc($a->{'name'}) cmp lc($b->{'name'}) }
71                  &get_bacula_storages();
72 print &ui_table_row($text{'restore_storage'},
73         &ui_select("storage", undef,
74          [ map { [ $_->{'name'},
75                    &text('storagestatus_on', $_->{'name'}, $_->{'address'}) ] }
76            @storages ]));
77
78 # Destination client or group
79 @clients = sort { lc($a->{'name'}) cmp lc($b->{'name'}) }
80                 grep { !&is_oc_object($_, 1) } &get_bacula_clients();
81 @groups = sort { lc($a->{'name'}) cmp lc($b->{'name'}) }
82                 grep { &is_oc_object($_, 1) } &get_bacula_clients();
83 @opts = ( );
84 if (@clients) {
85         push(@opts, [ undef, $text{'restore_clist'} ]) if (@groups);
86         push(@opts,
87            map { [ $_->{'name'},
88                    &text('clientstatus_on', $_->{'name'}, $_->{'address'}) ] }
89            @clients);
90         }
91 if (@groups) {
92         push(@opts, [ undef, $text{'restore_glist'} ]) if (@clients);
93         push(@opts,
94            map { ($g, $c) = &is_oc_object($_);
95                  $c ? ( ) : ( [ $_->{'name'}, $g ] ) } @groups);
96         }
97 if (@nodejobs) {
98         push(@opts, [ "*", $text{'restore_all'} ]);
99         }
100 print &ui_table_row($text{'restore_client'},
101                     &ui_select("client", undef, \@opts));
102
103 # Destination directory
104 $where = &find_value("Where", $backup->{'members'});
105 print &ui_table_row($text{'restore_where'},
106                     &ui_opt_textbox("where", undef, 40,
107                                     $text{'default'}." (<tt>$where</tt>)<br>",
108                                     $text{'restore_where2'}));
109
110 # Wait for completion?
111 print &ui_table_row($text{'backup_wait'},
112                     &ui_yesno_radio("wait", $config{'wait'}));
113
114 print &ui_table_end();
115 print &ui_form_end([ [ "restore", $text{'restore_ok'} ] ]);
116
117 &ui_print_footer("", $text{'index_return'});
118