2 # Bacula Python interface script for the File Daemon
4 # You must import both sys and bacula
7 # This is the list of Bacula daemon events that you
9 class BaculaEvents(object):
11 # Called here when a new Bacula Events class is
12 # is created. Normally not used
15 def JobStart(self, job):
17 Called here when a new job is started. If you want
18 to do anything with the Job, you must register
19 events you want to receive.
21 events = JobEvents() # create instance of Job class
22 events.job = job # save Bacula's job pointer
23 job.set_events(events) # register events desired
24 sys.stderr = events # send error output to Bacula
25 sys.stdout = events # send stdout to Bacula
28 job.JobReport="Python FD JobStart: JobId=%d Client=%s \n" % (jobid,client)
31 # Bacula Job is going to terminate
32 def JobEnd(self, job):
35 job.JobReport="Python FD JobEnd output: JobId=%d Client=%s.\n" % (jobid, client)
38 # Called here when the Bacula daemon is going to exit
42 bacula.set_events(BaculaEvents()) # register daemon events desired
45 There are the Job events that you can receive.
47 class JobEvents(object):
49 # Called here when you instantiate the Job. Not
53 # Pass output back to Bacula
54 def write(self, text):
57 # Open file to be backed up. file is the filename
58 def Python_open(self, file):
59 print "Open %s called" % file
60 self.fd = open(file, 'rb')
61 jobid = self.job.JobId
62 print "Open: %s" % file
64 # Read file data into Bacula memory buffer (mem)
65 # return length read. 0 => EOF, -1 => error
66 def Python_read(self, mem):
68 len = self.fd.readinto(mem)
69 print "Read %s bytes into mem.\n" % len
73 def Python_close(self):