5 Bweb - A Bacula web interface
6 Bacula® - The Network Backup Solution
8 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10 The main author of Bweb is Eric Bollengier.
11 The main author of Bacula is Kern Sibbald, with contributions from
12 many others, a complete list can be found in the file AUTHORS.
14 This program is Free Software; you can redistribute it and/or
15 modify it under the terms of version two of the GNU General Public
16 License as published by the Free Software Foundation plus additions
17 that are listed in the file LICENSE.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 Bacula® is a registered trademark of John Walker.
30 The licensor of Bacula is the Free Software Foundation Europe
31 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
32 Switzerland, email:ftf@fsfeurope.org.
41 ################################################################
42 # Manage with Expect the bconsole tool
47 # my $pref = new Pref(config_file => 'brestore.conf');
48 # my $bconsole = new Bconsole(pref => $pref);
51 my ($class, %arg) = @_;
54 pref => $arg{pref}, # Pref object
55 bconsole => undef, # Expect object
56 log_stdout => $arg{log_stdout} || 0,
57 timeout => $arg{timeout} || 20,
58 debug => $arg{debug} || 0,
66 my ($self, %arg) = @_;
77 for my $key (keys %arg) {
79 $arg{$key} =~ tr/""/ /;
80 $cmd .= "$key=\"$arg{$key}\" ";
84 unless ($self->connect()) {
88 print STDERR "===> $cmd $go\n";
89 $self->{bconsole}->clear_accum();
90 $self->send("$cmd $go\n");
91 $self->expect_it('-re','^[*]');
92 my $ret = $self->before();
93 if ($ret =~ /jobid=(\d+)/is) {
100 # for brestore.pl::BwebConsole
108 my ($self, $what) = @_;
109 $self->{bconsole}->send($what);
114 my ($self, @what) = @_;
115 unless ($self->{bconsole}->expect($self->{timeout}, @what)) {
116 return $self->error($self->{bconsole}->error());
123 my ($self, $how) = @_;
125 if ($self->{bconsole}) {
126 $self->{bconsole}->log_stdout($how);
129 $self->{log_stdout} = $how;
134 my ($self, $error) = @_;
135 $self->{error} = $error;
137 print STDERR "E: bconsole (", $self->{pref}->{bconsole}, ") $! $error\n";
146 if ($self->{error}) {
150 unless ($self->{bconsole}) {
151 my @cmd = split(/\s+/, $self->{pref}->{bconsole}) ;
153 return $self->error("bconsole string not found");
155 $self->{bconsole} = new Expect;
156 $self->{bconsole}->raw_pty(1);
157 $self->{bconsole}->debug($self->{debug});
158 $self->{bconsole}->log_stdout($self->{debug} || $self->{log_stdout});
160 # WARNING : die is trapped by gtk_main_loop()
161 # and exit() closes DBI connection
164 my $sav = $SIG{__DIE__};
165 $SIG{__DIE__} = sub { _exit 1 ;};
166 my $old = $ENV{COLUMNS};
168 $ret = $self->{bconsole}->spawn(@cmd) ;
169 delete $ENV{COLUMNS};
170 $ENV{COLUMNS} = $old if ($old) ;
171 $SIG{__DIE__} = $sav;
175 return $self->error($self->{bconsole}->error());
178 # TODO : we must verify that expect return the good value
180 $self->expect_it('*');
181 $self->send_cmd('gui on');
188 my ($self, $jobid) = @_;
189 return $self->send_cmd("cancel jobid=$jobid");
192 # get text between to expect
196 return $self->{bconsole}->before();
201 my ($self, $cmd) = @_;
202 unless ($self->connect()) {
205 $self->{bconsole}->clear_accum();
206 $self->send("$cmd\n");
207 $self->expect_it('-re','^[*]');
208 return $self->before();
213 my ($self, $cmd) = @_;
214 unless ($self->connect()) {
217 $self->send("$cmd\n");
218 $self->expect_it('-re', '[?].+:');
220 $self->send_cmd("yes");
221 return $self->before();
226 my ($self, %arg) = @_;
228 unless ($arg{storage}) {
232 unless ($self->connect()) {
236 $arg{drive} = $arg{drive} || '0' ;
237 $arg{pool} = $arg{pool} || 'Scratch';
239 my $cmd = "label barcodes drive=$arg{drive} pool=\"$arg{pool}\" storage=\"$arg{storage}\"";
242 $cmd .= " slots=$arg{slots}";
245 $self->send("$cmd\n");
246 $self->expect_it('-re', '[?].+\).*:');
247 my $res = $self->before();
248 $self->send("yes\n");
249 # $self->expect_it("yes");
250 # $res .= $self->before();
251 $self->expect_it('-re','^[*]');
252 $res .= $self->before();
257 # return [ { name => 'test1', vol => '00001', ... },
258 # { name => 'test2', vol => '00002', ... }... ]
260 sub director_get_sched
262 my ($self, $days) = @_ ;
266 unless ($self->connect()) {
270 my $status = $self->send_cmd("st director days=$days") ;
273 foreach my $l (split(/\r?\n/, $status)) {
274 #Level Type Pri Scheduled Name Volume
275 #Incremental Backup 11 03-ao-06 23:05 TEST_DATA 000001
276 if ($l =~ /^(I|F|Di)\w+\s+\w+\s+\d+/i) {
277 my ($level, $type, $pri, $d, $h, @name_vol) = split(/\s+/, $l);
279 my $vol = pop @name_vol; # last element
280 my $name = join(" ", @name_vol); # can contains space
298 my ($self, $storage, $drive) = @_;
299 $drive = $drive || 0;
301 return $self->send_cmd("update slots storage=$storage drive=$drive");
308 # 'file' => '</tmp/regress/tmp/file-list'
311 # 'file' => '</tmp/regress/tmp/other-file-list'
316 # 'file' => '</tmp/regress/tmp/efile-list'
319 # 'file' => '</tmp/regress/tmp/other-efile-list'
325 my ($self, $fs) = @_;
327 my $out = $self->send_cmd("show fileset=\"$fs\"");
331 foreach my $l (split(/\r?\n/, $out)) {
333 if ($l =~ /^\s+([I|E])\s+(.+)$/) { # include
334 push @{$ret->{$1}}, { file => $2 };
344 return sort split(/\r?\n/, $self->send_cmd(".jobs"));
350 return sort split(/\r?\n/, $self->send_cmd(".filesets"));
356 return sort split(/\r?\n/, $self->send_cmd(".storage"));
362 return sort split(/\r?\n/, $self->send_cmd(".clients"));
368 return sort split(/\r?\n/, $self->send_cmd(".pools"));
371 use Time::ParseDate qw/parsedate/;
372 use POSIX qw/strftime/;
377 my ($self, @volume) = @_;
378 return '' unless (@volume);
381 foreach my $vol (@volume) {
382 if ($vol =~ /^([\w\d\.-]+)$/) {
383 $sel .= " volume=$1";
386 $self->error("Sorry media is bad");
396 my ($self, $volume) = @_;
398 my $sel = $self->_get_volume($volume);
401 $ret = $self->send_cmd("purge $sel");
403 $ret = $self->{error};
410 my ($self, $volume) = @_;
412 my $sel = $self->_get_volume($volume);
415 $ret = $self->send_cmd("prune $sel yes");
417 $ret = $self->{error};
424 my ($self, @jobid) = @_;
426 return 0 unless (@jobid);
429 foreach my $job (@jobid) {
430 if ($job =~ /^(\d+)$/) {
434 return $self->error("Sorry jobid is bad");
438 $self->send_cmd("purge $sel");
444 $self->send("quit\n");
445 $self->{bconsole}->soft_close();
446 $self->{bconsole} = undef;
454 # grep -v __END__ Bconsole.pm | perl
458 use Data::Dumper qw/Dumper/;
459 print "test sans conio\n";
461 my $c = new Bconsole(pref => {
462 bconsole => '/tmp/regress/bin/bconsole -n -c /tmp/regress/bin/bconsole.conf',
466 print "fileset : ", join(',', $c->list_fileset()), "\n";
467 print "job : ", join(',', $c->list_job()), "\n";
468 print "storage : ", join(',', $c->list_storage()), "\n";
469 my $r = $c->get_fileset($c->list_fileset());
471 print "FS Include:\n", join (",", map { $_->{file} } @{$r->{I}}), "\n";
472 print "FS Exclude:\n", join (",", map { $_->{file} } @{$r->{E}}), "\n";
473 #print $c->label_barcodes(pool => 'Scratch', drive => 0, storage => 'LTO3', slots => '45');
474 #print "prune : " . $c->prune_volume('000001'), "\n";
475 #print "update : " . $c->send_cmd('update slots storage=SDLT-1-2, drive=0'), "\n";
476 #print "label : ", join(',', $c->label_barcodes(storage => 'SDLT-1-2',
478 # drive => 0)), "\n";