Generating email warnings of Bacula jobs that complete "OK" but have zero files or zero bytes

A recent feature request on the Bacula Community version mailing list was to have Bacula set a job's status to "W" (Backup OK -- with warnings) when a job completed with zero files or zero bytes.

The general consensus was that this probably should be handled outside of Bacula code, since it would require and additional directive and of course additional coding.

This request interested me and it prompted me to write this short script.

After editing some basic variables near the top of the script, the script requires only one command line parameter - the jobid - and currently also accepts "debug" to log everything to stdout, and "zero_incremental_ok" which does not trigger when Incremental or Differential jobs have zero files or zero bytes.

Example email subject when an email report is triggered:

Subject: Warning from Bacula Server - Backup job 'SpeedyVMs' (jobid 18511) was "OK", but wrote zero files and/or zero bytes

Example output with "zero_incremental_ok" set:

# ./bacula_warn_on_zero.sh 18511 debug zero_incremental_ok                                                         
Debug mode enabled.
Option 'zero_incremental_ok' is set
Checking JobId: 18511
JobType: B
JobName: SpeedyVMs
JobStatus: Backup OK
JobLevel: Incremental
JobFiles: 0
JobBytes: 0
JobId "18511" is a Incremental backup job.
It terminated (Backup OK) which matches "Backup OK" or "Backup OK -- with warnings"
And it wrote "0" files and "0" bytes.
Continuing to process...
Checking if this is a Full backup job.
Level is Incremental or Differential.
Checking for 'zero_incremental_ok'
'zero_incremental_ok' is set.
Skipping zero files and zero bytes checks.
No warning will be triggered
Not sending warning email to admin.

Example output with "zero_incremental_ok" not set:

# ./bacula_warn_on_zero.sh 18511 debug 
Debug mode enabled.
Checking JobId: 18511
JobType: B
JobName: SpeedyVMs
JobStatus: Backup OK
JobLevel: Incremental
JobFiles: 0
JobBytes: 0
JobId "18511" is a Incremental backup job.
It terminated (Backup OK) which matches "Backup OK" or "Backup OK -- with warnings"
And it wrote "0" files and "0" bytes.
Continuing to process...
Checking if this is a Full backup job.
Level is Incremental or Differential.
Checking for 'zero_incremental_ok'
'zero_incremental_ok' not set. Checking for zero files or zero bytes
Zero files or zero bytes written in job.
Incremental and Differential backup jobs are not allowed to have zero files nor zero bytes!
Warning Condition triggered.
Sending warning email to admin: "bacula_admin@example.com"
AttachmentSize
bacula_warn_on_zero-20171120.sh11.47 KB

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <b> <i> <u> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
/
m
4
N
L
w
Enter the code without spaces and pay attention to upper/lower case.