]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/en/concepts/newfeatures.tex
ebl Add info about copies
[bacula/docs] / docs / manuals / en / concepts / newfeatures.tex
1 %%
2 %%
3
4 \chapter{New Features}
5 \label{NewFeaturesChapter}
6 \index[general]{New Features}
7
8 This chapter presents the new features added to the development 2.5.x
9 versions to be released as Bacula version 3.0.0 near the end of 2008.
10
11 \section{Accurate Backup}
12 \index[general]{Accurate Backup}
13
14 As with most other backup programs, by default Bacula decides what files to
15 backup for Incremental and Differental backup by comparing the change
16 (st\_ctime) and modification (st\_mtime) times of the file to the time the last
17 backup completed.  If one of those two times is later than the last backup
18 time, then the file will be backed up.  This does not, however, permit tracking
19 what files have been deleted and will miss any file with an old time that may
20 have been restored to or moved onto the client filesystem.
21
22 \subsection{Accurate = \lt{}yes|no\gt{}}
23 If the {\bf Accurate = \lt{}yes|no\gt{}} directive is enabled (default no) in
24 the Job resource, the job will be run as an Accurate Job. For a {\bf Full}
25 backup, there is no difference, but for {\bf Differential} and {\bf
26   Incremental} backups, the Director will send a list of all previous files
27 backed up, and the File daemon will use that list to determine if any new files
28 have been added or or moved and if any files have been deleted. This allows
29 Bacula to make an accurate backup of your system to that point in time so that
30 if you do a restore, it will restore your system exactly.  One note of caution
31 about using Accurate backup is that it requires more resources (CPU and memory)
32 on both the Director and the Client machines to create the list of previous
33 files backed up, to send that list to the File daemon, for the File daemon to
34 keep the list (possibly very big) in memory, and for the File daemon to do
35 comparisons between every file in the FileSet and the list.
36
37
38 \section{Copy Jobs}
39 \index[general]{Copy Jobs}
40
41 A new {\bf Copy} job type 'C' has been implemented. It is similar to the
42 existing Migration feature with the exception that the Job that is copied is
43 left unchanged.  This essentially creates two identical copies of the same
44 backup. However, the copy is treated as a copy rather than a backup job, and
45 hence is not directly available for restore.  The {\bf restore} command lists
46 copy jobs and allows selection of copies by using \texttt{jobid=}
47 option. If the keyword {\bf copies} is present on the command line, Bacula will
48 display the list of all copies for selected jobs.
49
50 \begin{verbatim}
51 * restore copies
52 [...]
53 These JobIds have copies as follows:
54 +-------+------------------------------------+-----------+------------------+
55 | JobId | Job                                | CopyJobId | MediaType        |
56 +-------+------------------------------------+-----------+------------------+
57 | 2     | CopyJobSave.2009-02-17_16.31.00.11 | 7         | DiskChangerMedia |
58 +-------+------------------------------------+-----------+------------------+
59 +-------+-------+----------+----------+---------------------+------------------+
60 | JobId | Level | JobFiles | JobBytes | StartTime           | VolumeName       |
61 +-------+-------+----------+----------+---------------------+------------------+
62 | 19    | F     | 6274     | 76565018 | 2009-02-17 16:30:45 | ChangerVolume002 |
63 | 2     | I     | 1        | 5        | 2009-02-17 16:30:51 | FileVolume001    |
64 +-------+-------+----------+----------+---------------------+------------------+
65 You have selected the following JobIds: 19,2
66
67 Building directory tree for JobId(s) 19,2 ...  ++++++++++++++++++++++++++++++++++++++++++++
68 5,611 files inserted into the tree.
69 ...
70 \end{verbatim}
71
72
73 The Copy Job runs without using the File daemon by copying the data from the
74 old backup Volume to a different Volume in a different Pool. See the Migration
75 documentation for additional details. For copy Jobs there is a new selection
76 criterium named PoolUncopiedJobs which copies all jobs from a pool to an other
77 pool which were not copied before. Next to that the client, volume, job or sql
78 query are possible ways of selecting jobs which should be copied.  Selection
79 types like smallestvolume, oldestvolume, pooloccupancy and pooltime are
80 probably more suited for migration jobs only. But we could imagine some people
81 have a valid use for those kind of copy jobs too.
82
83 If bacula founds a copy when a job record is purged (deleted) from the catalog,
84 it will promote the copy as \textsl{real} backup and will make it available for
85 automatic restore. If more than one copy is available, it will promote the copy
86 with the smallest jobid.
87
88 A nice solution which can be build with the new copy jobs is what is
89 called the disk-to-disk-to-tape backup (DTDTT). A sample config could
90 look somethings like the one below:
91
92 \begin{verbatim}
93 Pool {
94   Name = FullBackupsVirtualPool
95   Pool Type = Backup
96   Purge Oldest Volume = Yes
97   Storage = vtl
98   NextPool = FullBackupsTapePool
99 }
100
101 Pool {
102   Name = FullBackupsTapePool
103   Pool Type = Backup
104   Recycle = Yes
105   AutoPrune = Yes
106   Volume Retention = 365 days
107   Storage = superloader
108 }
109
110 #
111 # Fake fileset for copy jobs
112 #
113 Fileset {
114   Name = None
115   Include {
116     Options {
117       signature = MD5
118     }
119   }
120 }
121
122 #
123 # Fake client for copy jobs
124 #
125 Client {
126   Name = None
127   Address = localhost
128   Password = "NoNe"
129   Catalog = MyCatalog
130 }
131
132 #
133 # Default template for a CopyDiskToTape Job
134 #
135 JobDefs {
136   Name = CopyDiskToTape
137   Type = Copy
138   Messages = StandardCopy
139   Client = None
140   FileSet = None
141   Selection Type = PoolUncopiedJobs
142   Maximum Concurrent Jobs = 10
143   SpoolData = No
144   Allow Duplicate Jobs = Yes
145   Allow Higher Duplicates = No
146   Cancel Queued Duplicates = No
147   Cancel Running Duplicates = No
148   Priority = 13
149 }
150
151 Schedule {
152    Name = DaySchedule7:00
153    Run = Level=Full daily at 7:00
154 }
155
156 Job {
157   Name = CopyDiskToTapeFullBackups
158   Enabled = Yes
159   Schedule = DaySchedule7:00
160   Pool = FullBackupsVirtualPool
161   JobDefs = CopyDiskToTape
162 }
163 \end{verbatim}
164
165 The example above had 2 pool which are copied using the PoolUncopiedJobs
166 selection criteria. Normal Full backups go to the Virtual pool and are copied
167 to the Tape pool the next morning.
168
169 The command \texttt{list copies [jobid=x,y,z]} lists copies for a given
170 \textbf{jobid}.
171
172 \begin{verbatim}
173 *list copies
174 +-------+------------------------------------+-----------+------------------+
175 | JobId | Job                                | CopyJobId | MediaType        |
176 +-------+------------------------------------+-----------+------------------+
177 |     9 | CopyJobSave.2008-12-20_22.26.49.05 |        11 | DiskChangerMedia |
178 +-------+------------------------------------+-----------+------------------+
179 \end{verbatim}
180
181 \section{ACL Updates}
182 The whole ACL code had been overhauled and in this version each platforms has
183 different streams for each type of acl available on such an platform. As acls
184 between platforms tend to be not that portable (most implement POSIX acls but
185 some use an other draft or a completely different format) we currently only
186 allow certain platform specific ACL streams to be decoded and restored on the
187 same platform that they were created on.  The old code allowed to restore ACL
188 cross platform but the comments already mention that not being to wise. For
189 backward compatability the new code will accept the 2 old ACL streams and
190 handle those with the platform specific handler. But for all new backups it
191 will save the ACLs using the new streams.
192
193 Currently the following platforms support ACLs:
194
195 \begin{itemize}
196  \item {\bf AIX}
197  \item {\bf Darwin/OSX}
198  \item {\bf FreeBSD}
199  \item {\bf HPUX}
200  \item {\bf IRIX}
201  \item {\bf Linux}
202  \item {\bf Tru64}
203  \item {\bf Solaris}
204 \end{itemize}
205
206 Currently we support the following ACL types (these ACL streams use a reserved
207 part of the stream numbers):
208
209 \begin{itemize}
210 \item {\bf STREAM\_ACL\_AIX\_TEXT} 1000 AIX specific string representation from
211   acl\_get
212  \item {\bf STREAM\_ACL\_DARWIN\_ACCESS\_ACL} 1001 Darwin (OSX) specific acl\_t
213    string representation from acl\_to\_text (POSIX acl)
214   \item {\bf STREAM\_ACL\_FREEBSD\_DEFAULT\_ACL} 1002 FreeBSD specific acl\_t
215     string representation from acl\_to\_text (POSIX acl) for default acls.
216   \item {\bf STREAM\_ACL\_FREEBSD\_ACCESS\_ACL} 1003 FreeBSD specific acl\_t
217     string representation from acl\_to\_text (POSIX acl) for access acls.
218   \item {\bf STREAM\_ACL\_HPUX\_ACL\_ENTRY} 1004 HPUX specific acl\_entry
219     string representation from acltostr (POSIX acl)
220   \item {\bf STREAM\_ACL\_IRIX\_DEFAULT\_ACL} 1005 IRIX specific acl\_t string
221     representation from acl\_to\_text (POSIX acl) for default acls.
222   \item {\bf STREAM\_ACL\_IRIX\_ACCESS\_ACL} 1006 IRIX specific acl\_t string
223     representation from acl\_to\_text (POSIX acl) for access acls.
224   \item {\bf STREAM\_ACL\_LINUX\_DEFAULT\_ACL} 1007 Linux specific acl\_t
225     string representation from acl\_to\_text (POSIX acl) for default acls.
226   \item {\bf STREAM\_ACL\_LINUX\_ACCESS\_ACL} 1008 Linux specific acl\_t string
227     representation from acl\_to\_text (POSIX acl) for access acls.
228   \item {\bf STREAM\_ACL\_TRU64\_DEFAULT\_ACL} 1009 Tru64 specific acl\_t
229     string representation from acl\_to\_text (POSIX acl) for default acls.
230   \item {\bf STREAM\_ACL\_TRU64\_DEFAULT\_DIR\_ACL} 1010 Tru64 specific acl\_t
231     string representation from acl\_to\_text (POSIX acl) for default acls.
232   \item {\bf STREAM\_ACL\_TRU64\_ACCESS\_ACL} 1011 Tru64 specific acl\_t string
233     representation from acl\_to\_text (POSIX acl) for access acls.
234   \item {\bf STREAM\_ACL\_SOLARIS\_ACLENT} 1012 Solaris specific aclent\_t
235     string representation from acltotext or acl\_totext (POSIX acl)
236   \item {\bf STREAM\_ACL\_SOLARIS\_ACE} 1013 Solaris specific ace\_t string
237     representation from from acl\_totext (NFSv4 or ZFS acl)
238 \end{itemize}
239
240 In future versions we might support conversion functions from one type of acl
241 into an other for types that are either the same or easily convertable. For now
242 the streams are seperate and restoring them on a platform that doesn't
243 recognize them will give you a warning.
244
245 \section{Extended Attributes}
246 Something that was on the project list for some time is now implemented for
247 platforms that support a similar kind of interface. Its the support for backup
248 and restore of so called extended attributes. As extended attributes are so
249 platform specific these attributes are saved in seperate streams for each
250 platform. Restores can only be performed on the same platform the backup was
251 done. There is support for all types of extended attributes, but restoring from
252 one type of filesystem onto an other type of filesystem on the same platform
253 may lead to supprises. As extended attributes can contain any type of data they
254 are stored as a series of so called value-pairs. This data must be seen as
255 mostly binary and is stored as such. As security labels from selinux are also
256 extended attributes this option also stores those labels and no specific code
257 is enabled for handling selinux security labels.
258
259 Currently the following platforms support extended attributes:
260 \begin{itemize}
261  \item {\bf Darwin/OSX}
262  \item {\bf FreeBSD}
263  \item {\bf Linux}
264  \item {\bf NetBSD}
265 \end{itemize}
266
267 On linux acls are also extended attributes, as such when you enable ACLs on a
268 Linux platform it will NOT save the same data twice e.g. it will save the ACLs
269 and not the same exteneded attribute.
270
271 To enable the backup of extended attributes please add the following to your
272 fileset definition.
273 \begin{verbatim}
274   FileSet {
275     Name = "MyFileSet"
276     Include {
277       Options {
278         signature = MD5
279         xattrsupport = yes
280       }
281       File = ...
282     }
283   }
284 \end{verbatim}
285
286 \section{Shared objects}
287 A default build of Bacula will now create the libraries as shared objects
288 (.so) rather than static libraries as was previously the case.  
289 The shared libraries are built using {\bf libtool} so it should be quite
290 portable.
291
292 An important advantage of using shared objects is that on a machine with the
293 Directory, File daemon, the Storage daemon, and a console, you will have only
294 one copy of the code in memory rather than four copies.  Also the total size of
295 the binary release is smaller since the library code appears only once rather
296 than once for every program that uses it; this results in significant reduction
297 in the size of the binaries particularly for the utility tools.
298  
299 In order for the system loader to find the shared objects when loading the
300 Bacula binaries, the Bacula shared objects must either be in a shared object
301 directory known to the loader (typically /usr/lib) or they must be in the
302 directory that may be specified on the {\bf ./configure} line using the {\bf
303   {-}{-}libdir} option as:
304
305 \begin{verbatim}
306   ./configure --libdir=/full-path/dir
307 \end{verbatim}
308
309 the default is /usr/lib. If {-}{-}libdir is specified, there should be
310 no need to modify your loader configuration provided that
311 the shared objects are installed in that directory (Bacula
312 does this with the make install command). The shared objects
313 that Bacula references are:
314
315 \begin{verbatim}
316 libbaccfg.so
317 libbacfind.so
318 libbacpy.so
319 libbac.so
320 \end{verbatim}
321
322 These files are symbolically linked to the real shared object file,
323 which has a version number to permit running multiple versions of
324 the libraries if desired (not normally the case).
325
326 If you have problems with libtool or you wish to use the old
327 way of building static libraries, you can do so by disabling
328 libtool on the configure command line with:
329
330 \begin{verbatim}
331   ./configure --disable-libtool
332 \end{verbatim}
333
334
335 \section{Virtual Backup (Vbackup)}
336 \index[general]{Virtual Backup}
337 \index[general]{Vbackup}
338
339 Bacula's virtual backup feature is often called Synthetic Backup or
340 Consolidation in other backup products.  It permits you to consolidate
341 the previous Full backup plus the most recent Differential backup and any
342 subsequent Incremental backups into a new Full backup. This is accomplished
343 without contacting the client by reading the previous backup data and 
344 writing it to a volume in a different pool.  
345
346 In some respects the Vbackup feature works similar to a Migration job, in
347 that Bacula normally reads the data from the pool specified in the 
348 Job resource, and writes it to the {\bf Next Pool} specified in the 
349 Job resource.  The input Storage resource and the Output Storage resource
350 must be different.
351
352 The Vbackup is enabled on a Job by Job in the Job resource by specifying
353 a level of {\bf VirtualFull}.
354
355 A typical Job resource definition might look like the following:
356
357 \begin{verbatim}
358 Job {
359   Name = "MyBackup"
360   Type = Backup
361   Client=localhost-fd
362   FileSet = "Full Set"
363   Storage = File
364   Messages = Standard
365   Pool = Default
366   SpoolData = yes
367 }
368
369 # Default pool definition
370 Pool {
371   Name = Default
372   Pool Type = Backup
373   Recycle = yes            # Automatically recycle Volumes
374   AutoPrune = yes          # Prune expired volumes
375   Volume Retention = 365d  # one year
376   NextPool = Full
377   Storage = File
378 }
379
380 Pool {
381   Name = Full
382   Pool Type = Backup
383   Recycle = yes            # Automatically recycle Volumes
384   AutoPrune = yes          # Prune expired volumes
385   Volume Retention = 365d  # one year
386   Storage = DiskChanger
387 }
388
389 # Definition of file storage device
390 Storage {
391   Name = File
392   Address = localhost
393   Password = "xxx"
394   Device = FileStorage
395   Media Type = File
396   Maximum Concurrent Jobs = 5
397 }
398
399 # Definition of DDS Virtual tape disk storage device
400 Storage {
401   Name = DiskChanger
402   Address = localhost  # N.B. Use a fully qualified name here
403   Password = "yyy"
404   Device = DiskChanger
405   Media Type = DiskChangerMedia
406   Maximum Concurrent Jobs = 4
407   Autochanger = yes
408 }
409 \end{verbatim}
410
411 Then in bconsole or via a Run schedule, you would run the job as:
412
413 \begin{verbatim}
414 run job=MyBackup level=Full
415 run job=MyBackup level=Incremental
416 run job=MyBackup level=Differential
417 run job=MyBackup level=Incremental
418 run job=MyBackup level=Incremental
419 \end{verbatim}
420
421 So providing there were changes between each of those jobs, you would end up
422 with a Full backup, a Differential, which includes the first Incremental
423 backup, then two Incremental backups.  All the above jobs would be written to
424 the {\bf Default} pool.
425
426 To consolidate those backups into a new Full backup, you would run the
427 following:
428
429 \begin{verbatim}
430 run job=MyBackup level=VirtualFull
431 \end{verbatim}
432
433 And it would produce a new Full backup without using the client, and the output
434 would be written to the {\bf Full} Pool which uses the Diskchanger Storage.
435
436 If the Virtual Full is run, and there are no prior Jobs, the Virtual Full will
437 fail with an error.
438
439 \section{Catalog format}
440 Bacula 3.0 comes with some changes on the catalog format. The upgrade operation
441 will convert an essential field of the File table that permits to handle more
442 than 4 billion objects over the time, and this operation will take TIME and
443 will DOUBLE THE SIZE of your catalog temporarily. Depending on your catalog
444 backend, you won't be able to run jobs during this period. For example, a 3
445 million files catalog will take 2mins to upgrade on a normal machine. Don't
446 forget to have a valid backup of it before executing the script.
447
448 \section{Duplicate Job Control}
449 \index[general]{Duplicate Jobs}
450 The new version of Bacula provides four new directives that
451 give additional control over what Bacula does if duplicate jobs 
452 are started.  A duplicate job in the sense we use it here means
453 a second or subsequent job with the same name starts.  This
454 happens most frequently when the first job runs longer than expected because no 
455 tapes are available.
456
457 The four directives each take as an argument a {\bf yes} or {\bf no} value and
458 are specified in the Job resource.
459
460 They are:
461
462 \subsection{Allow Duplicate Jobs = \lt{}yes|no\gt{}}
463   If this directive is enabled duplicate jobs will be run.  If
464   the directive is set to {\bf no} (default) then only one job of a given name
465   may run at one time, and the action that Bacula takes to ensure only
466   one job runs is determined by the other directives (see below).
467
468 \subsection{Allow Higher Duplicates = \lt{}yes|no\gt{}}
469   If this directive is set to {\bf yes} (default) the job with a higher
470   priority (lower priority number) will be permitted to run.  If the
471   priorities of the two jobs are the same, the outcome is determined by
472   other directives (see below).
473
474 \subsection{Cancel Queued Duplicates = \lt{}yes|no\gt{}}
475   If this directive is set to {\bf yes} (default) any job that is
476   already queued to run but not yet running will be canceled.
477
478 \subsection{Cancel Running Duplicates = \lt{}yes|no\gt{}}
479   If this directive is set to {\bf yes} any job that is already running
480   will be canceled.  The default is {\bf no}.
481
482
483 \section{TLS Authentication}
484 \index[general]{TLS Authentication}
485 In Bacula version 2.5.x and later, in addition to the normal Bacula
486 CRAM-MD5 authentication that is used to authenticate each Bacula
487 connection, you can specify that you want TLS Authentication as well,
488 which will provide more secure authentication.
489
490 This new feature uses Bacula's existing TLS code (normally used for
491 communications encryption) to do authentication.  To use it, you must
492 specify all the TLS directives normally used to enable communications
493 encryption (TLS Enable, TLS Verify Peer, TLS Certificate, ...) and
494 a new directive:
495
496 \subsection{TLS Authenticate = yes}
497 \begin{verbatim}
498 TLS Authenticate = yes
499 \end{verbatim}
500
501 in the main daemon configuration resource (Director for the Director,
502 Client for the File daemon, and Storage for the Storage daemon).
503
504 When {\bf TLS Authenticate} is enabled, after doing the CRAM-MD5
505 authentication, Bacula will do the normal TLS authentication, then TLS 
506 encryption will be turned off.
507
508 If you want to encrypt communications data, do not turn on {\bf TLS
509 Authenticate}.
510
511 \section{bextract non-portable Win32 data}
512 \index[general]{bextract handles Win32 non-portable data}
513 {\bf bextract} has been enhanced to be able to restore
514 non-portable Win32 data to any OS.  Previous versions were 
515 unable to restore non-portable Win32 data to machines that
516 did not have the Win32 BackupRead and BackupWrite API calls.
517
518 \section{State File updated at Job Termination}
519 \index[general]{State File}
520 In previous versions of Bacula, the state file, which provides a
521 summary of previous jobs run in the {\bf status} command output was
522 updated only when Bacula terminated, thus if the daemon crashed, the
523 state file might not contain all the run data.  This version of
524 the Bacula daemons updates the state file on each job termination.
525
526 \section{MaxFullInterval = \lt{}time-interval\gt{}}
527 \index[general]{MaxFullInterval}
528 The new Job resource directive {\bf Max Full Interval = \lt{}time-interval\gt{}}
529 can be used to specify the maximum time interval between {\bf Full} backup
530 jobs. When a job starts, if the time since the last Full backup is
531 greater than the specified interval, and the job would normally be an
532 {\bf Incremental} or {\bf Differential}, it will be automatically
533 upgraded to a {\bf Full} backup.
534
535 \section{MaxDiffInterval = \lt{}time-interval\gt{}}
536 \index[general]{MaxDiffInterval}
537 The new Job resource directive {\bf Max Diff Interval = \lt{}time-interval\gt{}}
538 can be used to specify the maximum time interval between {\bf Differential} backup
539 jobs. When a job starts, if the time since the last Differential backup is
540 greater than the specified interval, and the job would normally be an
541 {\bf Incremental}, it will be automatically
542 upgraded to a {\bf Differential} backup.
543
544 \section{Honor No Dump Flag = \lt{}yes|no\gt{}}
545 \index[general]{MaxDiffInterval}
546 On FreeBSD systems, each file has a {\bf no dump flag} that can be set
547 by the user, and when it is set it is an indication to backup programs
548 to not backup that particular file.  This version of Bacula contains a
549 new Options directive within a FileSet resource, which instructs Bacula to
550 obey this flag.  The new directive is:
551
552 \begin{verbatim}
553   Honor No Dump Flag = yes|no
554 \end{verbatim}
555
556 The default value is {\bf no}.
557
558
559 \section{Exclude Dirs Containing = \lt{}filename-string\gt{}}
560 \index[general]{IgnoreDir}
561 The {\bf ExcludeDirsContaining = \lt{}filename\gt{}} is a new directive that
562 can be added to the Include section of the FileSet resource.  If the specified
563 filename ({\bf filename-string}) is found on the Client in any directory to be
564 backed up, the whole directory will be ignored (not backed up).  For example:
565
566 \begin{verbatim}
567   # List of files to be backed up
568   FileSet {
569     Name = "MyFileSet"
570     Include {
571       Options {
572         signature = MD5
573       }
574       File = /home
575       Exclude Dirs Containing = .excludeme
576     }
577   }
578 \end{verbatim}
579
580 But in /home, there may be hundreds of directories of users and some
581 people want to indicate that they don't want to have certain
582 directories backed up. For example, with the above FileSet, if
583 the user or sysadmin creates a file named {\bf .excludeme} in 
584 specific directories, such as
585
586 \begin{verbatim}
587    /home/user/www/cache/.excludeme
588    /home/user/temp/.excludeme
589 \end{verbatim}
590
591 then Bacula will not backup the two directories named:
592
593 \begin{verbatim}
594    /home/user/www/cache
595    /home/user/temp
596 \end{verbatim}
597
598 NOTE: subdirectories will not be backed up.  That is, the directive
599 applies to the two directories in question and any children (be they
600 files, directories, etc).
601
602
603
604 \section{Bacula Plugins}
605 \index[general]{Plugin}
606 Support for shared object plugins has been implemented in the Linux, Unix
607 and Win32 File daemons. The API will be documented separately in
608 the Developer's Guide or in a new document.  For the moment, there is
609 a single plugin named {\bf bpipe} that allows an external program to
610 get control to backup and restore a file.
611
612 Plugins are also planned (partially implemented) in the Director and the
613 Storage daemon.  
614
615 \subsection{Plugin Directory}
616 Each daemon (DIR, FD, SD) has a new {\bf Plugin Directory} directive that may
617 be added to the daemon definition resource. The directory takes a quoted 
618 string argument, which is the name of the directory in which the daemon can
619 find the Bacula plugins. If this directive is not specified, Bacula will not
620 load any plugins. Since each plugin has a distinctive name, all the daemons
621 can share the same plugin directory. 
622
623 \subsection{Plugin Options}
624 The {\bf Plugin Options} directive takes a quoted string
625 arguement (after the equal sign) and may be specified in the
626 Job resource.  The options specified will be passed to the plugin
627 when it is run.  The value defined in the Job resource can be modified
628 by the user when he runs a Job via the {\bf bconsole} command line 
629 prompts.
630
631 Note: this directive may be specified, but it is not yet passed to
632 the plugin (i.e. not fully implemented).
633
634 \subsection{Plugin Options ACL}
635 The {\bf Plugin Options ACL} directive may be specified in the
636 Director's Console resource. It functions as all the other ACL commands
637 do by permitting users running restricted consoles to specify a 
638 {\bf Plugin Options} that overrides the one specified in the Job
639 definition. Without this directive restricted consoles may not modify
640 the Plugin Options.
641
642 \subsection{Plugin = \lt{}plugin-command-string\gt{}}
643 The {\bf Plugin} directive is specified in the Include section of
644 a FileSet resource where you put your {\bf File = xxx} directives.
645 For example:
646
647 \begin{verbatim}
648   FileSet {
649     Name = "MyFileSet"
650     Include {
651       Options {
652         signature = MD5
653       }
654       File = /home
655       Plugin = "bpipe:..."
656     }
657   }
658 \end{verbatim}
659
660 In the above example, when the File daemon is processing the directives
661 in the Include section, it will first backup all the files in {\bf /home}
662 then it will load the plugin named {\bf bpipe} (actually bpipe-dir.so) from
663 the Plugin Directory.  The syntax and semantics of the Plugin directive
664 require the first part of the string up to the colon (:) to be the name
665 of the plugin. Everything after the first colon is ignored by the File daemon but
666 is passed to the plugin. Thus the plugin writer may define the meaning of the
667 rest of the string as he wishes.
668
669 Please see the next section for information about the {\bf bpipe} Bacula
670 plugin.
671
672 \section{The bpipe Plugin}
673 The {\bf bpipe} plugin is provided in the directory src/plugins/fd/bpipe-fd.c of
674 the Bacula source distribution. When the plugin is compiled and linking into
675 the resulting dynamic shared object (DSO), it will have the name {\bf bpipe-fd.so}.
676
677 The purpose of the plugin is to provide an interface to any system program for
678 backup and restore. As specified above the {\bf bpipe} plugin is specified in
679 the Include section of your Job's FileSet resource.  The full syntax of the
680 plugin directive as interpreted by the {\bf bpipe} plugin (each plugin is free
681 to specify the sytax as it wishes) is:
682
683 \begin{verbatim}
684   Plugin = "<field1>:<field2>:<field3>:<field4>"
685 \end{verbatim}
686
687 where
688 \begin{description}
689 \item {\bf field1} is the name of the plugin with the trailing {\bf -fd.so}
690 stripped off, so in this case, we would put {\bf bpipe} in this field.
691
692 \item {\bf field2} specifies the namespace, which for {\bf bpipe} is the
693 pseudo path and filename under which the backup will be saved. This pseudo
694 path and filename will be seen by the user in the restore file tree.
695 For example, if the value is {\bf /MYSQL/regress.sql}, the data
696 backed up by the plugin will be put under that "pseudo" path and filename.
697 You must be careful to choose a naming convention that is unique to avoid
698 a conflict with a path and filename that actually exists on your system.
699
700 \item {\bf field3} for the {\bf bpipe} plugin 
701 specifies the "reader" program that is called by the plugin during
702 backup to read the data. {\bf bpipe} will call this program by doing a
703 {\bf popen} on it.
704
705 \item {\bf field4} for the {\bf bpipe} plugin
706 specifies the "writer" program that is called by the plugin during
707 restore to write the data back to the filesystem.  
708 \end{description}
709
710 Putting it all together, the full plugin directive line might look
711 like the following:
712
713 \begin{verbatim}
714 Plugin = "bpipe:/MYSQL/regress.sql:mysqldump -f 
715           --opt --databases bacula:mysql"
716 \end{verbatim}
717
718 The directive has been split into two lines, but within the {\bf bacula-dir.conf} file
719 would be written on a single line.
720
721 This causes the File daemon to call the {\bf bpipe} plugin, which will write
722 its data into the "pseudo" file {\bf /MYSQL/regress.sql} by calling the 
723 program {\bf mysqldump -f --opt --database bacula} to read the data during
724 backup. The mysqldump command outputs all the data for the database named
725 {\bf bacula}, which will be read by the plugin and stored in the backup.
726 During restore, the data that was backed up will be sent to the program
727 specified in the last field, which in this case is {\bf mysql}.  When
728 {\bf mysql} is called, it will read the data sent to it by the plugn
729 then write it back to the same database from which it came ({\bf bacula}
730 in this case).
731
732 The {\bf bpipe} plugin is a generic pipe program, that simply transmits 
733 the data from a specified program to Bacula for backup, and then from Bacula to 
734 a specified program for restore.
735
736 By using different command lines to {\bf bpipe},
737 you can backup any kind of data (ASCII or binary) depending
738 on the program called.
739
740 \section{Microsoft Exchange Server 2003/2007 Plugin}
741
742 \subsection{Concepts}
743 Although it is possible to backup Exchange using Bacula VSS the Exchange 
744 plugin adds a good deal of functionality, because while Bacula VSS
745 completes a full backup (snapshot) of Exchange, it does
746 not support Incremental or Differential backups, restoring is more
747 complicated, and a single database restore is not possible.
748
749 Microsoft Exchange organises its storage into Storage Groups with
750 Databases inside them. A default installation of Exchange will have a
751 single Storage Group called 'First Storage Group', with two Databases
752 inside it, "Mailbox Store (SERVER NAME)" and 
753 "Public Folder Store (SERVER NAME)", 
754 which hold user email and public folders respectively.
755
756 In the default configuration, Exchange logs everything that happens to
757 log files, such that if you have a backup, and all the log files since,
758 you can restore to the present time. Each Storage Group has its own set
759 of log files and operates independently of any other Storage Groups. At
760 the Storage Group level, the logging can be turned off by enabling a
761 function called "Enable circular logging". At this time the Exchange
762 plugin will not function if this option is enabled.
763
764 The plugin allows backing up of entire storage groups, and the restoring
765 of entire storage groups or individual databases. Backing up and
766 restoring at the individual mailbox or email item is not supported but
767 can be simulated by use of the "Recovery" Storage Group (see below).
768
769 \subsection{Installing}
770 The Exchange plugin requires a DLL that is shipped with Microsoft
771 Exchanger Server called {\bf esebcli2.dll}. Assuming Exchange is installed
772 correctly the Exchange plugin should find this automatically and run
773 without any additional installation.
774
775 If the DLL can not be found automatically it will need to be copied into
776 the Bacula installation
777 directory (eg C:\verb+\+Program Files\verb+\+Bacula\verb+\+bin). The Exchange API DLL is
778 named esebcli2.dll and is found in C:\verb+\+Program Files\verb+\+Exchsrvr\verb+\+bin on a
779 default Exchange installation.
780
781 \subsection{Backup up}
782 To back up an Exchange server the Fileset definition must contain at
783 least {\bf Plugin = "exchange:/@EXCHANGE/Microsoft Information Store"} for
784 the backup to work correctly. The 'exchange:' bit tells Bacula to look
785 for the exchange plugin, the '@EXCHANGE' bit makes sure all the backed
786 up files are prefixed with something that isn't going to share a name
787 with something outside the plugin, and the 'Microsoft Information Store'
788 bit is required also. It is also possible to add the name of a storage
789 group to the "Plugin =" line, eg \\
790 {\bf Plugin = "exchange:/@EXCHANGE/Microsoft Information Store/First Storage Group"} \\
791 if you want only a single storage group backed up.
792
793 Additionally, you can suffix the 'Plugin =' directive with
794 ":notrunconfull" which will tell the plugin not to truncate the Exchange
795 database at the end of a full backup.
796
797 An Incremental or Differential backup will backup only the database logs
798 for each Storage Group by inspecting the "modified date" on each
799 physical log file. Because of the way the Exchange API works, the last
800 logfile backed up on each backup will always be backed up by the next
801 Incremental or Differential backup too. This adds 5MB to each
802 Incremental or Differential backup size but otherwise does not cause any
803 problems.
804
805 By default, a normal VSS fileset containing all the drive letters will
806 also back up the Exchange databases using VSS. This will interfere with
807 the plugin and Exchange's shared ideas of when the last full backup was
808 done, and may also truncate log files incorrectly. It is important,
809 therefore, that the Exchange database files be excluded from the backup,
810 although the folders the files are in should be included, or they will
811 have to be recreated manually if a baremetal restore is done.
812
813 \begin{verbatim}
814 FileSet {
815    Include {
816       File = C:/Program Files/Exchsrvr/mdbdata
817       Plugin = "exchange:..."
818    }
819    Exclude {
820       File = C:/Program Files/Exchsrvr/mdbdata/E00.chk
821       File = C:/Program Files/Exchsrvr/mdbdata/E00.log
822       File = C:/Program Files/Exchsrvr/mdbdata/E000000F.log
823       File = C:/Program Files/Exchsrvr/mdbdata/E0000010.log
824       File = C:/Program Files/Exchsrvr/mdbdata/E0000011.log
825       File = C:/Program Files/Exchsrvr/mdbdata/E00tmp.log
826       File = C:/Program Files/Exchsrvr/mdbdata/priv1.edb
827    }
828 }
829 \end{verbatim}
830
831 The advantage of excluding the above files is that you can significantly
832 reduce the size of your backup since all the important Exchange files
833 will be properly saved by the Plugin.
834
835
836 \subsection{Restoring}
837
838 The restore operation is much the same as a normal Bacula restore, with
839 the following provisos:
840
841 \begin{itemize}
842 \item  The {\bf Where} restore option must not be specified
843 \item Each Database directory must be marked as a whole. You cannot just
844      select (say) the .edb file and not the others.
845 \item If a Storage Group is restored, the directory of the Storage Group
846      must be marked too.
847 \item  It is possible to restore only a subset of the available log files,
848      but they {\bf must} be contiguous. Exchange will fail to restore correctly
849      if a log file is missing from the sequence of log files
850 \item Each database to be restored must be dismounted and marked as "Can be
851     overwritten by restore"
852 \item If an entire Storage Group is to be restored (eg all databases and
853    logs in the Storage Group), then it is best to manually delete the
854    database files from the server (eg C:\verb+\+Program Files\verb+\+Exchsrvr\verb+\+mdbdata\verb+\+*)
855    as Exchange can get confused by stray log files lying around.
856 \end{itemize}
857
858 \subsection{Restoring to the Recovery Storage Group}
859
860 The concept of the Recovery Storage Group is well documented by
861 Microsoft 
862 \elink{http://support.microsoft.com/kb/824126}{http://support.microsoft.com/kb/824126}, 
863 but to briefly summarize...
864
865 Microsoft Exchange allows the creation of an additional Storage Group
866 called the Recovery Storage Group, which is used to restore an older
867 copy of a database (e.g. before a mailbox was deleted) into without
868 messing with the current live data. This is required as the Standard and
869 Small Business Server versions of Exchange can not ordinarily have more
870 than one Storage Group.
871
872 To create the Recovery Storage Group, drill down to the Server in
873 Exchange System Manager, right click, and select 
874 {\bf "New -> Recovery Storage Group..."}. Accept or change the file locations and click OK. On
875 the Recovery Storage Group, right click and select 
876 {\bf "Add Database to Recover..."} and select the database you will be restoring.
877
878 In Bacula, select the Database and the log files, making sure to mark
879 the Storage Group directory itself too. Once you have selected the files
880 to back up, use the RegexWhere clause to remove the prefix of
881 "/@EXCHANGE/Microsoft Information Store/\lt{}storage group name\gt{}/" and
882 replace it with "/@EXCHANGE/Microsoft Information Store/Recovery Storage Group/". 
883 Then run the restore.
884
885 \subsection{Restoring on Microsoft Server 2007}
886 Apparently the {\bf Exmerge} program no longer exists in Microsoft Server 2007, and henc
887 you use a new proceedure for recovering a single mail box.
888 This procedure is ducomented by Microsoft at:
889 \elink{http://technet.microsoft.com/en-us/library/aa997694.aspx}{http://technet.microsoft.com/en-us/library/aa997694.aspx},
890 and involves using the {\bf Restore-Mailbox} and {\bf Get-MailboxStatistics} shell commands.
891
892 \subsection{Caveats}
893 This plugin is still being developed, so you should consider it
894 currently in BETA test, and thus use in a production environment
895 should be done only after very careful testing.
896
897 The "Enable Circular Logging" option cannot be enabled or the plugin
898 will fail.
899
900 Exchange insists that a successful Full backup must have taken place if
901 an Incremental or Differential backup is desired, and the plugin will
902 fail if this is not the case. If a restore is done, Exchange will
903 require that a Full backup be done before an Incremental or Differential
904 backup is done.
905
906 The plugin will most likely not work well if another backup application
907 (eg NTBACKUP) is backing up the Exchange database, especially if the
908 other backup application is truncating the log files.
909
910 The Exchange plugin has not been tested with the {\bf Accurate} option, so
911 we recommend either carefully testing or that you avoid this option for
912 the current time.
913
914 The Exchange plugin is not called during processing the bconsole {\bf estimate} command,
915 and so anything that would be backed up by the plugin will not be added
916 to the estimate total that is displayed.
917
918
919 \section{libdbi Framework}
920 As a general guideline, Bacula has support for a few catalog database drivers
921 (MySQL, PostgreSQL, SQLite)
922 coded natively by the Bacula team.  With the libdbi implementation, which is a
923 Bacula driver that uses libdbi to access the catalog, we have an open field to
924 use many different kinds database engines following the needs of users.
925
926 The according to libdbi (http://libdbi.sourceforge.net/) project: libdbi
927 implements a database-independent abstraction layer in C, similar to the
928 DBI/DBD layer in Perl. Writing one generic set of code, programmers can
929 leverage the power of multiple databases and multiple simultaneous database
930 connections by using this framework.
931
932 Currently the libdbi driver in Bacula project only supports the same drivers
933 natively coded in Bacula.  However the libdbi project has support for many
934 others database engines. You can view the list at
935 http://libdbi-drivers.sourceforge.net/. In the future all those drivers can be
936 supported by Bacula, however, they must be tested properly by the Bacula team.
937
938 Some of benefits of using libdbi are:
939 \begin{itemize}
940 \item The possibility to use proprietary databases engines in which your
941   proprietary licenses prevent the Bacula team from developing the driver.
942  \item The possibility to use the drivers written for the libdbi project.
943  \item The possibility to use other database engines without recompiling Bacula
944    to use them.  Just change one line in bacula-dir.conf
945  \item Abstract Database access, this is, unique point to code and profiling
946    catalog database access.
947  \end{itemize}
948  
949  The following drivers have been tested:
950  \begin{itemize}
951  \item PostgreSQL, with and without batch insert
952  \item Mysql, with and without batch insert
953  \item SQLite
954  \item SQLite3
955  \end{itemize}
956
957  In the future, we will test and approve to use others databases engines
958  (proprietary or not) like DB2, Oracle, Microsoft SQL.
959
960  To compile Bacula to support libdbi we need to configure the code with the
961  --with-dbi and --with-dbi-driver=[database] ./configure options, where
962  [database] is the database engine to be used with Bacula (of course we can
963  change the driver in file bacula-dir.conf, see below).  We must configure the
964  access port of the database engine with the option --with-db-port, because the
965  libdbi framework doesn't know the default access port of each database.
966
967 The next phase is checking (or configuring) the bacula-dir.conf, example:
968 \begin{verbatim}
969 Catalog {
970   Name = MyCatalog
971   dbdriver = dbi:mysql; dbaddress = 127.0.0.1; dbport = 3306
972   dbname = regress; user = regress; password = ""
973 }
974 \end{verbatim}
975
976 The parameter {\bf dbdriver} indicates that we will use the driver dbi with a
977 mysql database.  Currently the drivers supported by Bacula are: postgresql,
978 mysql, sqlite, sqlite3; these are the names that may be added to string "dbi:".
979
980 The following limitations apply when Bacula is set to use the libdbi framework:
981  - Not tested on the Win32 platform
982  - A little performance is lost if comparing with native database driver. 
983    The reason is bound with the database driver provided by libdbi and the 
984    simple fact that one more layer of code was added.
985
986 It is important to remember, when compiling Bacula with libdbi, the
987 following packages are needed:
988  \begin{itemize}
989   \item libdbi version 1.0.0, http://libdbi.sourceforge.net/
990   \item libdbi-drivers 1.0.0, http://libdbi-drivers.sourceforge.net/
991  \end{itemize}
992  
993  You can download them and compile them on your system or install the packages
994  from your OS distribution.
995
996 \section{Console Command Additions and Enhancements}
997
998 \subsection{Display Autochanger Content}
999 \index[general]{StatusSlots}
1000
1001 The {\bf status slots storage=\lt{}storage-name\gt{}} command displays
1002 autochanger content.
1003
1004 \footnotesize
1005 \begin{verbatim}
1006  Slot |  Volume Name  |  Status  |  Media Type       |   Pool     |
1007 ------+---------------+----------+-------------------+------------|
1008     1 |         00001 |   Append |  DiskChangerMedia |    Default |
1009     2 |         00002 |   Append |  DiskChangerMedia |    Default |
1010     3*|         00003 |   Append |  DiskChangerMedia |    Scratch |
1011     4 |               |          |                   |            |
1012 \end{verbatim}
1013 \normalsize
1014
1015 If you an asterisk ({\bf *}) appears after the slot number, you must run an
1016 {\bf update slots} command to synchronize autochanger content with your
1017 catalog.
1018
1019 \subsection{list joblog job=xxx or jobid=nnn}
1020 A new list command has been added that allows you to list the contents
1021 of the Job Log stored in the catalog for either a Job Name (fully qualified)
1022 or for a particular JobId.  The {\bf llist} command will include a line with
1023 the time and date of the entry.
1024
1025 Note for the catalog to have Job Log entries, you must have a directive 
1026 such as:
1027
1028 \begin{verbatim}
1029   catalog = all
1030 \end{verbatim}
1031
1032 In your Director's {\bf Messages} resource.
1033
1034
1035 \section{Miscellaneous}
1036 \index[general]{Misc New Features}
1037
1038 \subsection{Allow Mixed Priority = \lt{}yes|no\gt{}}
1039    This directive is only implemented in version 2.5 and later.  When
1040    set to {\bf yes} (default {\bf no}), this job may run even if lower
1041    priority jobs are already running.  This means a high priority job
1042    will not have to wait for other jobs to finish before starting.
1043    The scheduler will only mix priorities when all running jobs have
1044    this set to true.
1045
1046    Note that only higher priority jobs will start early.  Suppose the
1047    director will allow two concurrent jobs, and that two jobs with
1048    priority 10 are running, with two more in the queue.  If a job with
1049    priority 5 is added to the queue, it will be run as soon as one of
1050    the running jobs finishes.  However, new priority 10 jobs will not
1051    be run until the priority 5 job has finished.
1052
1053 \subsection{Bootstrap File Directive -- FileRegex}
1054   {\bf FileRegex} is a new command that can be added to the bootstrap
1055   (.bsr) file.  The value is a regular expression.  When specified, only
1056   matching filenames will be restored.
1057
1058   During a restore, if all File records are pruned from the catalog
1059   for a Job, normally Bacula can restore only all files saved. That
1060   is there is no way using the catalog to select individual files.
1061   With this new command, Bacula will ask if you want to specify a Regex
1062   expression for extracting only a part of the full backup.
1063
1064 \subsection{Bootstrap File Optimization Changes}
1065 In order to permit proper seeking on disk files, we have extended the bootstrap
1066 file format to include a {\bf VolStartAddr} and {\bf VolEndAddr} records. Each
1067 takes a 64 bit unsigned integer range (i.e. nnn-mmm) which defines the start
1068 address range and end address range respectively.  These two directives replace
1069 the {\bf VolStartFile}, {\bf VolEndFile}, {\bf VolStartBlock} and {\bf
1070   VolEndBlock} directives.  Bootstrap files containing the old directives will
1071 still work, but will not properly take advantage of proper disk seeking, and
1072 may read completely to the end of a disk volume during a restore.  With the new
1073 format (automatically generated by the new Director), restores will seek
1074 properly and stop reading the volume when all the files have been restored.
1075
1076 \subsection{Solaris ZFS/NFSv4 ACLs}
1077 This is an upgrade of the previous Solaris ACL backup code
1078 to the new library format, which will backup both the old
1079 POSIX(UFS) ACLs as well as the ZFS ACLs.
1080
1081 The new code can also restore POSIX(UFS) ACLs to a ZFS filesystem
1082 (it will translate the POSIX(UFS)) ACL into a ZFS/NFSv4 one) it can also
1083 be used to transfer from UFS to ZFS filesystems.
1084
1085
1086 \subsection{Virtual Tape Emulation}
1087 We now have a Virtual Tape emulator that allows us to run though 99.9\% of
1088 the tape code but actually reading and writing to a disk file. Used with the
1089 \textbf{disk-changer} script, you can now emulate an autochanger with 10 drives
1090 and 700 slots. This feature is most useful in testing.  It is enabled
1091 by using {\bf Device Type = vtape} in the Storage daemon's Device
1092 directive. This feature is only implemented on Linux machines.
1093
1094 \subsection{Bat Enhancements}
1095 Bat (the Bacula Administration Tool) GUI program has been significantly
1096 enhanced and stabilized. In particular, there are new table based status 
1097 commands; it can now be easily localized using Qt4 Linguist.
1098
1099 The Bat communications protocol has been significantly enhanced to improve
1100 GUI handling.
1101
1102 \subsection{RunScript Enhancements}
1103 The {\bf RunScript} resource has been enhanced to permit multiple
1104 commands per RunScript.  Simply specify multiple {\bf Command} directives
1105 in your RunScript.
1106
1107 \begin{verbatim}
1108 Job {
1109   Name = aJob
1110   RunScript {
1111     Command = "/bin/echo test"
1112     Command = "/bin/echo an other test"
1113     Command = "/bin/echo 3 commands in the same runscript"
1114     RunsWhen = Before
1115   }
1116  ...
1117 }
1118 \end{verbatim}
1119
1120 A new Client RunScript {\bf RunsWhen} keyword of {\bf AfterVSS} has been
1121 implemented, which runs the command after the Volume Shadow Copy has been made.
1122
1123 Console commands can be specified within a RunScript by using:
1124 {\bf Console = \lt{}command\gt{}}, however, this command has not been 
1125 carefully tested and debugged and is known to easily crash the Director.
1126 We would appreciate feedback.  Due to the recursive nature of this command, we
1127 may remove it before the final release.
1128
1129 \subsection{Status Enhancements}
1130 The bconsole {\bf status dir} output has been enhanced to indicate
1131 Storage daemon job spooling and despooling activity.
1132
1133 \subsection{Connect Timeout}
1134 The default connect timeout to the File
1135 daemon has been set to 3 minutes. Previously it was 30 minutes.
1136
1137 \subsection{ftruncate for NFS Volumes}
1138 If you write to a Volume mounted by NFS (say on a local file server),
1139 in previous Bacula versions, when the Volume was recycled, it was not
1140 properly truncated because NFS does not implement ftruncate (file 
1141 truncate). This is now corrected in the new version because we have
1142 written code (actually a kind user) that deletes and recreates the Volume,
1143 thus accomplishing the same thing as a truncate.
1144
1145 \subsection{Support for Ubuntu}
1146 The new version of Bacula now recognizes the Ubuntu (and Kubuntu)
1147 version of Linux, and thus now provides correct autostart routines.
1148 Since Ubuntu officially supports Bacula, you can also obtain any
1149 recent release of Bacula from the Ubuntu repositories.
1150
1151 \subsection{Recycle Pool = \lt{}pool-name\gt{}}
1152 The new \textbf{RecyclePool} directive defines to which pool the Volume will
1153 be placed (moved) when it is recycled. Without this directive, a Volume will
1154 remain in the same pool when it is recycled. With this directive, it can be
1155 moved automatically to any existing pool during a recycle. This directive is
1156 probably most useful when defined in the Scratch pool, so that volumes will
1157 be recycled back into the Scratch pool.
1158
1159 \subsection{FD Version}
1160 The File daemon to Director protocol now includes a version 
1161 number, which although there is no visible change for users, 
1162 will help us in future versions automatically determine
1163 if a File daemon is not compatible.
1164
1165 \subsection{Max Run Sched Time = \lt{}time-period-in-seconds\gt{}}
1166 The time specifies the maximum allowed time that a job may run, counted from
1167 when the job was scheduled. This can be useful to prevent jobs from running
1168 during working hours. We can see it like \texttt{Max Start Delay + Max Run
1169   Time}.
1170
1171 \subsection{Max Wait Time = \lt{}time-period-in-seconds\gt{}}
1172
1173 Previous \textbf{MaxWaitTime} directives aren't working as expected, instead
1174 of checking the maximum allowed time that a job may block for a resource,
1175 those directives worked like \textbf{MaxRunTime}. Some users are reporting to
1176 use \textbf{Incr/Diff/Full Max Wait Time} to control the maximum run time of
1177 their job depending on the level. Now, they have to use
1178 \textbf{Incr/Diff/Full Max Run Time}.  \textbf{Incr/Diff/Full Max Wait Time}
1179 directives are now deprecated.
1180
1181 \subsection{Incremental|Differential Max Wait Time = \lt{}time-period-in-seconds\gt{}} 
1182 Theses directives have been deprecated in favor of
1183 \texttt{Incremental|Differential Max Run Time}.
1184
1185 \subsection{Max Run Time directives}
1186 Using \textbf{Full/Diff/Incr Max Run Time}, it's now possible to specify the
1187 maximum allowed time that a job can run depending on the level.
1188
1189 \addcontentsline{lof}{figure}{Job time control directives}
1190 \includegraphics{\idir different_time.eps}
1191
1192 \subsection{Statistics Enhancements}
1193 If you (or probably your boss) want to have statistics on your backups to
1194 provide some \textit{Service Level Agreement} indicators, you could use a few
1195 SQL queries on the Job table to report how many:
1196
1197 \begin{itemize}
1198 \item jobs have run
1199 \item jobs have been successful
1200 \item files have been backed up
1201 \item ...
1202 \end{itemize}
1203
1204 However, these statistics are accurate only if your job retention is greater
1205 than your statistics period. Ie, if jobs are purged from the catalog, you won't
1206 be able to use them. 
1207
1208 Now, you can use the \textbf{update stats [days=num]} console command to fill
1209 the JobHistory table with new Job records. If you want to be sure to take in
1210 account only \textbf{good jobs}, ie if one of your important job has failed but
1211 you have fixed the problem and restarted it on time, you probably want to
1212 delete the first \textit{bad} job record and keep only the successful one. For
1213 that simply let your staff do the job, and update JobHistory table after two or
1214 three days depending on your organization using the \textbf{[days=num]} option.
1215
1216 These statistics records aren't used for restoring, but mainly for
1217 capacity planning, billings, etc.
1218
1219 The Bweb interface provides a statistics module that can use this feature. You
1220 can also use tools like Talend or extract information by yourself.
1221
1222 The {\textbf Statistics Retention = \lt{}time\gt{}} director directive defines
1223 the length of time that Bacula will keep statistics job records in the Catalog
1224 database after the Job End time. (In \texttt{JobHistory} table) When this time
1225 period expires, and if user runs \texttt{prune stats} command, Bacula will
1226 prune (remove) Job records that are older than the specified period.
1227
1228 You can use the following Job resource in your nightly \textbf{BackupCatalog}
1229 job to maintain statistics.
1230 \begin{verbatim}
1231 Job {
1232   Name = BackupCatalog
1233   ...
1234   RunScript {
1235     Console = "update stats days=3"
1236     Console = "prune stats yes"
1237     RunsWhen = After
1238     RunsOnClient = no
1239   }
1240 }
1241 \end{verbatim}
1242
1243 \subsection{ScratchPool = \lt{}pool-resource-name\gt{}}
1244 This directive permits to specify a dedicate \textsl{Scratch} pool for the
1245 current pool. This is useful when using multiple storage sharing the same
1246 mediatype or when you want to dedicate volumes to a particular set of pool.
1247
1248 \subsection{Enhance attributes despooling}
1249 If the storage daemon and the director are on the same machine, the spool file
1250 that contains attributes is read directly by the director instead of being
1251 transmitted by the network. That should reduce load and speedup insertion.
1252
1253 \subsection{SpoolSize = \lt{}size-specification-in-bytes\gt{}}
1254 A new job directive permits to specify the spool size per job. This is used
1255 in advanced job tunning. {\bf SpoolSize={\it bytes}}
1256
1257 \subsection{MaxConsoleConnections = \lt{}number\gt{}}
1258 A new director directive permits to specify the maximum number of Console
1259 Connections that could run concurrently. The default is set to 20, but you may
1260 set it to a larger number.
1261
1262 \section{Building Bacula Plugins}
1263 There is currently one sample program {\bf example-plugin-fd.c} and
1264 one working plugin {\bf bpipe-fd.c} that can be found in the Bacula
1265 {\bf src/plugins/fd} directory.  Both are built with the following:
1266
1267 \begin{verbatim}
1268  cd <bacula-source>
1269  ./configure <your-options>
1270  make
1271  ...
1272  cd src/plugins/fd
1273  make
1274  make test
1275 \end{verbatim}
1276
1277 After building Bacula and changing into the src/plugins/fd directory,
1278 the {\bf make} command will build the {\bf bpipe-fd.so} plugin, which 
1279 is a very useful and working program.
1280
1281 The {\bf make test} command will build the {\bf example-plugin-fd.so}
1282 plugin and a binary named {\bf main}, which is build from the source
1283 code located in {\bf src/filed/fd\_plugins.c}. 
1284
1285 If you execute {\bf ./main}, it will load and run the example-plugin-fd
1286 plugin simulating a small number of the calling sequences that Bacula uses
1287 in calling a real plugin.  This allows you to do initial testing of 
1288 your plugin prior to trying it with Bacula.
1289
1290 You can get a good idea of how to write your own plugin by first 
1291 studying the example-plugin-fd, and actually running it.  Then
1292 it can also be instructive to read the bpipe-fd.c code as it is 
1293 a real plugin, which is still rather simple and small.
1294
1295 When actually writing your own plugin, you may use the example-plugin-fd.c
1296 code as a template for your code.
1297
1298
1299 %%
1300 %%
1301
1302 \chapter{Bacula FD Plugin API}
1303 To write a Bacula plugin, you create a dynamic shared object program (or dll on
1304 Win32) with a particular name and two exported entry points, place it in the
1305 {\bf Plugins Directory}, which is defined in the {\bf bacula-fd.conf} file in
1306 the {\bf Client} resource, and when the FD starts, it will load all the plugins
1307 that end with {\bf -fd.so} (or {\bf -fd.dll} on Win32) found in that directory.
1308
1309 \section{Normal vs Command Plugins}
1310 In general, there are two ways that plugins are called. The first way, is when
1311 a particular event is detected in Bacula, it will transfer control to each
1312 plugin that is loaded in turn informing the plugin of the event.  This is very
1313 similar to how a {\bf RunScript} works, and the events are very similar.  Once
1314 the plugin gets control, it can interact with Bacula by getting and setting
1315 Bacula variables.  In this way, it behaves much like a RunScript.  Currently
1316 very few Bacula variables are defined, but they will be implemented as the need
1317 arrises, and it is very extensible.
1318
1319 We plan to have plugins register to receive events that they normally would
1320 not receive, such as an event for each file examined for backup or restore.
1321 This feature is not yet implemented.
1322
1323 The second type of plugin, which is more useful and fully implemented in the
1324 current version is what we call a command plugin.  As with all plugins, it gets
1325 notified of important events as noted above (details described below), but in
1326 addition, this kind of plugin can accept a command line, which is a:
1327
1328 \begin{verbatim}
1329    Plugin = <command-string>
1330 \end{verbatim}
1331
1332 directive that is placed in the Include section of a FileSet and is very
1333 similar to the "File = " directive.  When this Plugin directive is encountered
1334 by Bacula during backup, it passes the "command" part of the Plugin directive
1335 only to the plugin that is explicitly named in the first field of that command
1336 string.  This allows that plugin to backup any file or files on the system that
1337 it wants. It can even create "virtual files" in the catalog that contain data
1338 to be restored but do not necessarily correspond to actual files on the
1339 filesystem.
1340
1341 The important features of the command plugin entry points are:
1342 \begin{itemize}
1343  \item It is triggered by a "Plugin =" directive in the FileSet
1344  \item Only a single plugin is called that is named on the "Plugin =" directive.
1345  \item The full command string after the "Plugin =" is passed to the plugin
1346     so that it can be told what to backup/restore.
1347 \end{itemize}
1348
1349
1350 \section{Loading Plugins}
1351 Once the File daemon loads the plugins, it asks the OS for the
1352 two entry points (loadPlugin and unloadPlugin) then calls the
1353 {\bf loadPlugin} entry point (see below).
1354
1355 Bacula passes information to the plugin through this call and it gets
1356 back information that it needs to use the plugin.  Later, Bacula
1357  will call particular functions that are defined by the
1358 {\bf loadPlugin} interface.  
1359
1360 When Bacula is finished with the plugin 
1361 (when Bacula is going to exit), it will call the {\bf unloadPlugin}
1362 entry point.
1363
1364 The two entry points are:
1365
1366 \begin{verbatim}
1367 bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
1368
1369 and
1370
1371 bRC unloadPlugin()
1372 \end{verbatim}
1373
1374 both these external entry points to the shared object are defined as C entry
1375 points to avoid name mangling complications with C++.  However, the shared
1376 object can actually be written in any language (preferrably C or C++) providing
1377 that it follows C language calling conventions.
1378
1379 The definitions for {\bf bRC} and the arguments are {\bf
1380 src/filed/fd-plugins.h} and so this header file needs to be included in
1381 your plugin.  It along with {\bf src/lib/plugins.h} define basically the whole
1382 plugin interface.  Within this header file, it includes the following
1383 files:
1384
1385 \begin{verbatim}
1386 #include <sys/types.h>
1387 #include "config.h"
1388 #include "bc_types.h"
1389 #include "lib/plugins.h"
1390 #include <sys/stat.h>
1391 \end{verbatim}
1392
1393 Aside from the {\bf bc\_types.h} and {\bf confit.h} headers, the plugin
1394 definition uses the minimum code from Bacula.  The bc\_types.h file is required
1395 to ensure that the data type defintions in arguments correspond to the Bacula
1396 core code.
1397
1398 The return codes are defined as:
1399 \begin{verbatim}
1400 typedef enum {
1401   bRC_OK    = 0,                         /* OK */
1402   bRC_Stop  = 1,                         /* Stop calling other plugins */
1403   bRC_Error = 2,                         /* Some kind of error */
1404   bRC_More  = 3,                         /* More files to backup */
1405 } bRC;
1406 \end{verbatim}
1407
1408
1409 At a future point in time, we hope to make the Bacula libbac.a into a
1410 shared object so that the plugin can use much more of Bacula's
1411 infrastructure, but for this first cut, we have tried to minimize the
1412 dependence on Bacula.
1413
1414 \section{loadPlugin}
1415 As previously mentioned, the {\bf loadPlugin} entry point in the plugin
1416 is called immediately after Bacula loads the plugin when the File daemon
1417 itself is first starting.  This entry point is only called once during the
1418 execution of the File daemon.  In calling the
1419 plugin, the first two arguments are information from Bacula that
1420 is passed to the plugin, and the last two arguments are information
1421 about the plugin that the plugin must return to Bacula.  The call is:
1422
1423 \begin{verbatim}
1424 bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
1425 \end{verbatim}
1426
1427 and the arguments are:
1428
1429 \begin{description}
1430 \item [lbinfo]
1431 This is information about Bacula in general. Currently, the only value
1432 defined in the bInfo structure is the version, which is the Bacula plugin 
1433 interface version, currently defined as 1.  The {\bf size} is set to the
1434 byte size of the structure. The exact definition of the bInfo structure
1435 as of this writing is: 
1436
1437 \begin{verbatim}
1438 typedef struct s_baculaInfo {
1439    uint32_t size;
1440    uint32_t version;
1441 } bInfo;
1442 \end{verbatim}
1443
1444 \item [lbfuncs]
1445 The bFuncs structure defines the callback entry points within Bacula
1446 that the plugin can use register events, get Bacula values, set
1447 Bacula values, and send messages to the Job output or debug output.
1448
1449 The exact definition as of this writing is:
1450 \begin{verbatim}
1451 typedef struct s_baculaFuncs {
1452    uint32_t size;
1453    uint32_t version;
1454    bRC (*registerBaculaEvents)(bpContext *ctx, ...);
1455    bRC (*getBaculaValue)(bpContext *ctx, bVariable var, void *value);
1456    bRC (*setBaculaValue)(bpContext *ctx, bVariable var, void *value);
1457    bRC (*JobMessage)(bpContext *ctx, const char *file, int line,
1458        int type, time_t mtime, const char *fmt, ...);
1459    bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
1460        int level, const char *fmt, ...);
1461    void *(*baculaMalloc)(bpContext *ctx, const char *file, int line,
1462        size_t size);
1463    void (*baculaFree)(bpContext *ctx, const char *file, int line, void *mem);
1464 } bFuncs;
1465 \end{verbatim}
1466
1467 We will discuss these entry points and how to use them a bit later when
1468 describing the plugin code.
1469
1470
1471 \item [pInfo]
1472 When the loadPlugin entry point is called, the plugin must initialize
1473 an information structure about the plugin and return a pointer to
1474 this structure to Bacula.
1475
1476 The exact definition as of this writing is:
1477
1478 \begin{verbatim}
1479 typedef struct s_pluginInfo {
1480    uint32_t size;
1481    uint32_t version;
1482    const char *plugin_magic;
1483    const char *plugin_license;
1484    const char *plugin_author;
1485    const char *plugin_date;
1486    const char *plugin_version;
1487    const char *plugin_description;
1488 } pInfo;
1489 \end{verbatim}
1490
1491 Where:
1492  \begin{description}
1493  \item [version] is the current Bacula defined plugin interface version, currently
1494    set to 1. If the interface version differs from the current version of 
1495    Bacula, the plugin will not be run (not yet implemented).
1496  \item [plugin\_magic] is a pointer to the text string "*FDPluginData*", a
1497    sort of sanity check.  If this value is not specified, the plugin
1498    will not be run (not yet implemented).
1499  \item [plugin\_license] is a pointer to a text string that describes the
1500    plugin license. Bacula will only accept compatible licenses (not yet
1501    implemented).
1502  \item [plugin\_author] is a pointer to the text name of the author of the program.
1503    This string can be anything but is generally the author's name.
1504  \item [plugin\_date] is the pointer text string containing the date of the plugin.
1505    This string can be anything but is generally some human readable form of 
1506    the date.
1507  \item [plugin\_version] is a pointer to a text string containing the version of
1508    the plugin.  The contents are determined by the plugin writer.
1509  \item [plugin\_description] is a pointer to a string describing what the
1510    plugin does. The contents are determined by the plugin writer.
1511  \end{description}
1512
1513 The pInfo structure must be defined in static memory because Bacula does not
1514 copy it and may refer to the values at any time while the plugin is
1515 loaded. All values must be supplied or the plugin will not run (not yet
1516 implemented).  All text strings must be either ASCII or UTF-8 strings that
1517 are terminated with a zero byte.
1518
1519 \item [pFuncs]
1520 When the loadPlugin entry point is called, the plugin must initialize
1521 an entry point structure about the plugin and return a pointer to
1522 this structure to Bacula. This structure contains pointer to each
1523 of the entry points that the plugin must provide for Bacula. When
1524 Bacula is actually running the plugin, it will call the defined
1525 entry points at particular times.  All entry points must be defined.
1526
1527 The pFuncs structure must be defined in static memory because Bacula does not
1528 copy it and may refer to the values at any time while the plugin is
1529 loaded.
1530
1531 The exact definition as of this writing is:
1532
1533 \begin{verbatim}
1534 typedef struct s_pluginFuncs {
1535    uint32_t size;
1536    uint32_t version;
1537    bRC (*newPlugin)(bpContext *ctx);
1538    bRC (*freePlugin)(bpContext *ctx);
1539    bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value);
1540    bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value);
1541    bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value);
1542    bRC (*startBackupFile)(bpContext *ctx, struct save_pkt *sp);
1543    bRC (*endBackupFile)(bpContext *ctx);
1544    bRC (*startRestoreFile)(bpContext *ctx, const char *cmd);
1545    bRC (*endRestoreFile)(bpContext *ctx);
1546    bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io);
1547    bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp);
1548    bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp);
1549 } pFuncs;
1550 \end{verbatim}
1551
1552 The details of the entry points will be presented in
1553 separate sections below. 
1554
1555 Where:
1556  \begin{description}
1557  \item [size] is the byte size of the structure.
1558  \item [version] is the plugin interface version currently set to 1.
1559  \end{description}
1560
1561 Sample code for loadPlugin:
1562 \begin{verbatim}
1563   bfuncs = lbfuncs;                  /* set Bacula funct pointers */
1564   binfo  = lbinfo;
1565   *pinfo  = &pluginInfo;             /* return pointer to our info */
1566   *pfuncs = &pluginFuncs;            /* return pointer to our functions */
1567
1568    return bRC_OK;
1569 \end{verbatim}
1570
1571 where pluginInfo and pluginFuncs are statically defined structures. 
1572 See bpipe-fd.c for details.
1573
1574
1575
1576 \end{description}
1577
1578 \section{Plugin Entry Points}
1579 This section will describe each of the entry points (subroutines) within
1580 the plugin that the plugin must provide for Bacula, when they are called
1581 and their arguments. As noted above, pointers to these subroutines are
1582 passed back to Bacula in the pFuncs structure when Bacula calls the 
1583 loadPlugin() externally defined entry point.
1584
1585 \subsection{newPlugin(bpContext *ctx)}
1586   This is the entry point that Bacula will call
1587   when a new "instance" of the plugin is created. This typically
1588   happens at the beginning of a Job.  If 10 Jobs are running
1589   simultaneously, there will be at least 10 instances of the
1590   plugin.
1591
1592   The bpContext structure will be passed to the plugin, and
1593   during this call, if the plugin needs to have its private
1594   working storage that is associated with the particular
1595   instance of the plugin, it should create it from the heap
1596   (malloc the memory) and store a pointer to
1597   its private working storage in the {\bf pContext} variable.
1598   Note: since Bacula is a multi-threaded program, you must not
1599   keep any variable data in your plugin unless it is truely meant
1600   to apply globally to the whole plugin.  In addition, you must
1601   be aware that except the first and last call to the plugin
1602   (loadPlugin and unloadPlugin) all the other calls will be 
1603   made by threads that correspond to a Bacula job.  The 
1604   bpContext that will be passed for each thread will remain the
1605   same throughout the Job thus you can keep your privat Job specific
1606   data in it ({\bf bContext}).
1607
1608 \begin{verbatim}
1609 typedef struct s_bpContext {
1610   void *pContext;   /* Plugin private context */
1611   void *bContext;   /* Bacula private context */
1612 } bpContext;
1613
1614 \end{verbatim}
1615    
1616   This context pointer will be passed as the first argument to all
1617   the entry points that Bacula calls within the plugin.  Needless
1618   to say, the plugin should not change the bContext variable, which
1619   is Bacula's private context pointer for this instance (Job) of this
1620   plugin.
1621
1622 \subsection{freePlugin(bpContext *ctx)}
1623 This entry point is called when the
1624 this instance of the plugin is no longer needed (the Job is
1625 ending), and the plugin should release all memory it may
1626 have allocated for this particular instance (Job) i.e. the pContext.  
1627 This is not the final termination
1628 of the plugin signaled by a call to {\bf unloadPlugin}. 
1629 Any other instances (Job) will
1630 continue to run, and the entry point {\bf newPlugin} may be called
1631 again if other jobs start.
1632
1633 \subsection{getPluginValue(bpContext *ctx, pVariable var, void *value)} 
1634 Bacula will call this entry point to get
1635 a value from the plugin.  This entry point is currently not called.
1636
1637 \subsection{setPluginValue(bpContext *ctx, pVariable var, void *value)}
1638 Bacula will call this entry point to set
1639 a value in the plugin.  This entry point is currently not called.
1640  
1641 \subsection{handlePluginEvent(bpContext *ctx, bEvent *event, void *value)}
1642 This entry point is called when Bacula
1643 encounters certain events (discussed below). This is, in fact, the 
1644 main way that most plugins get control when a Job runs and how
1645 they know what is happening in the job. It can be likened to the
1646 {\bf RunScript} feature that calls external programs and scripts,
1647 and is very similar to the Bacula Python interface.
1648 When the plugin is called, Bacula passes it the pointer to an event
1649 structure (bEvent), which currently has one item, the eventType:
1650
1651 \begin{verbatim}
1652 typedef struct s_bEvent {
1653    uint32_t eventType;
1654 } bEvent;
1655 \end{verbatim}
1656
1657   which defines what event has been triggered, and for each event,
1658   Bacula will pass a pointer to a value associated with that event.
1659   If no value is associated with a particular event, Bacula will 
1660   pass a NULL pointer, so the plugin must be careful to always check
1661   value pointer prior to dereferencing it.
1662   
1663   The current list of events are:
1664
1665 \begin{verbatim}
1666 typedef enum {
1667   bEventJobStart        = 1,
1668   bEventJobEnd          = 2,
1669   bEventStartBackupJob  = 3,
1670   bEventEndBackupJob    = 4,
1671   bEventStartRestoreJob = 5,
1672   bEventEndRestoreJob   = 6,
1673   bEventStartVerifyJob  = 7,
1674   bEventEndVerifyJob    = 8,
1675   bEventBackupCommand   = 9,
1676   bEventRestoreCommand  = 10,
1677   bEventLevel           = 11,
1678   bEventSince           = 12,
1679 } bEventType;
1680
1681 \end{verbatim}
1682  
1683 Most of the above are self-explanatory.
1684
1685 \begin{description}
1686  \item [bEventJobStart] is called whenever a Job starts. The value
1687    passed is a pointer to a string that contains: "Jobid=nnn 
1688    Job=job-name". Where nnn will be replaced by the JobId and job-name
1689    will be replaced by the Job name. The variable is temporary so if you
1690    need the values, you must copy them.
1691
1692  \item [bEventJobEnd] is called whenever a Job ends. No value is passed.
1693
1694  \item [bEventStartBackupJob] is called when a Backup Job begins. No value
1695    is passed.
1696
1697  \item [bEventEndBackupJob] is called when a Backup Job ends. No value is 
1698    passed.
1699
1700  \item [bEventStartRestoreJob] is called when a Restore Job starts. No value
1701    is passed.
1702
1703  \item [bEventEndRestoreJob] is called when a Restore Job ends. No value is
1704    passed.
1705
1706  \item [bEventStartVerifyJob] is called when a Verify Job starts. No value
1707    is passed.
1708
1709  \item [bEventEndVerifyJob] is called when a Verify Job ends. No value
1710    is passed.
1711
1712  \item [bEventBackupCommand] is called prior to the bEventStartBackupJob and
1713    the plugin is passed the command string (everything after the equal sign
1714    in "Plugin =" as the value.
1715
1716    Note, if you intend to backup a file, this is an important first point to
1717    write code that copies the command string passed into your pContext area
1718    so that you will know that a backup is being performed and you will know
1719    the full contents of the "Plugin =" command (i.e. what to backup and
1720    what virtual filename the user wants to call it.
1721
1722  \item [bEventRestoreCommand] is called prior to the bEventStartRestoreJob and
1723    the plugin is passed the command string (everything after the equal sign
1724    in "Plugin =" as the value.
1725
1726    See the notes above concerning backup and the command string. This is the
1727    point at which Bacula passes you the original command string that was
1728    specified during the backup, so you will want to save it in your pContext
1729    area for later use when Bacula calls the plugin again.
1730
1731  \item [bEventLevel] is called when the level is set for a new Job. The value
1732    is a 32 bit integer stored in the void*, which represents the Job Level code.
1733
1734  \item [bEventSince] is called when the since time is set for a new Job. The 
1735    value is a time\_t time at which the last job was run.
1736 \end{description}
1737
1738 During each of the above calls, the plugin receives either no specific value or
1739 only one value, which in some cases may not be sufficient.  However, knowing
1740 the context of the event, the plugin can call back to the Bacula entry points
1741 it was passed during the {\bf loadPlugin} call and get to a number of Bacula
1742 variables.  (at the current time few Bacula variables are implemented, but it
1743 easily extended at a future time and as needs require).
1744
1745 \subsection{startBackupFile(bpContext *ctx, struct save\_pkt *sp)}
1746 This entry point is called only if your plugin is a command plugin, and 
1747 it is called when Bacula encounters the "Plugin = " directive in
1748 the Include section of the FileSet.
1749 Called when beginning the backup of a file. Here Bacula provides you
1750 with a pointer to the {\bf save\_pkt} structure and you must fill in 
1751 this packet with the "attribute" data of the file.
1752
1753 \begin{verbatim}
1754 struct save_pkt {
1755    int32_t pkt_size;                  /* size of this packet */
1756    char *fname;                       /* Full path and filename */
1757    char *link;                        /* Link name if any */
1758    struct stat statp;                 /* System stat() packet for file */
1759    int32_t type;                      /* FT_xx for this file */
1760    uint32_t flags;                    /* Bacula internal flags */
1761    bool portable;                     /* set if data format is portable */
1762    char *cmd;                         /* command */
1763    int32_t pkt_end;                   /* end packet sentinel */
1764 };
1765 \end{verbatim}
1766
1767 The second argument is a pointer to the {\bf save\_pkt} structure for the file
1768 to be backed up.  The plugin is responsible for filling in all the fields 
1769 of the {\bf save\_pkt}. If you are backing up
1770 a real file, then generally, the statp structure can be filled in by doing
1771 a {\bf stat} system call on the file.  
1772
1773 If you are backing up a database or
1774 something that is more complex, you might want to create a virtual file.
1775 That is a file that does not actually exist on the filesystem, but represents 
1776 say an object that you are backing up.  In that case, you need to ensure
1777 that the {\bf fname} string that you pass back is unique so that it
1778 does not conflict with a real file on the system, and you need to 
1779 artifically create values in the statp packet.
1780
1781 Example programs such as {\bf bpipe-fd.c} show how to set these fields.  You
1782 must take care not to store pointers the stack in the pointer fields such as
1783 fname and link, because when you return from your function, your stack entries
1784 will be destroyed. The solution in that case is to malloc() and return the
1785 pointer to it. In order to not have memory leaks, you should store a pointer to
1786 all memory allocated in your pContext structure so that in subsequent calls or
1787 at termination, you can release it back to the system.
1788
1789 Once the backup has begun, Bacula will call your plugin at the {\bf pluginIO}
1790 entry point to "read" the data to be backed up.  Please see the {\bf bpipe-fd.c}
1791 plugin for how to do I/O.
1792
1793 Example of filling in the save\_pkt as used in bpipe-fd.c:
1794
1795 \begin{verbatim}
1796    struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext;
1797    time_t now = time(NULL);
1798    sp->fname = p_ctx->fname;
1799    sp->statp.st_mode = 0700 | S_IFREG;
1800    sp->statp.st_ctime = now;
1801    sp->statp.st_mtime = now;
1802    sp->statp.st_atime = now;
1803    sp->statp.st_size = -1;
1804    sp->statp.st_blksize = 4096;
1805    sp->statp.st_blocks = 1;
1806    p_ctx->backup = true;
1807    return bRC_OK; 
1808 \end{verbatim}
1809
1810 Note: the filename to be created has already been created from the 
1811 command string previously sent to the plugin and is in the plugin 
1812 context (p\_ctx->fname) and is a malloc()ed string.  This example
1813 creates a regular file (S\_IFREG), with various fields being created.
1814
1815 In general, the sequence of commands issued from Bacula to the plugin
1816 to do a backup while processing the "Plugin = " directive are:
1817
1818 \begin{enumerate}
1819  \item generate a bEventBackupCommand event to the specified plugin
1820        and pass it the command string.
1821  \item make a startPluginBackup call to the plugin, which
1822        fills in the data needed in save\_pkt to save as the file
1823        attributes and to put on the Volume and in the catalog.
1824  \item call Bacula's internal save\_file() subroutine to save the specified
1825        file.  The plugin will then be called at pluginIO() to "open"
1826        the file, and then to read the file data.
1827        Note, if you are dealing with a virtual file, the "open" operation
1828        is something the plugin does internally and it doesn't necessarily
1829        mean opening a file on the filesystem.  For example in the case of
1830        the bpipe-fd.c program, it initiates a pipe to the requested program.
1831        Finally when the plugin signals to Bacula that all the data was read,
1832        Bacula will call the plugin with the "close" pluginIO() function.
1833 \end{enumerate}
1834
1835
1836 \subsection{endBackupFile(bpContext *ctx)}
1837 Called at the end of backing up a file for a command plugin.  If the plugin's
1838 work is done, it should return bRC\_OK.  If the plugin wishes to create another
1839 file and back it up, then it must return bRC\_More (not yet implemented).  This
1840 is probably a good time to release any malloc()ed memory you used to pass back
1841 filenames.
1842
1843 \subsection{startRestoreFile(bpContext *ctx, const char *cmd)}
1844 Called when the first record is read from the Volume that was 
1845 previously written by the command plugin.
1846
1847 \subsection{createFile(bpContext *ctx, struct restore\_pkt *rp)}
1848 Called for a command plugin to create a file during a Restore job before 
1849 restoring the data. 
1850 This entry point is called before any I/O is done on the file.  After
1851 this call, Bacula will call pluginIO() to open the file for write.
1852
1853 The data in the 
1854 restore\_pkt is passed to the plugin and is based on the data that was
1855 originally given by the plugin during the backup and the current user
1856 restore settings (e.g. where, RegexWhere, replace).  This allows the
1857 plugin to first create a file (if necessary) so that the data can
1858 be transmitted to it.  The next call to the plugin will be a
1859 pluginIO command with a request to open the file write-only.
1860
1861 This call must return one of the following values:
1862
1863 \begin{verbatim}
1864  enum {
1865    CF_SKIP = 1,       /* skip file (not newer or something) */
1866    CF_ERROR,          /* error creating file */
1867    CF_EXTRACT,        /* file created, data to extract */
1868    CF_CREATED         /* file created, no data to extract */
1869 };
1870 \end{verbatim}
1871
1872 in the restore\_pkt value {\bf create\_status}.  For a normal file,
1873 unless there is an error, you must return {\bf CF\_EXTRACT}.
1874
1875 \begin{verbatim}
1876  
1877 struct restore_pkt {
1878    int32_t pkt_size;                  /* size of this packet */
1879    int32_t stream;                    /* attribute stream id */
1880    int32_t data_stream;               /* id of data stream to follow */
1881    int32_t type;                      /* file type FT */
1882    int32_t file_index;                /* file index */
1883    int32_t LinkFI;                    /* file index to data if hard link */
1884    uid_t uid;                         /* userid */
1885    struct stat statp;                 /* decoded stat packet */
1886    const char *attrEx;                /* extended attributes if any */
1887    const char *ofname;                /* output filename */
1888    const char *olname;                /* output link name */
1889    const char *where;                 /* where */
1890    const char *RegexWhere;            /* regex where */
1891    int replace;                       /* replace flag */
1892    int create_status;                 /* status from createFile() */
1893    int32_t pkt_end;                   /* end packet sentinel */
1894
1895 };
1896 \end{verbatim}
1897
1898 Typical code to create a regular file would be the following:
1899
1900 \begin{verbatim}
1901    struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext;
1902    time_t now = time(NULL);
1903    sp->fname = p_ctx->fname;   /* set the full path/filename I want to create */
1904    sp->type = FT_REG;
1905    sp->statp.st_mode = 0700 | S_IFREG;
1906    sp->statp.st_ctime = now;
1907    sp->statp.st_mtime = now;
1908    sp->statp.st_atime = now;
1909    sp->statp.st_size = -1;
1910    sp->statp.st_blksize = 4096;
1911    sp->statp.st_blocks = 1;
1912    return bRC_OK;
1913 \end{verbatim}
1914
1915 This will create a virtual file.  If you are creating a file that actually 
1916 exists, you will most likely want to fill the statp packet using the
1917 stat() system call.
1918
1919 Creating a directory is similar, but requires a few extra steps:
1920
1921 \begin{verbatim}
1922    struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext;
1923    time_t now = time(NULL);
1924    sp->fname = p_ctx->fname;   /* set the full path I want to create */
1925    sp->link = xxx; where xxx is p_ctx->fname with a trailing forward slash
1926    sp->type = FT_DIREND
1927    sp->statp.st_mode = 0700 | S_IFDIR;
1928    sp->statp.st_ctime = now;
1929    sp->statp.st_mtime = now;
1930    sp->statp.st_atime = now;
1931    sp->statp.st_size = -1;
1932    sp->statp.st_blksize = 4096;
1933    sp->statp.st_blocks = 1;
1934    return bRC_OK;
1935 \end{verbatim}
1936
1937 The link field must be set with the full cononical path name, which always 
1938 ends with a forward slash.  If you do not terminate it with a forward slash,
1939 you will surely have problems later.
1940
1941 As with the example that creates a file, if you are backing up a real
1942 directory, you will want to do an stat() on the directory.  
1943
1944 Note, if you want the directory permissions and times to be correctly
1945 restored, you must create the directory {\bf after} all the file directories
1946 have been sent to Bacula. That allows the restore process to restore all the
1947 files in a directory using default directory options, then at the end, restore
1948 the directory permissions.  If you do it the other way around, each time you
1949 restore a file, the OS will modify the time values for the directory entry.
1950
1951 \subsection{setFileAttributes(bpContext *ctx, struct restore\_pkt *rp)}
1952 This is call not yet implemented.  Called for a command plugin.
1953
1954 See the definition of {\bf restre\_pkt} in the above section.
1955
1956 \subsection{endRestoreFile(bpContext *ctx)}
1957 Called when a command plugin is done restoring a file.
1958
1959 \subsection{pluginIO(bpContext *ctx, struct io\_pkt *io)}
1960 Called to do the input (backup) or output (restore) of data from or to a file
1961 for a command plugin. These routines simulate the Unix read(), write(), open(),
1962 close(), and lseek() I/O calls, and the arguments are passed in the packet and
1963 the return values are also placed in the packet.  In addition for Win32 systems
1964 the plugin must return two additional values (described below).
1965
1966 \begin{verbatim}
1967  enum {
1968    IO_OPEN = 1,
1969    IO_READ = 2,
1970    IO_WRITE = 3,
1971    IO_CLOSE = 4,
1972    IO_SEEK = 5
1973 };
1974
1975 struct io_pkt {
1976    int32_t pkt_size;                  /* Size of this packet */
1977    int32_t func;                      /* Function code */
1978    int32_t count;                     /* read/write count */
1979    mode_t mode;                       /* permissions for created files */
1980    int32_t flags;                     /* Open flags */
1981    char *buf;                         /* read/write buffer */
1982    const char *fname;                 /* open filename */
1983    int32_t status;                    /* return status */
1984    int32_t io_errno;                  /* errno code */
1985    int32_t lerror;                    /* Win32 error code */
1986    int32_t whence;                    /* lseek argument */
1987    boffset_t offset;                  /* lseek argument */
1988    bool win32;                        /* Win32 GetLastError returned */
1989    int32_t pkt_end;                   /* end packet sentinel */
1990 };
1991 \end{verbatim}
1992
1993 The particular Unix function being simulated is indicated by the {\bf func},
1994 which will have one of the IO\_OPEN, IO\_READ, ... codes listed above.  The
1995 status code that would be returned from a Unix call is returned in {\bf status}
1996 for IO\_OPEN, IO\_CLOSE, IO\_READ, and IO\_WRITE. The return value for IO\_SEEK
1997 is returned in {\bf offset} which in general is a 64 bit value.
1998
1999 When there is an error on Unix systems, you must always set io\_error, and
2000 on a Win32 system, you must always set win32, and the returned value from
2001 the OS call GetLastError() in lerror.
2002
2003 For all except IO\_SEEK, {\bf status} is the return result.  In general it is
2004 a positive integer unless there is an error in which case it is -1.
2005
2006 The following describes each call and what you get and what you
2007 should return:
2008
2009 \begin{description}
2010  \item [IO\_OPEN]
2011    You will be passed fname, mode, and flags.
2012    You must set on return: status, and if there is a Unix error
2013    io\_errno must be set to the errno value, and if there is a 
2014    Win32 error win32 and lerror. 
2015
2016  \item [IO\_READ]
2017   You will be passed: count, and buf (buffer of size count).
2018   You must set on return: status to the number of bytes 
2019   read into the buffer (buf) or -1 on an error, 
2020   and if there is a Unix error
2021   io\_errno must be set to the errno value, and if there is a
2022   Win32 error, win32 and lerror must be set.
2023
2024  \item [IO\_WRITE]
2025   You will be passed: count, and buf (buffer of size count).
2026   You must set on return: status to the number of bytes 
2027   written from the buffer (buf) or -1 on an error, 
2028   and if there is a Unix error
2029   io\_errno must be set to the errno value, and if there is a
2030   Win32 error, win32 and lerror must be set.
2031
2032  \item [IO\_CLOSE]
2033   Nothing will be passed to you.  On return you must set 
2034   status to 0 on success and -1 on failure.  If there is a Unix error
2035   io\_errno must be set to the errno value, and if there is a
2036   Win32 error, win32 and lerror must be set.
2037
2038  \item [IO\_LSEEK]
2039   You will be passed: offset, and whence. offset is a 64 bit value
2040   and is the position to seek to relative to whence.  whence is one
2041   of the following SEEK\_SET, SEEK\_CUR, or SEEK\_END indicating to
2042   either to seek to an absolute possition, relative to the current 
2043   position or relative to the end of the file.
2044   You must pass back in offset the absolute location to which you 
2045   seeked. If there is an error, offset should be set to -1.
2046   If there is a Unix error
2047   io\_errno must be set to the errno value, and if there is a
2048   Win32 error, win32 and lerror must be set.
2049
2050   Note: Bacula will call IO\_SEEK only when writing a sparse file.
2051   
2052 \end{description}
2053
2054 \section{Bacula Plugin Entrypoints}
2055 When Bacula calls one of your plugin entrypoints, you can call back to
2056 the entrypoints in Bacula that were supplied during the xxx plugin call
2057 to get or set information within Bacula.
2058
2059 \subsection{bRC registerBaculaEvents(bpContext *ctx, ...)}
2060 This Bacula entrypoint will allow you to register to receive events
2061 that are not autmatically passed to your plugin by default. This 
2062 entrypoint currently is unimplemented.
2063
2064 \subsection{bRC getBaculaValue(bpContext *ctx, bVariable var, void *value)}
2065 Calling this entrypoint, you can obtain specific values that are available
2066 in Bacula.
2067
2068 \subsection{bRC setBaculaValue(bpContext *ctx, bVariable var, void *value)}
2069 Calling this entrypoint allows you to set particular values in
2070 Bacula.
2071
2072 \subsection{bRC JobMessage(bpContext *ctx, const char *file, int line,
2073        int type, time\_t mtime, const char *fmt, ...)}
2074 This call permits you to put a message in the Job Report.
2075
2076
2077 \subsection{bRC DebugMessage(bpContext *ctx, const char *file, int line,
2078        int level, const char *fmt, ...)}
2079 This call permits you to print a debug message.
2080
2081
2082 \subsection{void baculaMalloc(bpContext *ctx, const char *file, int line,
2083        size\_t size)}
2084 This call permits you to obtain memory from Bacula's memory allocator.
2085
2086
2087 \subsection{void baculaFree(bpContext *ctx, const char *file, int line, void *mem)}
2088 This call permits you to free memory obtained from Bacula's memory allocator.