\section{bimagemgr}
\label{blb:bimagemgr}
\index[general]{Bimagemgr}

\btool{bimagemgr} is a utility for those who backup to disk volumes in order to
commit them to CDR disk, rather than tapes. It is a web based interface
written in Perl and is used to monitor when a volume file needs to be burned to
disk. It requires:

\begin{bitemize}
\item A web server running on the bacula server
\item A CD recorder installed and configured on the bacula server
\item The cdrtools package installed on the bacula server.
\item \btool{perl}, \texttt{perl-DBI} module, and either \texttt{DBD-MySQL} \texttt{DBD-SQLite} or \texttt{DBD-PostgreSQL} modules
\end{bitemize}

DVD burning is not supported by \btool{bimagemgr} at this
time, but both are planned for future releases.

\subsection{bimagemgr installation}
\index[general]{bimagemgr!Installation}
\index[general]{bimagemgr Installation}

Installation from tarball:
\begin{benumerate}
  % TODO: use itemized list for this?
  %% done by Philippe 22 dev 2016
\item Examine the \bfilename{Makefile} and adjust it to your configuration if needed.
\item Edit \bfilename{config.pm} to fit your configuration.
\item Do \btool{make install} as \texttt{root}.
\item Edit \bfilename{httpd.conf} and change the Timeout value. The web server must not time
out and close the connection before the burn process is finished. The exact
value needed may vary depending upon your \acs{CD} recorder speed and whether you are
burning on the \bacula{} server on on another machine across your network. In my
case I set it to 1000 seconds. Restart \btool{httpd}.
\item Make sure that cdrecord is \btool{setuid} \texttt{root}.
% TODO: I am pretty sure cdrecord can be used without setuid \texttt{root}
% TODO: as long as devices are setup correctly
\end{benumerate}

Installation from rpm package:
% TODO: use itemized list for this?
\begin{benumerate}
\item Install the rpm package for your platform.
\item Edit \bfilename{/cgi-bin/config.pm} to fit your configuration.
  \item Edit \bfilename{httpd.conf} and change the Timeout value. The web server must not time
out and close the connection before the burn process is finished. The exact
value needed may vary depending upon your cd recorder speed and whether you are
burning on the bacula server on on another machine across your network. In my
case I set it to 1000 seconds. Restart \btool{httpd}.
\item  Make sure that cdrecord is \btool{setuid} \texttt{root}.
\end{benumerate}
For \bacula{} systems less than 1.36:
\begin{benumerate}
% TODO: use itemized list for this?
\item Edit the configuration section of \bfilename{config.pm} to fit your configuration.
\item Run \bfilename{/etc/bacula/create\_cdimage\_table.pl} from a console on your \bacula{}
server (as \texttt{root}) to add the CDImage table to your bacula database.
\end{benumerate}
Accessing the Volume files:
The Volume files by default have permissions \bdefaultvalue{640} and can only be read by \texttt{root}.
The recommended approach to this is as follows (and only works if \btool{bimagemgr} and \btool{apache}
are running on the same host as \bacula{}.

For bacula-1.34 or 1.36 installed from tarball -
\begin{benumerate}
  % TODO: use itemized list for this?
\item Create a new user group \texttt{bacula} and add the user \texttt{apache} to the group for
Red Hat or Mandrake systems. For SuSE systems add the user \texttt{wwwrun} to the
\texttt{bacula} group.
\item Change ownership of all of your Volume files to \texttt{root}.\texttt{bacula}
\item Edit the \bfilename{/etc/bacula/bacula} startup script and set SD\_USER=root and
SD\_GROUP=bacula. Restart \btool{bacula}.
\end{benumerate}
Note: step 3 should also be done in \bfilename{/etc/init.d/bacula-sd} but released versions
of this file prior to 1.36 do not support it. In that case it would be necessary after
a reboot of the server to execute \btool{/etc/bacula/bacula restart}.

For bacula-1.38 installed from tarball -
\begin{benumerate}
  % TODO: use itemized list for this?
\item Your configure statement should include:
  % TODO: fix formatting here
  % Done. Philippe 22 dec 2016
  \begin{bVerbatim}
--with-dir-user=bacula
--with-dir-group=bacula
--with-sd-user=bacula
--with-sd-group=disk
--with-fd-user=root
--with-fd-group=bacula
\end{bVerbatim}
\item Add the user \texttt{apache} to the \texttt{bacula} group for Red Hat or Mandrake systems.
For SuSE systems add the user \texttt{wwwrun} to the \texttt{bacula} group.
\item Check/change ownership of all of your Volume files to \texttt{root}.\texttt{bacula}
\end{benumerate}

For bacula-1.36 or bacula-1.38 installed from rpm -
\begin{benumerate}
  % TODO: use itemized list for this?
\item  Add the user \texttt{apache} to the group \texttt{bacula} for Red Hat or Mandrake systems.
For SuSE systems add the user \texttt{wwwrun} to the \texttt{bacula} group.
\item Check/change ownership of all of your Volume files to \texttt{root}.\texttt{bacula}
\end{benumerate}

\btool{bimagemgr} installed from rpm \gt{} 1.38.9 will add the web server user to the
\texttt{bacula} group in a post install script. Be sure to edit the configuration
information in \bfilename{config.pm} after installation of rpm package.

\btool{bimagemgr} will now be able to read the Volume files but they are still not
world readable.

If you are running \btool{bimagemgr} on another host (not recommended) then you will
need to change the permissions on all of your backup volume files to 644 in
order to access them via \acs{NFS} share or other means. This approach should only
be taken if you are sure of the security of your environment as it exposes
the backup Volume files to world read.

\subsection{bimagemgr usage}
\index[general]{bimagemgr!Usage}
\index[general]{bimagemgr Usage}

% TODO: use tex to say figure number => done.
Calling the program in your web browser, e.g. \url{http://localhost/cgi-bin/bimagemgr.pl} will produce a display as shown below in Figure \vref{fig:util:bimagemgr1}. The program will query the bacula database and display all volume
files with the date last written and the date last burned to disk. If a volume
needs to be burned (last written is newer than last burn date) a ``Burn''
button will be displayed in the rightmost column.

\bimageH{bimagemgr1}{\bacula{} CD Image Manager}{fig:util:bimagemgr1}

Place a blank CDR disk in your recorder and click the ``Burn'' button. This will
cause a pop up window as shown in Figure \vref{fig:util:bimagemgr2} to display the burn progress.
% TODO: use tex to say figure number

\bimageH{bimagemgr2}{\bacula{} CD Image Burn Progress Window}{fig:util:bimagemgr2}
% TODO: use tex to say figure number

When the burn finishes the pop up window will display the results of cdrecord
% TODO: use tex to say figure number
as shown in Figure \vref{fig:util:bimagemgr3}. Close the pop up window and refresh the main window. The
last burn date will be updated and the ``Burn'' button for that volume will
disappear. Should you have a failed burn you can reset the last burn date of
that volume by clicking its ``Reset'' link.

\bimageH{bimagemgr3}{\bacula{} CD Image Burn Results}{fig:util:bimagemgr3}
% TODO: use tex to say figure number

In the bottom row of the main display window are two more buttons labeled
``Burn Catalog'' and ``Blank CDRW''. ``Burn Catalog'' will place a copy of
your \bacula{} catalog on a disk. If you use CDRW disks rather than CDR then
``Blank CDRW'' allows you to erase the disk before re-burning it. Regularly
committing your backup volume files and your catalog to disk with \btool{bimagemgr}
ensures that you can rebuild easily in the event of some disaster
on the \bacula{} server itself.
