I am trying to run a python script for the newVolume Event on bacula
5.01 on Ubuntu 10.04 with python 2.6.5
The installation is actually working without python scripting and the
LabelFormat directive in the bacula-dir.conf, but for the test I have
removed the LabelFormat from the pool definition.
The backup is written to file volumes on a hard disk.
For activating python scripting I added:
Scripts Directory = "/etc/bacula/python-scripts"
to the Director configuration.
This seems to work fine, since messages set with job.JobReport in the
script show up in the console messages.
This is the script I want to use, but it won't work:
#######################################
# Bacula Python interface script for the Director
#
# You must import both sys and bacula
import sys, bacula
# This is the list of Bacula daemon events that you
# can receive.
class BaculaEvents(object):
def __init__(self):
# Called here when a new Bacula Events class is
# is created. Normally not used
noop = 1
def JobStart(self, job):
"""
Called here when a new job is started. If you want
to do anything with the Job, you must register
events you want to receive.
"""
events = JobEvents() # create instance of Job class
events.job = job # save Bacula's job pointer
job.set_events(events) # register events desired
sys.stderr = events # send error output to Bacula
sys.stdout = events # send stdout to Bacula
# Bacula Job is going to terminate
def JobEnd(self, job):
jobid = job.JobId
client = job.Client
job.JobReport="Python Dir JobEnd output: JobId=%d Client=%s.\n" %
(jobid, client)
# Called here when the Bacula daemon is going to exit
def Exit(self, job):
print "Daemon exiting."
bacula.set_events(BaculaEvents()) # register daemon events desired
"""
These are the Job events that you can receive.
"""
class JobEvents(object):
def __init__(self):
# Called here when you instantiate the Job. Not
# normally used
noop = 1
def JobInit(self, job):
# Called when the job is first scheduled
noop = 1
def JobRun(self, job):
# Called just before running the job after initializing
# This is the point to change most Job parameters.
def NewVolume(self, job):
# Called when Bacula wants a new Volume name. The Volume
# name returned, if any, must be stored in job.VolumeName
jobid = job.JobId; client = job.Client; numvols = job.NumVols
name = client.partition(".")[0]
nextNum = 0
while TRUE:
nextNum = nextNum + 1
newVolume = "%s-backup-volume-%0.4d" % (name, nextNum)
if not job.DoesVolumeExist(newVolume):
job.VolumeName = newVolume
job.JobReport = "New volume name: %s \n" % (newVolume)
return 1
elif nextNum > 10000:
job.JobReport = "Error: can't create new volume label"
return 0
# job.JobReport = "Creating volume label: JobId=%d Client=%s
NumVols=%d" % (jobid, client, numvols)
def VolumePurged(self, job):
# Called when a Volume is purged. The Volume name can be referenced
# with job.VolumeName
noop = 1
#######################
When I run this script, then none of the two active job.JobReport
messages in the script show up and the backup job goes in state "waiting
for appendable volume"
I have replaced the newVolume event handler with something primitive
like this:
#########################
def NewVolume(self, job):
job.VolumeName = "test"
job.jobReport = "name set"
return 1
###########################
This time the message "name set" shows up and a new medium "test" is
added to the catalog, but the backup hangs and bacula never creates a
volume "test" on the disk.
Where should I start to look at for fixing the problem?
Regards,
Detlef Grittner
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users
|