Bacula: RunBeforeJob on Storage Daemon
This article deals with a particular Bacula
This directive, part of a Job resource, is used to run a command after the job completed. In my case, I am
collecting statistics regarding tape errors.
The directive has many options, including:
- run before or after the Job
- run on the client or on the Director
- run on success
- run on failure
- execute a console command
For more information on this directive, refer to Job Resource
in the Bacula documentation.
One interesting note, I found this in the documentation:
%v = Volume name (Only on director side)
Today I realised that my statistics gathering program must run in the
Storage Daemon (SD). Previously,
my Director (DIR) and SD were both on the same server. In my new setup,
I’ve created a new SD which
has 12TB of HDD storage and 10TB of tape storage (but just a 10 slot tape
library). My JobDefs resource
contained this line
RunAfterJob = "/home/dan/bin/dlt-stats %l %v"
This directive can be run on either the Client or on the DIR, but not on
the SD. This is an issue. I solved
it by using ssh. The above line is now:
RunAfterJob = "/home/dan/bin/dlt-stats-kraken %l %v"
Where /home/dan/bin/dlt-stats-kraken contains:
ssh -i /home/dan/bin/ssh-kraken-dlt-stats dan@kraken
/home/dan/bin/dlt-stats $1 $2
The existing dlt-stats script has been copied to the new host (kraken).
Thus, the above command executes the
script on kraken. How does it do that? With a passphrase-less ssh-key.
A detailed explanation of that is
beyond the scope of this article, but I have used and written about this
great tool before.
After creating the ssh public key, I got this error:
24-Nov 18:03 bacula-dir JobId 40176: AfterJob: Warning: Identity file
/home/dan/.ssh/ssh-kraken-dlt-stats not accessible: Permission denied.
This was an issue with having the key within ~/.ssh, which is usually
chmod 700. These permission levels prevented meaning Bacula from reading it. I moved the
private and public key to ~/bin, did a chown and chmod so Bacula could
read it, and things started working/