From: Joris H. <jh...@ma...> - 2011-07-16 18:36:22
|
Ok, at his time no answer received from user-list. Now i want ask questing here in the developer list... i played with this script: 1 # 2 # Bacula Python interface script for the Director 3 # 4 5 # You must import both sys and bacula 6 import sys, bacula 7 8 class globalVars(): 9 def __init__( self ): 10 self.fullBackupIsActive = False 11 12 myGlobal = globalVars() 13 14 # This is the list of Bacula daemon events that you 15 # can receive. 16 class BaculaEvents(object): 17 def __init__(self): 18 # Called here when a new Bacula Events class is 19 # is created. Normally not used 20 noop = 1 21 22 def JobStart(self, job): 23 """ 24 Called here when a new job is started. If you want 25 to do anything with the Job, you must register 26 events you want to receive. 27 """ 28 events = JobEvents() # create instance of Job class 29 events.job = job # save Bacula's job pointer 30 job.set_events(events) # register events desired 31 sys.stderr = events # send error output to Bacula 32 sys.stdout = events # send stdout to Bacula 33 jobid = job.JobId; client = job.Client 34 numvols = job.NumVols 35 prio = job.Priority 36 job.JobReport="Python Dir JobStart: JobId=%d Client=%s NumVols=%d\n Priority=%s" % (jobid,client,numvols,prio) 37 38 # Bacula Job is going to terminate 39 def JobEnd(self, job): 40 # global i 41 jobid = job.JobId 42 client = job.Client 43 job.JobReport="Python Dir JobEnd output: JobId=%d Status=%s Client=%s.\n" % (jobid, job.JobStatus, client) 44 if (job.Client == "stf-imap1") and (job.Level == "Full"): 45 myGlobal.fullBackupIsActive = False 46 job.JobReport="Imap Full Backup finished other following jobs keep there priority" 47 48 # Called here when the Bacula daemon is going to exit 49 def Exit(self, job): 50 print "Daemon exiting." 51 52 bacula.set_events(BaculaEvents()) # register daemon events desired 53 54 """ 55 There are the Job events that you can receive. 56 """ 57 class JobEvents(object): 58 def __init__(self): 59 # Called here when you instantiate the Job. Not 60 # normally used 61 noop = 1 62 63 def JobInit(self, job): 64 #noop = 1 65 #if (job.JobId < 2): 66 #startid = job.run("run kernsave") 67 #job.JobReport = "Python started new Job: jobid=%d\n" % startid 68 69 print "name=%s version=%s conf=%s working=%s" % (bacula.Name, bacula.Version, bacula.ConfigFile, bacula.WorkingDir) 70 if (myGlobal.fullBackupIsActive): 71 job.Priority = 9 72 job.JobReport = "Priority changed to 9 because Imap-Fullbackup ist running..." 73 if (job.Client == "stf-imap1") and (job.Level == "Full"): 74 myGlobal.fullBackupIsActive=True 75 job.JobReport="Imap Full Backup detected set all other following jobs to higher priority" 76 77 def JobRun(self, job): 78 noop = 1 79 80 def NewVolume(self, job): 81 jobid = job.JobId 82 client = job.Client 83 numvol = job.NumVols; 84 print job.CatalogRes 85 job.JobReport = "JobId=%d Client=%s NumVols=%d" % (jobid, client, numvol) 86 job.JobReport="Python before New Volume set for Job.\n" 87 Vol = "TestA-%d" % numvol 88 job.JobReport = "Exists=%d TestA-%d" % (job.DoesVolumeExist(Vol), numvol) 89 job.VolumeName="TestA-%d" % numvol 90 job.JobReport="Python after New Volume set for Job.\n" 91 return 1 92 noop = 1 93 94 def VolumePurged(self, job): 95 noop = 1 96 97 # Pass output back to Bacula 98 def write(self, text): 99 self.job.write(text) 100 101 # Open file to be backed up. file is the filename 102 # NOT YET IMPLEMENTED 103 def open(self, file): 104 print "Open %s called" % file 105 self.fd = open('m.py', 'rb') 106 jobid = self.job.JobId 107 print "Open: JobId=%d" % jobid 108 109 # Read file data into Bacula memory buffer (mem) 110 # return length read. 0 => EOF, -1 => error 111 # NOT YET IMPLEMENTED 112 def read(self, mem): 113 print "Read called\n" 114 len = self.fd.readinto(mem) 115 print "Read %s bytes into mem.\n" % len 116 return len 117 118 # Close file 119 # NOT YET IMPLEMENTED 120 def close(self): 121 self.fd.close() 122 but i get this error if i start the next job... 15-Jul 22:07 stf-bac1-dir JobId 304487: Traceback (most recent call last): 15-Jul 22:07 stf-bac1-dir JobId 304487: File "/etc/bacula/scripts/DirStartUp.py", line 71, in JobInit 15-Jul 22:07 stf-bac1-dir JobId 304487: 15-Jul 22:07 stf-bac1-dir JobId 304487: ValueError Any pythen experts are there wich can help me to get this script working? Thanks for help. JHN Am 14.07.11 18:54, schrieb Joris Heinrich: > Hello All, > > I m looking for examples about phyton startup scripts... My issue is, > that i will change the priority of jobs to the starting time. > > the script should look for an fullbackup-job and if this job exists > and run... all other jobs should get an higher priority. If this job > not running, configured priority should not changed. > > Any one have an idea or implemented similar solution? > > Thanks for help and > > Best Regards > > > JHN > > > ------------------------------------------------------------------------------ > AppSumo Presents a FREE Video for the SourceForge Community by Eric > Ries, the creator of the Lean Startup Methodology on "Lean Startup > Secrets Revealed." This video shows you how to validate your ideas, > optimize your ideas and identify your business strategy. > http://p.sf.net/sfu/appsumosfdev2dev > > > _______________________________________________ > Bacula-users mailing list > Bac...@li... > https://lists.sourceforge.net/lists/listinfo/bacula-users |