1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
3
<!--Converted with LaTeX2HTML 2002-2-1 (1.71)
4
original version by: Nikos Drakos, CBLU, University of Leeds
5
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
6
* with significant contributions from:
7
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
10
<TITLE>Variable Expansion</TITLE>
11
<META NAME="description" CONTENT="Variable Expansion">
12
<META NAME="keywords" CONTENT="bacula">
13
<META NAME="resource-type" CONTENT="document">
14
<META NAME="distribution" CONTENT="global">
16
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
17
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
19
<LINK REL="STYLESHEET" HREF="bacula.css">
21
<LINK REL="next" HREF="Using_Stunne_Encryp_Commun.html">
22
<LINK REL="previous" HREF="Thanks.html">
23
<LINK REL="up" HREF="Bacula_Users_Guide.html">
24
<LINK REL="next" HREF="Using_Stunne_Encryp_Commun.html">
29
<DIV CLASS="navigation"><!--Navigation Panel-->
30
<A NAME="tex2html2537"
31
HREF="Using_Stunne_Encryp_Commun.html">
32
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
33
<A NAME="tex2html2531"
34
HREF="Bacula_Users_Guide.html">
35
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
36
<A NAME="tex2html2525"
38
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
39
<A NAME="tex2html2533"
41
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
42
<A NAME="tex2html2535"
43
HREF="General_Index.html">
44
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
46
<B> Next:</B> <A NAME="tex2html2538"
47
HREF="Using_Stunne_Encryp_Commun.html">Using Stunnel to Encrypt</A>
48
<B> Up:</B> <A NAME="tex2html2532"
49
HREF="Bacula_Users_Guide.html">Bacula User's Guide</A>
50
<B> Previous:</B> <A NAME="tex2html2526"
51
HREF="Thanks.html">Thanks</A>
52
<B> <A NAME="tex2html2534"
53
HREF="Contents.html">Contents</A></B>
54
<B> <A NAME="tex2html2536"
55
HREF="General_Index.html">Index</A></B>
58
<!--End of Navigation Panel-->
59
<!--Table of Child-Links-->
60
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
62
<UL CLASS="ChildLinks">
63
<LI><A NAME="tex2html2539"
64
HREF="Variable_Expansion.html#SECTION005810000000000000000">General Functionality</A>
65
<LI><A NAME="tex2html2540"
66
HREF="Variable_Expansion.html#SECTION005820000000000000000">Bacula Variables</A>
67
<LI><A NAME="tex2html2541"
68
HREF="Variable_Expansion.html#SECTION005830000000000000000">Full Syntax</A>
69
<LI><A NAME="tex2html2542"
70
HREF="Variable_Expansion.html#SECTION005840000000000000000">Semantics</A>
71
<LI><A NAME="tex2html2543"
72
HREF="Variable_Expansion.html#SECTION005850000000000000000">Examples</A>
74
<!--End of Table of Child-Links-->
77
<H1><A NAME="SECTION005800000000000000000"></A>
78
<A NAME="VarsChapter"></A>
86
Please note that as of version 1.37, the Variable Expansion
87
is deprecated and replaced by Python scripting (not yet
91
Variable expansion is somewhat similar to Unix shell variable expansion.
92
Currently (version 1.31), it is used only in format labels, but in the future,
93
it will most likely be used in more places.
97
<H1><A NAME="SECTION005810000000000000000">
98
General Functionality</A>
104
This is basically a string expansion capability that permits referencing
105
variables, indexing arrays, conditional replacement of variables, case
106
conversion, substring selection, regular expression matching and replacement,
107
character class replacement, padding strings, repeated expansion in a user
108
controlled loop, support of arithmetic expressions in the loop start, step and
109
end conditions, and recursive expansion.
112
When using variable expansion characters in a Volume Label Format record, the
113
format should always be enclosed in double quotes (<B>"</B>).
116
For example, <B>${HOME}</B> will be replaced by your home directory as
117
defined in the environment. If you have defined the variable <B>xxx</B> to be
118
<B>Test</B>, then the reference <B>${xxx:p/7/Y/r}</B> will right pad the
119
contents of <B>xxx</B> to a length of seven characters filling with the
120
character <B>Y</B> giving <B>YYYTest</B>.
124
<H1><A NAME="SECTION005820000000000000000">
131
Within Bacula, there are three main classes of variables with some minor
132
variations within the classes. The classes are:
136
<DT><STRONG>Counters</STRONG></DT>
137
<DD><A NAME="28603"></A>
138
Counters are defined by the <B>Counter</B> resources in the Director's conf
139
file. The counter can either be a temporary counter that lasts for the
140
duration of Bacula's execution, or it can be a variable that is stored in
141
the catalog, and thus retains its value from one Bacula execution to another.
142
Counter variables may be incremented by postfixing a plus sign (<B>+</B> after
147
<DT><STRONG>Internal Variables</STRONG></DT>
148
<DD><A NAME="28606"></A>
149
Internal variables are read-only, and may be related to the current job (i.e.
150
Job name), or maybe special variables such as the date and time. The
151
following variables are available:
159
<DD>-- the current month 1-12
162
<DD>-- the day of the month 1-31
168
<DD>-- the current minute 0-59
171
<DD>-- the current second 0-59
174
<DD>-- the current day of the week 0-6 with 0 being Sunday
180
<DD>-- the Director's name
192
<DD>-- the unique job name composed of Job and date
195
<DD>-- the Storage daemon's name
198
<DD>-- the Client's name
201
<DD>-- the current number of Volumes in the Pool
207
<DD>-- the Catalog name
210
<DD>-- the Media Type
217
<DT><STRONG>Environment Variables</STRONG></DT>
218
<DD><A NAME="28609"></A>
219
Environment variables are read-only, and must be defined in the environment
220
prior to executing Bacula. Environment variables may be either scalar or an
221
array, where the elements of the array are referenced by subscripting the
222
variable name (e.g. <B>${Months[3]}</B>). Environment variable arrays are
223
defined by separating the elements with a vertical bar (<B>|</B>), thus <B>set Months="Jan|Feb|Mar|Apr|..."</B> defines an environment variable named
224
<B>Month</B> that will be treated as an array, and the reference <B>${Months[3]}</B> will yield <B>Mar</B>. The elements of the array can have
231
<H1><A NAME="SECTION005830000000000000000">
238
Since the syntax is quite extensive, below, you will find the pseudo BNF. The
239
special characters have the following meaning:
244
( ) grouping if the parens are not quoted
245
| separates alternatives
246
'/' literal / (or any other character)
247
CAPS a character or character sequence
248
* preceding item can be repeated zero or more times
249
? preceding item can appear zero or one time
250
+ preceding item must appear one or more times
253
And the pseudo BNF describing the syntax is:
259
| INDEX_OPEN input INDEX_CLOSE (loop_limits)?
261
variable ::= DELIM_INIT (name|expression)
262
name ::= (NAME_CHARS)+
263
expression ::= DELIM_OPEN
265
(INDEX_OPEN num_exp INDEX_CLOSE)?
268
command ::= '-' (TEXT_EXP|variable)+
269
| '+' (TEXT_EXP|variable)+
270
| 'o' NUMBER ('-'|',') (NUMBER)?
272
| '*' (TEXT_EXP|variable)+
273
| 's' '/' (TEXT_PATTERN)+
274
'/' (variable|TEXT_SUBST)*
275
'/' ('m'|'g'|'i'|'t')*
276
| 'y' '/' (variable|TEXT_SUBST)+
277
'/' (variable|TEXT_SUBST)*
280
'/' (variable|TEXT_SUBST)*
282
| '%' (name|variable)+
283
('(' (TEXT_ARGS)? ')')?
287
| operand ('+'|'-'|'*'|'/'|'%') num_exp
288
operand ::= ('+'|'-')? NUMBER
292
loop_limits ::= DELIM_OPEN
293
(num_exp)? ',' (num_exp)? (',' (num_exp)?)?
295
NUMBER ::= ('0'|...|'9')+
296
TEXT_PATTERN::= (^('/'))+
297
TEXT_SUBST ::= (^(DELIM_INIT|'/'))+
298
TEXT_ARGS ::= (^(DELIM_INIT|')'))+
299
TEXT_EXP ::= (^(DELIM_INIT|DELIM_CLOSE|':'|'+'))+
300
TEXT ::= (^(DELIM_INIT|INDEX_OPEN|INDEX_CLOSE))+
307
NAME_CHARS ::= 'a'|...|'z'|'A'|...|'Z'|'0'|...|'9'
311
<H1><A NAME="SECTION005840000000000000000">
317
The items listed in <B>command</B> above, which always follow a colon (<B>:</B>)
318
have the following meanings:
322
- perform substitution if variable is empty
323
+ perform substitution if variable is not empty
324
o cut out substring of the variable value
325
# length of the variable value
326
* substitute empty string if the variable value is not empty,
327
otherwise substitute the trailing parameter
328
s regular expression search and replace. The trailing
329
options are: m = multiline, i = case insensitive,
330
g = global, t = plain text (no regexp)
331
y transpose characters from class A to class B
332
p pad variable to l = left, r = right or c = center,
334
% special function call (none implemented)
335
l lower case the variable value
336
u upper case the variable value
339
The <B>loop_limits</B> are start, step, and end values.
342
A counter variable name followed immediately by a plus (<B>+</B>) will cause
343
the counter to be incremented by one.
347
<H1><A NAME="SECTION005850000000000000000">
353
To create an ISO date:
357
DLT-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}
360
on 20 June 2003 would give <B>DLT-2003-06-20</B>
363
If you set the environment variable <B>mon</B> to
367
January|February|March|April|May|...
368
File-${mon[${Month}]}/${Day}/${Year}
371
on the first of March would give <B>File-March/1/2003 </B>
375
<DIV CLASS="navigation"><HR>
376
<!--Navigation Panel-->
377
<A NAME="tex2html2537"
378
HREF="Using_Stunne_Encryp_Commun.html">
379
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
380
<A NAME="tex2html2531"
381
HREF="Bacula_Users_Guide.html">
382
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
383
<A NAME="tex2html2525"
385
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
386
<A NAME="tex2html2533"
387
HREF="Contents.html">
388
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
389
<A NAME="tex2html2535"
390
HREF="General_Index.html">
391
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
393
<B> Next:</B> <A NAME="tex2html2538"
394
HREF="Using_Stunne_Encryp_Commun.html">Using Stunnel to Encrypt</A>
395
<B> Up:</B> <A NAME="tex2html2532"
396
HREF="Bacula_Users_Guide.html">Bacula User's Guide</A>
397
<B> Previous:</B> <A NAME="tex2html2526"
398
HREF="Thanks.html">Thanks</A>
399
<B> <A NAME="tex2html2534"
400
HREF="Contents.html">Contents</A></B>
401
<B> <A NAME="tex2html2536"
402
HREF="General_Index.html">Index</A></B> </DIV>
403
<!--End of Navigation Panel-->