File: FDStartUp.py

package info (click to toggle)
bacula 5.0.2-2.2%2Bsqueeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 22,692 kB
  • ctags: 15,071
  • sloc: ansic: 109,509; cpp: 24,105; sh: 21,958; makefile: 4,012; perl: 3,083; sql: 1,366; lisp: 479; python: 166; xml: 64; sed: 32; awk: 8
file content (74 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#
# Bacula Python interface script for the File Daemon
#
# 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
     jobid = job.JobId
     client = job.Client
     job.JobReport="Python FD JobStart: JobId=%d Client=%s \n" % (jobid,client)
     return 1

  # Bacula Job is going to terminate
  def JobEnd(self, job):    
     jobid = job.JobId
     client = job.Client 
     job.JobReport="Python FD JobEnd output: JobId=%d Client=%s.\n" % (jobid, client)
     

  # Called here when the Bacula daemon is going to exit
  def Exit(self):
      noop = 1
     
bacula.set_events(BaculaEvents()) # register daemon events desired

"""
  There 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

  # Pass output back to Bacula
  def write(self, text):
     self.job.write(text)

  # Open file to be backed up. file is the filename
  def Python_open(self, file):
     print "Open %s called" % file
     self.fd = open(file, 'rb')
     jobid = self.job.JobId
     print "Open: %s" % file
 
  # Read file data into Bacula memory buffer (mem)
  #  return length read. 0 => EOF, -1 => error
  def Python_read(self, mem):
     print "Read called\n"
     len = self.fd.readinto(mem)
     print "Read %s bytes into mem.\n" % len
     return len

  # Close file
  def Python_close(self):
     self.fd.close()