Hoi, A few weeks ago, I wanted get sequential numbering for my backups. So for host1: host1-Full-0001, host1-Full-0002 etc, host1-Inc-0001, host1-Inc-0002, host1-Inc-0003 host1-Diff-0001, host1-Diff-0002 etc.
And for another host the same, but than with a different hostname, in a different directory. I did get the answer that this was not possible to config with the standard Bacula configuration scripts. Because in the catalog the numbering is always the nextnumber, so duplicate names cant be in the catalog. The solution for my problem, is making a python script. I have done this. In the directory file "bacula-dir.conf" i have added the script parameter: === Director { # define myself Name = host1-dir DIRport = 9101 # where we listen for UA connections QueryFile = "/etc/bacula/scripts/query.sql" WorkingDirectory = "/var/lib/bacula" Scripts Directory = "/etc/bacula/scripts" PidDirectory = "/var/run/bacula" Maximum Concurrent Jobs = 20 Password = "xxxxx" # Console password Messages = Daemon DirAddress = xxx.xxx.xxx.xxx } .... .... === I copyed the file (from the example-directory) DirStartUp.py I have modified this file, so i think it should work. ==> If I start bacula, start a job in bconsole, I get: Aug 14:58 host1-dir JobId 82: Python Dir JobStart: JobId=82 Client=host1-fd NumVols=0 So - the script is loaded - and no error !!!! (otherwise if there was an error i get python disabled) I see a DirStartUp.pyc in the scripts directory. But after this - the procedure is not working. In the console I get the next messages: 06-aug 15:13 host1-dir JobId 86: Python Dir JobStart: JobId=86 Client=host1-fd NumVols=0 06-aug 15:13 host1-dir JobId 86: name=host1-dir version=2.4.4 28 December 2008 conf=/etc/bacula/bacula-dir.conf working=/var/lib/bacula 06-aug 15:13 host1-dir JobId 86: Start Backup JobId 86, Job=host1Test0.2010-08-06_15.13.50.03 06-aug 15:13 host1-dir JobId 86: Using Device "FileStorage" 06-aug 15:13 host1-sd JobId 86: Job host1Test0.2010-08-06_15.13.50.03 waiting. Cannot find any appendable volumes. Please use the "label" command to create a new Volume for: Storage: "FileStorage" (/var/disk1/backup/) Pool: Full-Pool Media type: File I have to label by the label-command. I dont understand why. So can anybody tell me if i did forget something. I asume that the procedure is called, because in the original file there was no noop=1, so this NewVolumefunction was used in the example. So maybe i have to declare/or register something. I dont know. Please can someone help me with this. I'm just trying to understand python for not more than 2 weeks. This is the DirStartUp.py ===== # # Bacula Python interface script for the Director # # 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 numvols = job.NumVols job.JobReport="Python Dir JobStart: JobId=%d Client=%s NumVols=%d\n" % (jobid,client,numvols) # Bacula Job is going to terminate def JobEnd(self, job): jobid = job.JobId client = job.Client job.JobReport="Python Dir JobEnd output: JobId=%d Status=%s Client=%s.\n" % (jobid, job.JobStatus, client) # Called here when the Bacula daemon is going to exit def Exit(self, job): print "Daemon exiting." 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 def JobInit(self, job): noop = 1 if (job.JobId < 2): startid = job.run("run kernsave") job.JobReport = "Python started new Job: jobid=%d\n" % startid print "name=%s version=%s conf=%s working=%s" % (bacula.Name, bacula.Version, bacula.ConfigFile, bacula.WorkingDir) def JobRun(self, job): noop = 1 def NewVolume(self, job): jobid = job.JobId client = job.Client level = job.Level #1e add numvol = job.NumVols; print job.CatalogRes # job.JobReport = "JobId=%d Client=%s NumVols=%d" % (jobid, client, numvol) # job.JobReport="Python before New Volume set for Job.\n" # Vol = "TestA-%d" % numvol # job.JobReport = "Exists=%d TestA-%d" % (job.DoesVolumeExist(Vol), numvol) # job.VolumeName="TestA-%d" % numvol # job.JobReport="Python after New Volume set for Job.\n" # return 1 ## number = -1 VolumeName="" client=client[0:len(client)-2] if level[0:1] == "F": level = "Full-" if level[0:1] == "D": level = "Diff-" if level[0:1] == "I": level = "Inc-" number = -1 exists=0 while number < 10000: VolumeName = client + level number = number + 1 numtot = number for i in (1000, 100, 10, 1): num = numtot//i #integer van numtot/i dus 4321//1 --> 4 numtot = numtot%i #rest in geheel getal bij deling door i dus 4321%1000 --> 321 VolumeName=VolumeName+chr(num+48) if not job.DoesVolumeExist(VolumeName): job.VolumeName = VolumeName job.JobReport = "New Volumename: %s \n" % (VolumeName) return 1 if number == 10000 : #print "Error can't create new Label" job.JobReport = "Error can't create new Label" return 0 ## def VolumePurged(self, job): 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 # NOT YET IMPLEMENTED def open(self, file): print "Open %s called" % file self.fd = open('m.py', 'rb') jobid = self.job.JobId print "Open: JobId=%d" % jobid # Read file data into Bacula memory buffer (mem) # return length read. 0 => EOF, -1 => error # NOT YET IMPLEMENTED def read(self, mem): print "Read called\n" len = self.fd.readinto(mem) print "Read %s bytes into mem.\n" % len return len # Close file # NOT YET IMPLEMENTED def close(self): self.fd.close() ===== Thanks Erik ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ Bacula-users mailing list Bacula-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bacula-users