2 # Show a form for restoring an old backup job
4 require './bacula-backup-lib.pl';
5 &ui_print_header(undef, $text{'restore_title'}, "", "restore");
7 $conf = &get_director_config();
8 @jobs = &find("Job", $conf);
9 $backup = &find_by("Type", "Restore", \@jobs);
11 print &ui_form_start("restore.cgi", "post");
12 print &ui_table_start($text{'restore_header'}, undef, 2);
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);
19 while(my ($id, $name, $when, $level) = $cmd->fetchrow()) {
20 $level = $text{'restore_level_'.$level} || $level;
21 ($j, $c) = &is_oc_object($name);
24 push(@opts, [ $id, "$id - $name ($when) - $level" ]);
28 push(@opts, [ $id, "$id - $j on $c ($when) - $level" ]);
30 # Save the job ID to a list of those for this particular node
32 $stime = &date_to_unix($when);
34 foreach $nj (@nodejobs) {
35 $diff = abs($stime - $nj->{'stime'});
36 if ($nj->{'job'} eq $j && $diff < 30) {
37 push(@{$nj->{'clients'}}, [ $id, $c ]);
43 push(@nodejobs, { 'job' => $j,
46 'clients' => [ [ $id, $c ] ]});
50 # Add entries for entire node group restores
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'}" ]);
61 print &ui_table_row($text{'restore_job'},
62 &ui_select("job", undef, \@opts));
65 print &ui_table_row($text{'restore_files'},
66 &ui_textarea("files", undef, 8, 50)."\n".
67 &bacula_file_button("files", "job"));
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'}) ] }
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();
85 push(@opts, [ undef, $text{'restore_clist'} ]) if (@groups);
88 &text('clientstatus_on', $_->{'name'}, $_->{'address'}) ] }
92 push(@opts, [ undef, $text{'restore_glist'} ]) if (@clients);
94 map { ($g, $c) = &is_oc_object($_);
95 $c ? ( ) : ( [ $_->{'name'}, $g ] ) } @groups);
98 push(@opts, [ "*", $text{'restore_all'} ]);
100 print &ui_table_row($text{'restore_client'},
101 &ui_select("client", undef, \@opts));
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'}));
110 # Wait for completion?
111 print &ui_table_row($text{'backup_wait'},
112 &ui_yesno_radio("wait", $config{'wait'}));
114 print &ui_table_end();
115 print &ui_form_end([ [ "restore", $text{'restore_ok'} ] ]);
117 &ui_print_footer("", $text{'index_return'});