Hello Folks, I'm tryint to write a DirStartup script which define volume names and upload the volume file to an azure storage service through their rest API (my backup server is on linode and cannot use the smb to mount the storage).
So, looking at the python script documentation page, I wrote the following script: import bacula, os, stat, sys, pdb, re from azure.storage.file import FileService backup_dir = '/bacula/backup' def get_volname(job): """ The Job name is composed from the Job Name and the JobId. """ return "{0}.{1}".format(job.Job, job.JobId) def get_volumes(path, volname, next=False): """ Get Volumes associated with a Given Job. Optionally this function can be used discover the next Volume Id available to be created. """ pattern = re.compile(r'(\w+)-(\w+\.\w{0,}\.\w{0,})-(\d+)-(\d+)') # if next: # vol_index = int(pattern.match(volname).group(4)) + 1 # return os.path.join(path, volname + '-{0}'.format(vol_index)) volumes = [] for root, dirs, files in os.walk(path): if volname in files: volumes.append(files) return volumes class BaculaEvents: def __init__(self): noop = 1 backup_dir = '/bacula/backup' self.file_service = FileService(account_name='storage', account_key='key') def JobStart(self, job): """ Download the volumes associated with a Given Job from the Azure File Storage if it exists. """ print("Job Start: {0}".format(job)) events = JobEvents() events.job = job job.set_events(events) vol_name = get_volname(job) volumes = get_volumes(backup_dir, vol_name, next=False) if job.DoesVolumeExist(vol_name): for volume in volumes: os.remove(volume) self.file_service.get_file_from_path('latest', None, None, volume) def JobEnd(self, job): """ Upload the volumes associated with a Given Job to the Azure File Storage. TODO: Create a Symlink stub?? """ print("Job End: {0}".format(job)) vol_name = get_volname(job) print(vol_name) vol_file = backup_dir + '/' + vol_name self.file_service.create_file_from_path('latest', None, vol_name, vol_file) os.remove(vol_file) def Exit(self, job): """ Avoiding Bacula Warning. """ print("Daemon Exiting") bacula.set_events(BaculaEvents()) class JobEvents: def __init__(self): """ Avoiding Bacula Warning. """ noop = 1 def JobInit(self, job): """ Avoiding Bacula Warning. """ noop = 1 def JobRun(self, job): """ Avoiding Bacula Warning. """ noop = 1 def NewVolume(self, job): """ Verify the last volume and create One using the get_volumes method. """ vol_name = get_volname(job) next_vol = get_volumes(backup_dir, vol_name, next=False) print("Creating new Vol: {0}".format(next_vol)) job.VolumeName = next_vol return 1 def VolumePurged(self, job): noop = 1 self.file_service.delete_file('latest', None, job.VolumeName) But, When I try to run a backup job, the following error occurs: Traceback (most recent call last): File "/etc/bacula/scripts/DirStartUp.py", line 110, in NewVolume job.VolumeName = next_vol TypeError: Read-only attribute bacula-dir: pythondir.c:464-44 Error in Python method NewVolume In the documentation, the following behaviour is stated: *VolumeName*Set a new Volume name. Valid only during the NewVolume event. So ... how can I set a new Volume Name using the DirStartup Script? Thanks in advance.
------------------------------------------------------------------------------
_______________________________________________ Bacula-users mailing list Bacula-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bacula-users