Private
Server IP : 195.201.23.43  /  Your IP : 18.191.154.119
Web Server : Apache
System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64
User : kdecoratie ( 1041)
PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/webmin/bacula-backup/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/share/webmin/bacula-backup/restore.cgi
#!/usr/bin/perl
# Actually execute the restore

require './bacula-backup-lib.pl';
&ReadParse();
&error_setup($text{'restore_err'});
$dbh = &connect_to_database();

# Validate inputs
@files = split(/\r?\n/, $in{'files'});
@files || &error($text{'restore_efiles'});
$in{'where'} =~ s/\\/\//g;
$in{'where_def'} || $in{'where'} =~ /^([a-zA-Z]:)?\// ||
	&error($text{'restore_ewhere'});
$in{'client'} || &error($text{'restore_eclient'});
if ($in{'job'} =~ /^nj_(.*)_(\d+)_(\d+)$/) {
	# Node group job restore ..
	$in{'client'} eq "*" || &error($text{'restore_eall1'});
	$name = $1;
	$time = $2;
	}
else {
	# Single job restore
	$in{'client'} eq "*" && &error($text{'restore_eall2'});

	# Get the job name
	$cmd = $dbh->prepare("select Name from Job where JobId = ?");
	$cmd->execute($in{'job'});
	($name) = $cmd->fetchrow();
	$cmd->finish();
	}

# Work out clients to restore to
if ($in{'client'} eq "*") {
	# Clients that were originally backed up
	$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");
	$cmd->execute();
	while(my ($jid, $jname, $jwhen, $jclient) = $cmd->fetchrow()) {
		($j, $c) = &is_oc_object($jname);
		$stime = &date_to_unix($jwhen);
		if ($j && $c && $j eq $name) {
			if (abs($stime - $time) < 30) {
				# Found a member of the group
				push(@clients, [ $jclient, $jid ]);
				}
			}
		}
	$cmd->finish();
	@clients || &error($text{'restore_eclients'});
	&ui_print_unbuffered_header(undef,  $text{'restore_title3'}, "", "restore");
	}
elsif ($g = &is_oc_object($in{'client'})) {
	# All clients in a node group
	($group) = grep { $_->{'name'} eq $g } &list_node_groups();
	$group || &error($text{'restore_egroup'});
	@clients = map { [ "occlient_${g}_".$_, $in{'job'} ] } @{$group->{'members'}};
	&ui_print_unbuffered_header(undef,  $text{'restore_title2'}, "", "restore");
	}
else {
	# Just one
	&ui_print_unbuffered_header(undef,  $text{'restore_title'}, "", "restore");
	@clients = ( [ $in{'client'}, $in{'job'} ] );
	}

$dbh->disconnect();

foreach $clientjob (@clients) {
	$client = $clientjob->[0];
	$job = $clientjob->[1];
	($g, $c) = &is_oc_object($name);
	($gc, $cc) = &is_oc_object($client);
	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";
	print "<pre>";
	$h = &open_console();

	# Clear messages
	&console_cmd($h, "messages");

	# Start the restore process
	&sysprint($h->{'infh'}, "restore client=$client jobid=$job storage=$in{'storage'}".($in{'where_def'} ? "" : " where=\"$in{'where'}\"")."\n");
	&wait_for($h->{'outfh'}, 'restore.*\n');
	print $wait_for_input;
	$rv = &wait_for($h->{'outfh'}, 'Enter\s+"done".*\n',
				       'Unable to get Job record',
				       'all the files');
	print $wait_for_input;
	if ($rv == 1) {
		&job_error($text{'restore_ejob'});
		}
	elsif ($rv == 2) {
		&job_error($text{'restore_ejobfiles'});
		}

	# Select the files
	&wait_for($h->{'outfh'}, "\\\$");	# Wait for first prompt
	print $wait_for_input;
	foreach $f (@files) {
		$f = &unix_to_dos($f);
		if ($f eq "/") {
			&sysprint($h->{'infh'}, "cd /\n");
			&wait_for($h->{'outfh'}, "\\\$");
			print $wait_for_input;

			&sysprint($h->{'infh'}, "mark *\n");
			&wait_for($h->{'outfh'}, "\\\$");
			print $wait_for_input;
			}
		elsif ($f =~ /^(.*)\/([^\/]+)\/?$/) {
			local ($fd, $ff) = ($1, $2);
			$fd ||= "/";
			&sysprint($h->{'infh'}, "cd \"$fd\"\n");
			&wait_for($h->{'outfh'}, "\\\$");
			print $wait_for_input;

			&sysprint($h->{'infh'}, "mark \"$ff\"\n");
			&wait_for($h->{'outfh'}, "\\\$");
			print $wait_for_input;
			}
		}
	&sysprint($h->{'infh'}, "done\n");
	$rv = &wait_for($h->{'outfh'}, 'OK to run.*:', 'no files selected',
				       'Select Restore Job.*:');
	print $wait_for_input;
	if ($rv == 0) {
		&sysprint($h->{'infh'}, "yes\n");
		}
	elsif ($rv == 1) {
		&job_error($text{'restore_enofiles'});
		}
	elsif ($rv == 2) {
		&sysprint($h->{'infh'}, "1\n");
		&wait_for($h->{'outfh'}, 'OK to run.*:');
		&sysprint($h->{'infh'}, "yes\n");
		}
	else {
		&job_error($text{'backup_eok'});
		}
	print "</pre>\n";

	if ($in{'wait'}) {
		# Wait till we have a status
		print "</pre>\n";
		print "<b>",$text{'restore_running'},"</b>\n";
		print "<pre>";
		while(1) {
			$out = &console_cmd($h, "messages");
			if ($out !~ /You\s+have\s+no\s+messages/i) {
				print $out;
				}
			if ($out =~ /Termination:\s+(.*)/) {
				$status = $1;
				last;
				}
			sleep(1);
			}
		print "</pre>\n";
		if ($status =~ /Restore\s+OK/i && $status !~ /warning/i) {
			print "<b>",$text{'restore_done'},"</b><p>\n";
			}
		else {
			print "<b>",$text{'restore_failed'},"</b><p>\n";
			}
		}
	else {
		# Let it fly
		print "<b>",$text{'restore_running2'},"</b><p>\n";
		}

	&close_console($h);
	}

&webmin_log("restore", $in{'job'});

&ui_print_footer("restore_form.cgi", $text{'restore_return'});

sub job_error
{
&close_console($h);
print "</pre>\n";
print "<b>",@_,"</b><p>\n";
&ui_print_footer("backup_form.cgi", $text{'backup_return'});
exit;
}

Private