File: Variable_Expansion.html

package info (click to toggle)
bacula-doc 9.6.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 241,364 kB
  • sloc: makefile: 1,869; perl: 937; sh: 218
file content (239 lines) | stat: -rw-r--r-- 13,930 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>Variable Expansion</title>
		<meta content="text/html; charset=utf-8" http-equiv="content-type" />
		<meta content="Variable Expansion" name="description" />
		<meta content="misc" name="keywords" />
		<meta content="document" name="resource-type" />
		<meta content="global" name="distribution" />
		<meta content="LaTeX2HTML v2018" name="Generator" />
		<meta content="text/css" http-equiv="Content-Style-Type" />
		<link href="../css/misc.css" rel="STYLESHEET" />
		<link href="Using_Stunnel_Encrypt_Commu.html" rel="next" />
		<link href="Contents.html" rel="previous" />
		<link href="Miscellaneous_Guide.html" rel="up" />
		<link href="Using_Stunnel_Encrypt_Commu.html" rel="next" />
	</head>
	<body>
		<div class="navigation"><a href="Using_Stunnel_Encrypt_Commu.html" name="tex2html118"> <img align="BOTTOM" alt="next" border="0" class="navigation-next" height="24" src="../images/next.png" width="37" /></a> <a href="Miscellaneous_Guide.html" name="tex2html112"> <img align="BOTTOM" alt="up" border="0" class="navigation-up" height="24" src="../images/up.png" width="26" /></a> <a href="Contents.html" name="tex2html106"> <img align="BOTTOM" alt="previous" border="0" class="navigation-prev" height="24" src="../images/prev.png" width="63" /></a> <a href="Contents.html" name="tex2html114"> <img align="BOTTOM" alt="contents" border="0" class="navigation-next" height="24" src="../images/contents.png" width="65" /></a> <a href="Index.html" name="tex2html116"> <img align="BOTTOM" alt="index" border="0" class="navigation-next" height="24" src="../images/index.png" width="43" /></a><br /><b> Next:</b> <a href="Using_Stunnel_Encrypt_Commu.html" name="tex2html119">Using Stunnel to Encrypt</a> <b> Up:</b> <a href="Miscellaneous_Guide.html" name="tex2html113">Miscellaneous Guide</a> <b> Previous:</b> <a href="Contents.html" name="tex2html107">Contents</a>  <b> <a href="Contents.html" name="tex2html115">Contents</a></b>  <b> <a href="Index.html" name="tex2html117">Index</a></b><br />
			<br />
		</div><a name="CHILD_LINKS"><strong>Subsections</strong></a><ul class="ChildLinks">
			<li><a href="Variable_Expansion.html#SECTION00210000000000000000" name="tex2html120">General Functionality</a></li>
			<li><a href="Variable_Expansion.html#SECTION00220000000000000000" name="tex2html121">Bacula Variables</a></li>
			<li><a href="Variable_Expansion.html#SECTION00230000000000000000" name="tex2html122">Full Syntax</a></li>
			<li><a href="Variable_Expansion.html#SECTION00240000000000000000" name="tex2html123">Semantics</a></li>
			<li><a href="Variable_Expansion.html#SECTION00250000000000000000" name="tex2html124">Examples</a></li>
		</ul>
		<hr />
		<h1><a name="SECTION00200000000000000000"></a> <a name="VarsChapter"></a><br /> Variable Expansion </h1><a name="76"></a> <a name="77"></a><p> Variable expansion is somewhat similar to Unix shell variable expansion. Currently (version 1.31), it is used only in format labels, but in the future, it will most likely be used in more places. </p>
		<p>
		</p>
		<h1><a name="SECTION00210000000000000000"> General Functionality</a></h1><a name="79"></a> <a name="80"></a><p> This is basically a string expansion capability that permits referencing variables, indexing arrays, conditional replacement of variables, case conversion, substring selection, regular expression matching and replacement, character class replacement, padding strings, repeated expansion in a user controlled loop, support of arithmetic expressions in the loop start, step and end conditions, and recursive expansion. </p>
		<p> When using variable expansion characters in a Volume Label Format record, the format should always be enclosed in double quotes (<b>"</b>). </p>
		<p> For example, <b>${HOME}</b> will be replaced by your home directory as defined in the environment. If you have defined the variable <b>xxx</b> to be <b>Test</b>, then the reference <b>${xxx:p/7/Y/r}</b> will right pad the contents of <b>xxx</b> to a length of seven characters filling with the character <b>Y</b> giving <b>YYYTest</b>. </p>
		<p>
		</p>
		<h1><a name="SECTION00220000000000000000"> Bacula Variables</a></h1><a name="90"></a> <a name="91"></a><p> Within Bacula, there are three main classes of variables with some minor variations within the classes. The classes are: </p>
		<p>
			<dl>
				<dt><strong>Counters</strong></dt>
				<dd><a name="93"></a> Counters are defined by the <b>Counter</b> resources in the Director's conf file. The counter can either be a temporary counter that lasts for the duration of Bacula's execution, or it can be a variable that is stored in the catalog, and thus retains its value from one Bacula execution to another. Counter variables may be incremented by postfixing a plus sign (<b>+</b> after the variable name). <p>
					</p>
				</dd>
				<dt><strong>Internal Variables</strong></dt>
				<dd><a name="96"></a> Internal variables are read-only, and may be related to the current job (i.e. Job name), or maybe special variables such as the date and time. The following variables are available: <p>
						<table width="90%">
							<tr>
								<td align="right" valign="top">Year</td>
								<td valign="top">- the full year</td>
							</tr>
							<tr>
								<td align="right" valign="top">Month</td>
								<td valign="top">- the current month 1-12</td>
							</tr>
							<tr>
								<td align="right" valign="top">Day</td>
								<td valign="top">- the day of the month 1-31</td>
							</tr>
							<tr>
								<td align="right" valign="top">Hour</td>
								<td valign="top">- the hour 0-24</td>
							</tr>
							<tr>
								<td align="right" valign="top">Minute</td>
								<td valign="top">- the current minute 0-59</td>
							</tr>
							<tr>
								<td align="right" valign="top">Second</td>
								<td valign="top">- the current second 0-59</td>
							</tr>
							<tr>
								<td align="right" valign="top">WeekDay</td>
								<td valign="top">- the current day of the week 0-6 with 0 being Sunday</td>
							</tr>
							<tr>
								<td align="right" valign="top">Job</td>
								<td valign="top">- the job name</td>
							</tr>
							<tr>
								<td align="right" valign="top">general</td>
								<td valign="top">- the Director's name</td>
							</tr>
							<tr>
								<td align="right" valign="top">Level</td>
								<td valign="top">- the Job Level</td>
							</tr>
							<tr>
								<td align="right" valign="top">Type</td>
								<td valign="top">- the Job type</td>
							</tr>
							<tr>
								<td align="right" valign="top">JobId</td>
								<td valign="top">- the JobId</td>
							</tr>
							<tr>
								<td align="right" valign="top">JobName</td>
								<td valign="top">- the unique job name composed of Job and date</td>
							</tr>
							<tr>
								<td align="right" valign="top">Storage</td>
								<td valign="top">- the Storage daemon's name</td>
							</tr>
							<tr>
								<td align="right" valign="top">Client</td>
								<td valign="top">- the Client's name</td>
							</tr>
							<tr>
								<td align="right" valign="top">NumVols</td>
								<td valign="top">- the current number of Volumes in the Pool</td>
							</tr>
							<tr>
								<td align="right" valign="top">Pool</td>
								<td valign="top">- the Pool name</td>
							</tr>
							<tr>
								<td align="right" valign="top">Catalog</td>
								<td valign="top">- the Catalog name</td>
							</tr>
							<tr>
								<td align="right" valign="top">MediaType</td>
								<td valign="top">- the Media Type </td>
							</tr>
						</table>
					</p>
					<p>
					</p>
				</dd>
				<dt><strong>Environment Variables</strong></dt>
				<dd><a name="99"></a> Environment variables are read-only, and must be defined in the environment prior to executing Bacula. Environment variables may be either scalar or an array, where the elements of the array are referenced by subscripting the variable name (e.g. <b>${Months[3]}</b>). Environment variable arrays are 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 <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 differing lengths. </dd>
			</dl>
		</p>
		<p>
		</p>
		<h1><a name="SECTION00230000000000000000"> Full Syntax</a></h1><a name="108"></a> <a name="109"></a><p> Since the syntax is quite extensive, below, you will find the pseudo BNF. The special characters have the following meaning: </p>
		<p><pre>
 ::=     definition
 ( )     grouping if the parens are not quoted
 |       separates alternatives
 '/'     literal / (or any other character)
 CAPS    a character or character sequence
 *       preceding item can be repeated zero or more times
 ?       preceding item can appear zero or one time
 +       preceding item must appear one or more times
</pre></p>
		<p> And the pseudo BNF describing the syntax is: </p>
		<p><pre>
 input       ::= ( TEXT
                 | variable
                 | INDEX_OPEN input INDEX_CLOSE (loop_limits)?
                 )*
 variable    ::= DELIM_INIT (name|expression)
 name        ::= (NAME_CHARS)+
 expression  ::= DELIM_OPEN
                 (name|variable)+
                 (INDEX_OPEN num_exp INDEX_CLOSE)?
                 (':' command)*
                 DELIM_CLOSE
 command     ::= '-' (TEXT_EXP|variable)+
               | '+' (TEXT_EXP|variable)+
               | 'o' NUMBER ('-'|',') (NUMBER)?
               | '#'
               | '*' (TEXT_EXP|variable)+
               | 's' '/' (TEXT_PATTERN)+
                     '/' (variable|TEXT_SUBST)*
                     '/' ('m'|'g'|'i'|'t')*
               | 'y' '/' (variable|TEXT_SUBST)+
                     '/' (variable|TEXT_SUBST)*
                     '/'
               | 'p' '/' NUMBER
                     '/' (variable|TEXT_SUBST)*
                     '/' ('r'|'l'|'c')
               | '%' (name|variable)+
                     ('(' (TEXT_ARGS)? ')')?
               | 'l'
               | 'u'
 num_exp     ::= operand
               | operand ('+'|'-'|'*'|'/'|'%') num_exp
 operand     ::= ('+'|'-')? NUMBER
               | INDEX_MARK
               | '(' num_exp ')'
               | variable
 loop_limits ::= DELIM_OPEN
                 (num_exp)? ',' (num_exp)? (',' (num_exp)?)?
                 DELIM_CLOSE
 NUMBER      ::= ('0'|...|'9')+
 TEXT_PATTERN::= (^('/'))+
 TEXT_SUBST  ::= (^(DELIM_INIT|'/'))+
 TEXT_ARGS   ::= (^(DELIM_INIT|')'))+
 TEXT_EXP    ::= (^(DELIM_INIT|DELIM_CLOSE|':'|'+'))+
 TEXT        ::= (^(DELIM_INIT|INDEX_OPEN|INDEX_CLOSE))+
 DELIM_INIT  ::= '$'
 DELIM_OPEN  ::= '{'
 DELIM_CLOSE ::= '}'
 INDEX_OPEN  ::= '['
 INDEX_CLOSE ::= ']'
 INDEX_MARK  ::= '#'
 NAME_CHARS  ::= 'a'|...|'z'|'A'|...|'Z'|'0'|...|'9'
</pre></p>
		<p>
		</p>
		<h1><a name="SECTION00240000000000000000"> Semantics</a></h1><a name="115"></a><p> The items listed in <b>command</b> above, which always follow a colon (<b>:</b>) have the following meanings: </p>
		<p><pre>
 -    perform substitution if variable is empty
 +    perform substitution if variable is not empty
 o    cut out substring of the variable value
 #    length of the variable value
 *    substitute empty string if the variable value is not empty,
      otherwise substitute the trailing parameter
 s    regular expression search and replace. The trailing
      options are: m = multiline, i = case insensitive,
                   g = global,    t = plain text (no regexp)
 y    transpose characters from class A to class B
 p    pad variable to l = left, r = right or c = center,
      with second value.
 %    special function call (none implemented)
 l    lower case the variable value
 u    upper case the variable value
</pre></p>
		<p> The <b>loop_limits</b> are start, step, and end values. </p>
		<p> A counter variable name followed immediately by a plus (<b>+</b>) will cause the counter to be incremented by one. </p>
		<p>
		</p>
		<h1><a name="SECTION00250000000000000000"> Examples</a></h1><a name="123"></a><p> To create an ISO date: </p>
		<p><pre>
  DLT-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}
