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 = "x" # 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