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