</pre></p>
		<p> on 20 June 2003 would give <b>DLT-2003-06-20</b></p>
		<p> If you set the environment variable <b>mon</b> to </p>
		<p><pre>
   January|February|March|April|May|...
   File-${mon[${Month}]}/${Day}/${Year}
</pre></p>
		<p> on the first of March would give <b>File-March/1/2003 </b></p>
		<p>
			<div class="navigation">
				<hr /><a href="Using_Stunnel_Encrypt_Commu.html" name="tex2html118"> <img align="BOTTOM" alt="next" border="0" class="navigation-next" height="24" src="../images/next.png" width="37" /></a> <a href="Miscellaneous_Guide.html" name="tex2html112"> <img align="BOTTOM" alt="up" border="0" class="navigation-up" height="24" src="../images/up.png" width="26" /></a> <a href="Contents.html" name="tex2html106"> <img align="BOTTOM" alt="previous" border="0" class="navigation-prev" height="24" src="../images/prev.png" width="63" /></a> <a href="Contents.html" name="tex2html114"> <img align="BOTTOM" alt="contents" border="0" class="navigation-next" height="24" src="../images/contents.png" width="65" /></a> <a href="Index.html" name="tex2html116"> <img align="BOTTOM" alt="index" border="0" class="navigation-next" height="24" src="../images/index.png" width="43" /></a><br /><b> Next:</b> <a href="Using_Stunnel_Encrypt_Commu.html" name="tex2html119">Using Stunnel to Encrypt</a> <b> Up:</b> <a href="Miscellaneous_Guide.html" name="tex2html113">Miscellaneous Guide</a> <b> Previous:</b> <a href="Contents.html" name="tex2html107">Contents</a>  <b> <a href="Contents.html" name="tex2html115">Contents</a></b>  <b> <a href="Index.html" name="tex2html117">Index</a></b></div>
		</p>
	</body>
</html>