2 # Actually execute the restore
4 require './bacula-backup-lib.pl';
6 &error_setup($text{'restore_err'});
7 $dbh = &connect_to_database();
10 @files = split(/\r?\n/, $in{'files'});
11 @files || &error($text{'restore_efiles'});
12 $in{'where'} =~ s/\\/\//g;
13 $in{'where_def'} || $in{'where'} =~ /^([a-z]:)?\// ||
14 &error($text{'restore_ewhere'});
15 $in{'client'} || &error($text{'restore_eclient'});
16 if ($in{'job'} =~ /^nj_(.*)_(\d+)_(\d+)$/) {
17 # Node group job restore ..
18 $in{'client'} eq "*" || &error($text{'restore_eall1'});
24 $in{'client'} eq "*" && &error($text{'restore_eall2'});
27 $cmd = $dbh->prepare("select Name from Job where JobId = ?");
28 $cmd->execute($in{'job'});
29 ($name) = $cmd->fetchrow();
33 # Work out clients to restore to
34 if ($in{'client'} eq "*") {
35 # Clients that were originally backed up
36 $cmd = $dbh->prepare("select Job.JobId,Job.Name,Job.SchedTime,Client.Name from Job,Client where Job.Name not like 'Restore%' and Job.ClientId = Client.ClientId order by SchedTime desc");
38 while(my ($jid, $jname, $jwhen, $jclient) = $cmd->fetchrow()) {
39 ($j, $c) = &is_oc_object($jname);
40 $stime = &date_to_unix($jwhen);
41 if ($j && $c && $j eq $name) {
42 if (abs($stime - $time) < 30) {
43 # Found a member of the group
44 push(@clients, [ $jclient, $jid ]);
49 @clients || &error($text{'restore_eclients'});
50 &ui_print_unbuffered_header(undef, $text{'restore_title3'}, "", "restore");
52 elsif ($g = &is_oc_object($in{'client'})) {
53 # All clients in a node group
54 ($group) = grep { $_->{'name'} eq $g } &list_node_groups();
55 $group || &error($text{'restore_egroup'});
56 @clients = map { [ "occlient_${g}_".$_, $in{'job'} ] } @{$group->{'members'}};
57 &ui_print_unbuffered_header(undef, $text{'restore_title2'}, "", "restore");
61 &ui_print_unbuffered_header(undef, $text{'restore_title'}, "", "restore");
62 @clients = ( [ $in{'client'}, $in{'job'} ] );
65 foreach $clientjob (@clients) {
66 $client = $clientjob->[0];
67 $job = $clientjob->[1];
68 ($g, $c) = &is_oc_object($name);
69 ($gc, $cc) = &is_oc_object($client);
70 print "<b>",&text('restore_run', $c ? "<tt>$c</tt>" : "<tt>$name</tt>", $cc ? "<tt>$cc</tt>" : "<tt>$client</tt>", "<tt>$in{'storage'}</tt>"),"</b>\n";
75 &console_cmd($h, "messages");
77 # Start the restore process
78 &sysprint($h->{'infh'}, "restore client=$client jobid=$job storage=$in{'storage'}".($in{'where_def'} ? "" : " where=\"$in{'where'}\"")."\n");
79 &wait_for($h->{'outfh'}, 'restore.*\n');
80 print $wait_for_input;
81 $rv = &wait_for($h->{'outfh'}, 'Enter\s+"done".*\n',
82 'Unable to get Job record',
84 print $wait_for_input;
86 &job_error($text{'restore_ejob'});
89 &job_error($text{'restore_ejobfiles'});
94 $f = &unix_to_dos($f);
96 &sysprint($h->{'infh'}, "cd /\n");
97 &wait_for($h->{'outfh'}, "\\\$");
98 print $wait_for_input;
100 &sysprint($h->{'infh'}, "mark *\n");
101 &wait_for($h->{'outfh'}, "\\\$");
102 print $wait_for_input;
104 elsif ($f =~ /^(.*)\/([^\/]+)\/?$/) {
105 local ($fd, $ff) = ($1, $2);
107 &sysprint($h->{'infh'}, "cd \"$fd\"\n");
108 &wait_for($h->{'outfh'}, "\\\$");
109 print $wait_for_input;
111 &sysprint($h->{'infh'}, "mark \"$ff\"\n");
112 &wait_for($h->{'outfh'}, "\\\$");
113 print $wait_for_input;
116 &sysprint($h->{'infh'}, "done\n");
117 $rv = &wait_for($h->{'outfh'}, 'OK to run.*:', 'no files selected');
118 print $wait_for_input;
120 &sysprint($h->{'infh'}, "yes\n");
123 &job_error($text{'restore_enofiles'});
126 &job_error($text{'backup_eok'});
131 # Wait till we have a status
133 print "<b>",$text{'restore_running'},"</b>\n";
136 $out = &console_cmd($h, "messages");
137 if ($out !~ /You\s+have\s+no\s+messages/i) {
140 if ($out =~ /Termination:\s+(.*)/) {
147 if ($status =~ /Restore\s+OK/i && $status !~ /warning/i) {
148 print "<b>",$text{'restore_done'},"</b><p>\n";
151 print "<b>",$text{'restore_failed'},"</b><p>\n";
156 print "<b>",$text{'restore_running2'},"</b><p>\n";
162 &webmin_log("restore", $in{'job'});
164 &ui_print_footer("restore_form.cgi", $text{'restore_return'});
170 print "<b>",@_,"</b><p>\n";
171 &ui_print_footer("backup_form.cgi", $text{'backup_return'});