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 sys.stderr = events # send error output to Bacula
26 sys.stdout = events # send stdout to Bacula
27 jobid = job.JobId; client = job.Client
29 job.JobReport="Python Dir JobStart: JobId=%d Client=%s NumVols=%d\n" % (jobid,client,numvols)
31 # Bacula Job is going to terminate
32 def JobEnd(self, job):
35 job.JobReport="Python Dir JobEnd output: JobId=%d Status=%s Client=%s.\n" % (jobid, job.JobStatus, client)
37 # Called here when the Bacula daemon is going to exit
39 print "Daemon exiting."
41 bacula.set_events(BaculaEvents()) # register daemon events desired
44 There are the Job events that you can receive.
48 # Called here when you instantiate the Job. Not
52 def JobInit(self, job):
55 startid = job.run("run kernsave")
56 job.JobReport = "Python started new Job: jobid=%d\n" % startid
58 def JobRun(self, job):
61 def NewVolume(self, job):
65 job.JobReport = "JobId=%d Client=%s NumVols=%d" % (jobid, client, numvol)
66 job.JobReport="Python before New Volume set for Job.\n"
67 job.VolumeName="TestA-001"
68 job.JobReport="Python after New Volume set for Job.\n"
72 # Pass output back to Bacula
73 def write(self, text):
76 # Open file to be backed up. file is the filename
78 print "Open %s called" % file
79 self.fd = open('m.py', 'rb')
80 jobid = self.job.JobId
81 print "Open: JobId=%d" % jobid
82 print "name=%s" % bacula.name
84 # Read file data into Bacula memory buffer (mem)
85 # return length read. 0 => EOF, -1 => error
88 len = self.fd.readinto(mem)
89 print "Read %s bytes into mem.\n" % len