Bacula Reports version 0.9 Written by Berend Dekens ( ABOUT: After using Bacula for some time, the large number of mailings you get when using it on a small server park drove me insane. Even when using filters to sort out new mail, it is hard to see if everything is going as it should be. Enter Bacula Reports: a mail aggregator for Bacula 2.x and 3.x. Bacula Reports consists of a faux mail command (which does not send out reports by mail but rather analyses and stores them) and a report generator which aggregates all the stored reports into one mailing with an overview and some HTML styling to make it more readable (if you don't want HTML, modify the template to generate plain text). By intergrating the scripts into the Bacula configuration at 2 points (a mail command used for sending out reports and a job to send out the combined report), the avalange of daily mails changes into one neat report at the end of the backup cycle. Normal error messages and operator messages are unaffected and will be delivered as they used to be, only the backup reports per job are redirected to Bacula Reports. REQUIREMENTS: - Linux 32 or 64-bit (tested on Gentoo 2008 and CentOS 5.2), things might work on Windows but this is untested and probably requires some tweaking - Bacula 2.x or 3.x (the machine running the director is the machine you should install this package on) - A working Bacula setup: do not try to add this reporting tool to an untested setup as you might run into trouble and cannot determine which program is at fault - PHP as a command line interpreter, you can test this by typing 'php -v' and you should see something like: PHP 5.1.6 (cli) (built: May 24 2008 14:10:50) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies - 10 minutes of your time or less if you have done this before (assuming everything works out of the box) INSTALLATION INSTRUCTIONS: - Make sure you have PHP as a command line interpreter and that the binary is found in /usr/bin/php (otherwise, adjust the paths in the scripts) - Extract all files into (for example) /usr/local/share/bacula-reports - Change ownership of (at least) the installation directory itself to the bacula user (bacula user needs write permissions): # chown -R bacula:bacula /usr/local/share/bacula-reports - Make sure both entry scripts are executable: # chmod +x /usr/local/share/bacula-reports/mtx # chmod +x /usr/local/share/bacula-reports/compile-report - Create links to the scripts from the executable directories (allowing the scripts to be run globally without a prefix) # ln -s /usr/local/share/bacula-reports/mtx /usr/sbin/bacula-mtx # ln -s /usr/local/share/bacula-reports/compile-report /usr/sbin/bacula-compile-report - If you want security, make the scripts and directories only accessable for the bacula user (locking other users and processes out) - Alter the email name and email target to your own, change other settings if needed. Normally you only change the two email settings. Bacula Reports is now installed. Please note that if you changed the installation directory or run into trouble, you might want to check to see if the paths are correct. The next task is to divert the director output to Bacula Reports instead of the bstmp program. Open your director configuration and find the Messages directive and change the mailcommand command to use the new bacula-mtx script: Messages { Name = Standard mailcommand = "/usr/sbin/bacula-mtx -h localhost -f \"\(Bacula\) \" -s \"Bacula: %t %e of %c %l\" %r" operatorcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \" -s \"Bacula: Intervention needed for %j\" %r" mail = = all, !skipped operator = = mount console = all, !skipped, !saved append = "/var/lib/bacula/log" = all, !skipped } Please note that you should only change the mailcommand directive: that is the command used to send status reports of jobs. Other mail commands are used to signal problems and should not be passed to Bacula Reports. On a side note: the mtx script has a fail-safe that should invoke bsmtp if it can not store the backup report or something goes wrong. If you still receive normal bacula status reports after modifying the director configuration (and reloading it!), something is going wrong. Finally, we need to send the accumulated reports on a certain time. You can add the bacula-compile-report script to your crontab (make sure it runs as the bacula user) or add it to a job. For example, the database backup job is great for this purpose as it runs after all the normal jobs: # Backup the catalog database (after the nightly save) Job { Name = "BackupCatalog" JobDefs = "DefaultJob" Level = Full FileSet="Catalog" Schedule = "WeeklyCycleAfterBackup" # This creates an ASCII copy of the catalog RunBeforeJob = "/usr/lib64/bacula/make_catalog_backup bacula yourpassword" # This deletes the copy of the catalog RunAfterJob = "/usr/lib64/bacula/delete_catalog_backup" # Bacula Reports: Send out the daily report after all other backups RunScript { Command = "/usr/sbin/bacula-compile-report" RunsWhen = After RunsOnFailure = yes RunsOnClient = no RunsOnSuccess = yes # default, you can drop this line } Write Bootstrap = "/var/lib/bacula/BackupCatalog.bsr" Priority = 11 # run after main backup } Congratulations! You have completed the install of Bacula Reports and the intergration into Bacula. If things go very wrong, make sure all the files have the correct permissions, scripts are run with the correct user credentials and if all else fails: revert the director configuration to use bsmtp and check again if everything is working properly. CHANGELOG: 0.9: - Make reporting address variable and part of - Few template tweaks and bug fixes - First public release 0.8: - Fix more template bugs (and add things like duration for jobs and reports) - Write readme guide for other people - Clean up code for publication 0.7: - Fix bugs in template like labels and show more information - Add alternative body to notify text-only users that the content is in HTML 0.6: - Add more variables to make reports more readable (instead of just a summation of reports) - Add Bacula logo to template - Modify mailer code to include images 0.5: - Add Smarty for generating reports ( - First HTML template 0.4: - Internal rewrites to make use of fewer classes and speed things up when handling lots of reports - Introduce lock files to make sure reads and (mainly) writes are performed serially (to prevent data corruption) 0.3: - Use PHPMailer ( to handle mail generation to include HTML body 0.2: - Change of storage format for jobs using classes and string storage 0.1: - Initial version with basic parsing and report storage - Initial mailer script using PHP mailing and no layouts