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


#    print "Python SD JobEnd\n"

# 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)
Ejemplo n.º 2
0
        if 'Snap' in job.Job: return # cannot verify snapshot backups

        # Let's truncate any new purged volumes in this pool.
        runcmd = 'purge volume action=Truncate allpools storage=%s\nquit\n' % job.Storage
        # We cannot use job.run() because it won't accept the action
        # keyword for purge.  Le sigh.
        try:
            so = subprocess.Popen('bconsole', shell=True,
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE).communicate(runcmd)[0]
        except Exception as e:
            job.JobReport = 'Bailing ... '
            job.JobReport = str(e)
            return
        job.JobReport = "ran volume purge command: %s" % so

        # This bit gives us a chance (5%) of running a verify job against this one.
        if choice(numarray) < 5:          # 5% chance of running a verify
            runcmd = 'run job=%s-Verify jobid=%d yes' % (job.Job, job.JobId)
            newjob = job.run(runcmd)
            job.JobReport="%s: jobid=%d\n" % (runcmd, newjob)
        return

  # Called here when the Bacula daemon is going to exit
    def Exit(self, job):
        noop = 1
        return

# This is what makes it actually work
bacula.set_events(BaculaEvents()) # register daemon events desired