2 # Bacula Python interface script for the Director
5 # You must import both sys and bacula
8 # This is the list of Bacula daemon events that you
12 # Called here when a new Bacula Events class is
13 # is created. Normally not used
16 def JobStart(self, job):
18 Called here when a new job is started. If you want
19 to do anything with the Job, you must register
20 events you want to receive.
22 events = JobEvents() # create instance of Job class
23 events.job = job # save Bacula's job pointer
24 # job.set_events = events # register events desired
25 job.set_events(events) # register events desired
26 sys.stderr = events # send error output to Bacula
27 sys.stdout = events # send stdout to Bacula
28 jobid = job.JobId; client = job.Client
30 job.JobReport="Python Dir JobStart: JobId=%d Client=%s NumVols=%d\n" % (jobid,client,numvols)
33 # Bacula Job is going to terminate
34 def JobEnd(self, job):
37 job.JobReport="Python Dir JobEnd output: JobId=%d Client=%s.\n" % (jobid, client)
39 startid = job.run("run kernsave")
40 print "Python started new Job: jobid=", startid
43 # Called here when the Bacula daemon is going to exit
45 print "Daemon exiting."
47 bacula.set_events(BaculaEvents()) # register daemon events desired
50 There are the Job events that you can receive.
54 # Called here when you instantiate the Job. Not
58 def NewVolume(self, job):
62 print "JobId=%d Client=%s NumVols=%d" % (jobid, client, numvol)
63 job.JobReport="Python before New Volume set for Job.\n"
64 job.VolumeName="TestA-001"
65 job.JobReport="Python after New Volume set for Job.\n"
69 # Pass output back to Bacula
70 def write(self, text):
73 # Open file to be backed up. file is the filename
75 print "Open %s called" % file
76 self.fd = open('m.py', 'rb')
77 jobid = self.job.JobId
78 print "Open: JobId=%d" % jobid
79 print "name=%s" % bacula.name
81 # Read file data into Bacula memory buffer (mem)
82 # return length read. 0 => EOF, -1 => error
85 len = self.fd.readinto(mem)
86 print "Read %s bytes into mem.\n" % len