By default, Bacula is configured to send an email report for every Job that runs (Backup, Restore, Copy, Migration, Admin, Verify). The subject of each email indicates the status of the Job (OK, OK — with warnings, Failed, etc.), but if you manage a large Bacula infrastructure and you are running 2,000, 3,000, or more jobs per day, who is going to read all of those emails? How do you know if your backups ran OK last night, last week, last month?
That was my question about 10 years ago, so I wrote a small bash script which sent a simple text email showing a list of jobs that had completed in the last 24 hours. The text table showed Jobid, Name, Status, Files, Bytes, Start Time, End Time, and Run Time. The output was very basic, obtaining its information by piping commands to bconsole and using sed, awk, and grep to pick out the necessary information and just printing the results. For example, the status of each job was just the single character like ‘T’ (for ‘terminated OK’) as stored in each job’s ‘jobstatus’ field in the database, not a word like “OK”, or “Canceled”.
I released the original script as open-source and announced it on the Bacula Community mailing list. Shortly after, I began to receive bug reports and some great feature requests. Over time, the script grew into a giant, unmaintainable mashup/combination of bash & awk. 🙂
This script is a rewrite/port of that original baculabackupreport.sh bash/awk script in Python.
Rewriting this script in Python has been an interesting, fun, and challenging experience. Not only have I learned some things about Python, but I was also able to identify and fix all of the bugs which were impossible to even locate (much less fix) in the bash/awk version. Additionally, thanks to Python’s capabilities compared to bash and awk, I was able to add many more options and features along the way.
As an added benefit, and due to all the digging into Bacula’s internals, I learned more than I bargained for about Copy, Migration, and Verify jobs. The end result is that the report is able to link and display information about copy/migration control jobs, the original jobid they copied/migrated, and the jobid they were copied/migrated to. It also shows the original jobid that a copied/migrated job was copied/migrated from.
Some key features:
- Supports Bacula Enterprise Edition as well as Bacula Community Edition
- Supports PostgreSQL, MySQL, and MariaDB database backends (default PostgreSQL)
- Can create direct URL links into your BWeb (Enterprise) or Baculum (Community) web gui for each job, and for “always failing” jobs
- Number of hours to report on is configurable (default 24)
- Number of days to report on jobs that have never succeeded (always failing) is configurable (default 7)
- The job columns to display and their order are fully configurable
- The order of jobs listed is configurable (default: ‘ORDER BY jobid, descending’)
- The jobs to report on may be filtered by Client Name, Job Name, or both. Useful for sending specific reports to specific admins.
- All key/primary variables may be assigned on the command line, via environment variables, or just accept the defaults
- All HTML colors and styles are configurable by editing clearly named variables in the script
- Email report may include Job summaries of all jobs
- Email report may include full job logs of ‘bad’ jobs (eg: all necessary information about problem jobs in one email)
In this screenshot, the command line parameter “-j Speedy%” was used to limit the output to only show jobs who’s name starts with “Speedy” so we see some jobs and the Summary:
In this screenshot where no filters were used, we see some backup, copy/migration control, verify, and some copied and migrated jobs (Summary below it):
Link to current version on Github:
I’d like to thank my friends and colleagues Dorian and Marcin!
@Dorian for the seemingly infinite number of late nights discussing Python, Bacula, this script, as well as the live coding sessions along the way. I learned a lot of Python in these sessions!
@Marcin for helping me to finally get a working Baculum web gui running in my Arch Linux/Bacula Community environment and for offering me a nice patch to replace my original “web 1.0” HTML tables with more current inline CSS.