1) install Perl lib
2) copy your files
3) initialize your configuration file
-4) do some sql stuff (for postgresql users)
+4) do some sql stuff (for postgresql or mysql 5 users)
5) use the -n option on bconsole so that it works with Expect
6) get bacula log more useful
7) bweb limitation
text/brestore with your brestore.pl, and you must install brestore.
See gui/brestore/README for instructions on installing brestore.pl.
-################ POSTGRESQL NOTES ##############################
+################ POSTGRESQL AND MYSQL5 NOTES ####################
If you want to use PostgreSQL instead of MySQL, you must add
a function to the PostgreSQL Bacula database to get Bweb to work.
psql -U bacula bacula < script/bweb-postgresql.sql
-Tips: PL must be enable in your cluster, you can do this with postgres user
+Tips: PL must be enabled in your cluster, you can do this with postgres user
postgres:~$ echo 'CREATE PROCEDURAL LANGUAGE plpgsql;' | psql bacula
+
+To get database size with mysql5, edit Bweb.pm and change the DB_SIZE macro
+
+ # with mysql < 5, you have to play with the ugly SHOW command
+ DB_SIZE => " SELECT 0 ",
+ # works only with mysql 5
+ # DB_SIZE => " SELECT sum(DATA_LENGTH) FROM INFORMATION_SCHEMA.TABLES ",
+
################ BCONSOLE NOTES ################################
You must use bconsole without conio/readline support. For that, use
--- /dev/null
+lib/Bweb.pm
+lib/Bconsole.pm
+lib/CCircle.pm
+Makefile.PL
+INSTALL
+COPYING
+MANIFEST
--- /dev/null
+use Test::More tests => 7;
+
+require_ok('DBI');
+require_ok('GD::Graph');
+require_ok('GD');
+require_ok('HTML::Template');
+require_ok('CGI');
+require_ok('Expect');
+require_ok('Time::ParseDate');
+
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ ABSTRACT => "An other Bacula WEB interface",
+ AUTHOR => "Eric Bollengier <eric@eb.homelinux.org>",
+ NAME => 'Bweb',
+ VERSION => "lib/Bweb.pm",
+
+ #INST_BIN => "cgi",
+ # setup your cgi installation
+ # debian : /usr/lib/cgi-bin/bweb
+ # redhat/suse : /var/www/cgi-bin/bweb
+ #
+ #INSTALLSITEBIN => "/usr/lib/cgi-bin/bweb",
+);
Release Notes for bweb 2.0
+2007/03/02
+ - Add Postgresql and Mysql5 database size information (See INSTALL for mysql)
+
2007/03/01
- Add display_time_log option to get timestamp in display_log
- Add Warning filter on display_job (see jobstatus=T and joberrors > 0)
--- /dev/null
+#!/bin/sh
+#
+# Change the following four environment variables to suit your system
+# Note, the configuration below works on a stock SuSE 10.2 system
+#
+# You can, in general, execute this file multiple times. However, if
+# you edit certain of the installed files, your changes might be lost.
+# This script will not overwrite any installed /etc/bacula/bweb.conf
+#
+# Configuration directory for bweb
+CONF_DIR=/etc/bacula
+#
+# Root directory of web files
+#
+WEB_DIR=/srv/www/htdocs
+#
+# share directory for programs
+#
+SHARE_DIR=/usr/share
+#
+# cgi_bin location for web server
+#
+CGI_BIN=/srv/www/cgi-bin
+#
+# Userid the web server is running under
+#
+HTTP_USER=wwwrun
+HTTP_GROUP=www
+
+# Bacula database name and password
+DB=bacula
+DB_PW=""
+EMAIL_ADDR="xxx@localhost"
+MTX="/sbin/mtx"
+
+if [ `whoami` != "root" ] ; then
+ echo "You must be root to run this script."
+ exit 1
+fi
+
+#
+# Normally you should not need to change the following
+#
+# first, copy the bweb perl library into your PERL5 INC path
+sed -i "s!/etc/bacula!${CONF_DIR}!" lib/Bweb.conf
+perl Makefile.PL
+make install
+
+# copy the bweb perl program to your cgi location
+if [ ! -d ${CGI_BIN}/bweb ] ; then
+ mkdir -m 755 ${CGI_BIN}/bweb
+fi
+install -m 755 -o root -g root cgi/*.pl ${CGI_BIN}/bweb
+
+# get a config file
+if [ ! -d ${CONF_DIR} ] ; then
+ mkdir -m 755 ${CONF_DIR}
+ chown root:bacula ${CONF_DIR}
+fi
+
+# Setup a default ${CONF_DIR}/bweb.conf
+if [ ! -e ${CONF_DIR}/bweb.conf ] ; then
+cat > ${CONF_DIR}/bweb.conf <<END_OF_DATA
+\$VAR1 = bless( {
+ 'graph_font' => '/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf',
+ 'name' => undef,
+ 'config_file' => '${CONF_DIR}/bweb.conf',
+ 'bconsole' => '/usr/sbin/bconsole -n -c /etc/bacula/bconsole.conf',
+ 'ach_list' => {
+ 'S1_L80' => bless( {
+ 'info' => {
+ 'drive' => 0,
+ 'io' => 0,
+ 'slot' => 0
+ },
+ 'name' => 'S1_L80',
+ 'bweb' => undef,
+ 'device' => '/dev/changer',
+ 'drive' => [],
+ 'debug' => 0,
+ 'label' => {},
+ 'precmd' => 'sudo',
+ 'io' => [],
+ 'mtxcmd' => '${MTX}',
+ 'drive_name' => [
+ 'S1_L80_SDLT0',
+ 'S1_L80_SDLT1'
+ ],
+ 'slot' => []
+ }, 'Bweb::Autochanger' )
+ },
+ 'password' => '${DB_PW}',
+ 'template_dir' => '${SHARE_DIR}/bweb/tpl',
+ 'dbi' => 'DBI:mysql:database=bacula',
+ 'error' => '',
+ 'debug' => 0,
+ 'user' => '${DB}',
+ 'email_media' => '${EMAIL_ADDR}'
+}, 'Bweb::Config' );
+END_OF_DATA
+fi
+
+chown ${HTTP_USER} ${CONF_DIR}/bweb.conf
+
+# copy the bweb template file
+if [ ! -d ${SHARE_DIR}/bweb/tpl ] ; then
+ mkdir -p ${SHARE_DIR}/bweb/tpl
+fi
+install -m 644 -o root -g root tpl/*.tpl ${SHARE_DIR}/bweb/tpl
+
+# copy the bweb graphics elements (bweb elements must reside in /bweb)
+if [ ! -d ${WEB_DIR} ] ; then
+ mkdir ${WEB_DIR}/bweb
+fi
+install -m 644 -o root -g root html/*.{js,png,css,gif,ico,html} ${WEB_DIR}/bweb
+
+echo " "
+echo "Please edit /etc/bweb.conf and ensure that all the paths to"
+echo " the various programs and files such as bconsole, bconsole.conf"
+echo " are correct, and that the DBI driver is correct (default mysql)"
+echo " and has the right password for your DB"
+echo " "
+
+
+
+# done !
odd_cell_color: odd_cell_color,
header_color: header_color,
page_nav: true,
- rows_per_page: rows_per_page,
-// disable_sorting: new Array(1)
+// disable_sorting: new Array(1),
+ rows_per_page: rows_per_page
}
);
</script>
header_color: header_color,
page_nav: true,
padding: 3,
- rows_per_page: rows_per_page,
-// disable_sorting: new Array(5,6)
+// disable_sorting: new Array(5,6),
+ rows_per_page: rows_per_page
}
);
</script>
</div>
<div class='bodydiv'>
<a href='?action=job;age=172800;jobtype=B'>
-<img src='bgraph.pl?age=2678400;width=450;height=200;graph=job_sum_day;limit=500;action=graph;legend=off' alt='Rien a afficher'>
+<img width='450' height='200' src='bgraph.pl?age=2678400;width=450;height=200;graph=job_sum_day;limit=500;action=graph;legend=off' alt='Rien a afficher'>
</a>
</div>
$self->{log_stdout} = $how;
}
+sub error
+{
+ my ($self, $error) = @_;
+ $self->{error} = $!;
+ if ($self->{debug}) {
+ print "E: bconsole (", $self->{pref}->{bconsole}, ") $!\n";
+ }
+ return 0;
+}
+
sub connect
{
my ($self) = @_;
unless ($self->{bconsole}) {
my @cmd = split(/\s+/, $self->{pref}->{bconsole}) ;
unless (@cmd) {
- $self->{error} = "bconsole string not found";
- return 0;
+ return $self->error("bconsole string not found");
}
$self->{bconsole} = new Expect;
$self->{bconsole}->raw_pty(0);
{
my $sav = $SIG{__DIE__};
$SIG{__DIE__} = sub { _exit 1 ;};
+ my $old = $ENV{COLUMNS};
+ $ENV{COLUMNS} = 300;
$ret = $self->{bconsole}->spawn(@cmd) ;
+ delete $ENV{COLUMNS};
+ $ENV{COLUMNS} = $old if ($old) ;
$SIG{__DIE__} = $sav;
}
unless ($ret) {
- $self->{error} = $!;
- return 0;
+ return $self->error($ret);
}
# TODO : we must verify that expect return the good value
}
$self->send("$cmd\n");
- $self->expect_it('-re', '[?].+\)\s*:');
+ $self->expect_it('-re', '[?].+\).*:');
my $res = $self->before();
$self->send("yes\n");
$self->expect_it("yes");
$sel .= " volume=$1";
} else {
- $self->{error} = "Sorry media is bad";
+ $self->error("Sorry media is bad");
return '';
}
}
$sel .= " jobid=$1";
} else {
- $self->{error} = "Sorry jobid is bad";
- return 0;
+ return $self->error("Sorry jobid is bad");
}
}
STARTTIME_PHOUR=> " date_part('hour', Job.StartTime) ",
STARTTIME_PDAY => " date_part('day', Job.StartTime) ",
STARTTIME_PMONTH => " date_part('month', Job.StartTime) ",
+ DB_SIZE => " SELECT pg_database_size(current_database()) ",
},
mysql => {
UNIX_TIMESTAMP => 'UNIX_TIMESTAMP',
STARTTIME_PHOUR=> " DATE_FORMAT(StartTime, '%H') ",
STARTTIME_PDAY => " DATE_FORMAT(StartTime, '%d') ",
STARTTIME_PMONTH => " DATE_FORMAT(StartTime, '%m') ",
+ # with mysql < 5, you have to play with the ugly SHOW command
+ DB_SIZE => " SELECT 0 ",
+ # works only with mysql 5
+ # DB_SIZE => " SELECT sum(DATA_LENGTH) FROM INFORMATION_SCHEMA.TABLES ",
},
);
(SELECT count(Media.MediaId) FROM Media) AS nb_media,
(SELECT count(Job.JobId) FROM Job) AS nb_job,
(SELECT sum(VolBytes) FROM Media) AS nb_bytes,
+ ($self->{sql}->{DB_SIZE}) AS db_size,
(SELECT count(Job.JobId)
FROM Job
WHERE Job.JobStatus IN ('E','e','f','A')
$row->{nb_bytes} = human_size($row->{nb_bytes});
- $row->{db_size} = '???';
+ $row->{db_size} = human_size($row->{db_size});
$row->{label} = $label;
$self->display($row, "general.tpl");
+CREATE PROCEDURAL LANGUAGE plpgsql;
BEGIN;
CREATE FUNCTION SEC_TO_TIME(timestamp with time zone)
END;
$$ language 'plpgsql';
-COMMIT;
\ No newline at end of file
+COMMIT;
--- /dev/null
+-- First, create job_old table
+-- CREATE TABLE job_old (LIKE Job);
+--
+-- then put this on your crontab
+-- */20 * * * * psql -f /opt/bacula/etc/update_job_old.sql > /home/bacula/update_job_old.log
+INSERT INTO job_old
+ (SELECT * FROM Job WHERE JobId NOT IN (SELECT JobId FROM job_old) );
+