2 # Bacula Python interface script
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.get("JobId"); client = job.get("Client");
28 numvols = job.get("NumVols")
29 job.set(JobReport="Python StartJob: JobId=%d Client=%s NumVols=%d\n" % (jobid,client,numvols))
32 # Bacula Job is going to terminate
33 def JobEnd(self, job):
34 jobid = job.get("JobId")
35 client = job.get("Client")
36 job.set(JobReport="Python EndJob output: JobId=%d Client=%s.\n" % (jobid, client))
38 startid = job.run("run kernsave")
39 print "Python started new Job: jobid=", startid
42 # Called here when the Bacula daemon is going to exit
44 print "Daemon exiting."
46 bacula.set_events(BaculaEvents()) # register daemon events desired
49 There are the Job events that you can receive.
53 # Called here when you instantiate the Job. Not
57 def NewVolume(self, job):
58 jobid = job.get("JobId")
59 client = job.get("Client")
60 numvol = job.get("NumVols");
61 print "JobId=%d Client=%s NumVols=%d" % (jobid, client, numvol)
62 job.set(JobReport="Python before New Volume set for Job.\n")
63 job.set(VolumeName="TestA-001")
64 job.set(JobReport="Python after New Volume set for Job.\n")
68 # Pass output back to Bacula
69 def write(self, text):
72 # Open file to be backed up. file is the filename
74 print "Open %s called" % file
75 self.fd = open('m.py', 'rb')
76 jobid = self.job.get("JobId")
77 print "Open: JobId=%d" % jobid
78 print "name=%s" % bacula.name
80 # Read file data into Bacula memory buffer (mem)
81 # return length read. 0 => EOF, -1 => error
84 len = self.fd.readinto(mem)
85 print "Read %s bytes into mem.\n" % len