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