]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/en/problems/tips.tex
Commit two patches from Philippe to cleanup the manuals
[bacula/docs] / docs / manuals / en / problems / tips.tex
1 %%
2 %%
3
4 \chapter{Tips and Suggestions}
5 \label{TipsChapter}
6 \index[general]{Tips and Suggestions }
7 \index[general]{Suggestions!Tips and }
8 \label{examples}
9 \index[general]{Examples }
10
11 There are a number of example scripts for various things that can be found in
12 the {\bf example} subdirectory and its subdirectories of the Bacula source
13 distribution. 
14
15 For additional tips, please see the \elink{Bacula
16 wiki}{http://wiki.bacula.org}.
17
18 \section{Upgrading Bacula Versions}
19 \label{upgrading}
20 \index[general]{Upgrading Bacula Versions }
21 \index[general]{Versions!Upgrading Bacula }
22 \index[general]{Upgrading}
23
24 The first thing to do before upgrading from one version to another is to
25 ensure that you don't overwrite or delete your production (current) version
26 of Bacula until you have tested that the new version works.
27
28 If you have installed Bacula into a single directory, this is simple: simply
29 make a copy of your Bacula directory. 
30
31 If you have done a more typical Unix installation where the binaries are
32 placed in one directory and the configuration files are placed in another,
33 then the simplest way is to configure your new Bacula to go into a single
34 file. Alternatively, make copies of all your binaries and especially your 
35 conf files.
36
37 Whatever your situation may be (one of the two just described), you should
38 probably start with the {\bf defaultconf} script that can be found in the {\bf
39 examples} subdirectory. Copy this script to the main Bacula directory, modify
40 it as necessary (there should not need to be many modifications), configure
41 Bacula, build it, install it, then stop your production Bacula, copy all the
42 {\bf *.conf} files from your production Bacula directory to the test Bacula
43 directory, start the test version, and run a few test backups. If all seems
44 good, then you can proceed to install the new Bacula in place of or possibly
45 over the old Bacula. 
46
47 When installing a new Bacula you need not worry about losing the changes you
48 made to your configuration files as the installation process will not
49 overwrite them providing that you do not do a {\bf make uninstall}.
50
51 If the new version of Bacula requires an upgrade to the database,
52 you can upgrade it with the script {\bf update\_bacula\_tables}, which
53 will be installed in your scripts directory (default {\bf /etc/bacula}),
54 or alternatively, you can find it in the  
55 {\bf \lt{}bacula-source\gt{}/src/cats} directory.
56
57 \section{Getting Notified of Job Completion}
58 \label{notification}
59 \index[general]{Getting Notified of Job Completion }
60 \index[general]{Completion!Getting Notified of Job }
61
62 One of the first things you should do is to ensure that you are being properly
63 notified of the status of each Job run by Bacula, or at a minimum of each Job
64 that terminates with an error. 
65
66 Until you are completely comfortable with {\bf Bacula}, we recommend that you
67 send an email to yourself for each Job that is run. This is most easily
68 accomplished by adding an email notification address in the {\bf Messages}
69 resource of your Director's configuration file. An email is automatically
70 configured in the default configuration files, but you must ensure that the
71 default {\bf root} address is replaced by your email address. 
72
73 For additional examples of how to configure a Bacula, please take a look at the
74 {\bf .conf} files found in the {\bf examples} sub-directory. We recommend the
75 following configuration (where you change the paths and email address to
76 correspond to your setup). Note, the {\bf mailcommand} and {\bf
77 operatorcommand} should be on a single line. They were split here for
78 presentation: 
79
80 \footnotesize
81 \begin{verbatim}
82 Messages {
83   Name = Standard
84   mailcommand = "/home/bacula/bin/bsmtp -h localhost
85                 -f \"\(Bacula\) %r\"
86                 -s \"Bacula: %t %e of %c %l\" %r"
87   operatorcommand = "/home/bacula/bin/bsmtp -h localhost
88                 -f \"\(Bacula\) %r\"
89                 -s \"Bacula: Intervention needed for %j\" %r"
90   Mail = your-email-address = all, !skipped, !terminate
91   append = "/home/bacula/bin/log" = all, !skipped, !terminate
92   operator = your-email-address = mount
93   console = all, !skipped, !saved
94 }
95 \end{verbatim}
96 \normalsize
97
98 You will need to ensure that the {\bf /home/bacula/bin} path on the {\bf
99 mailcommand} and the {\bf operatorcommand} lines point to your {\bf Bacula}
100 binary directory where the {\bf bsmtp} program will be installed. You will
101 also want to ensure that the {\bf your-email-address} is replaced by your
102 email address, and finally, you will also need to ensure that the {\bf
103 /home/bacula/bin/log} points to the file where you want to log all messages. 
104
105 With the above Messages resource, you will be notified by email of every Job
106 that ran, all the output will be appended to the {\bf log} file you specify,
107 all output will be directed to the console program, and all mount messages
108 will be emailed to you. Note, some messages will be sent to multiple
109 destinations. 
110
111 The form of the mailcommand is a bit complicated, but it allows you to
112 distinguish whether the Job terminated in error or terminated normally. Please
113 see the 
114 \borgxrlink{Mail}{mailcommand}{main}{command} in the \mainman{} for the
115  details of the substitution characters used above.
116
117 Once you are totally comfortable with Bacula as I am, or if you have a large
118 number of nightly Jobs as I do (eight), you will probably want to change the
119 {\bf Mail} command to {\bf Mail On Error} which will generate an email message
120 only if the Job terminates in error. If the Job terminates normally, no email
121 message will be sent, but the output will still be appended to the log file as
122 well as sent to the Console program. 
123
124 \section{Getting Email Notification to Work}
125 \label{email}
126 \index[general]{Work!Getting Email Notification to }
127 \index[general]{Getting Email Notification to Work }
128
129 The section above describes how to get email notification of job status.
130 Occasionally, however, users have problems receiving any email at all. In that
131 case, the things to check are the following: 
132
133 \begin{itemize}
134 \item Ensure that you have a valid email address specified on your  {\bf Mail}
135    record in the Director's Messages resource. The email  address should be fully
136    qualified. Simply using {\bf root} generally  will not work, rather you should
137 use {\bf root@localhost} or better  yet your full domain.  
138 \item Ensure that you do not have a {\bf Mail} record in the Storage  daemon's
139    or File daemon's configuration files. The only record  you should have is {\bf
140    director}:  
141
142 \footnotesize
143 \begin{verbatim}
144       director = director-name = all
145       
146 \end{verbatim}
147 \normalsize
148
149 \item If all else fails, try replacing the {\bf mailcommand} with 
150
151    \footnotesize
152 \begin{verbatim}
153 mailcommand = "mail -s test your@domain.com"
154 \end{verbatim}
155 \normalsize
156
157 \item Once the above is working, assuming you want to use {\bf bsmtp},  submit
158    the desired bsmtp command by hand and ensure that the email  is delivered,
159    then put that command into {\bf Bacula}. Small  differences in things such as
160 the parenthesis around the word  Bacula can make a big difference to some
161 bsmtp programs.  For example, you might start simply by using: 
162
163 \footnotesize
164 \begin{verbatim}
165 mailcommand = "/home/bacula/bin/bsmtp -f \"root@localhost\" %r"
166 \end{verbatim}
167 \normalsize
168
169 \end{itemize}
170
171 \section{Getting Notified that Bacula is Running}
172 \label{JobNotification}
173 \index[general]{Running!Getting Notified that Bacula is }
174 \index[general]{Getting Notified that Bacula is Running }
175
176 If like me, you have setup Bacula so that email is sent only when a Job has
177 errors, as described in the previous section of this chapter, inevitably, one
178 day, something will go wrong and {\bf Bacula} can stall. This could be because
179 Bacula crashes, which is vary rare, or more likely the network has caused {\bf
180 Bacula} to {\bf hang} for some unknown reason. 
181
182 To avoid this, you can use the {\bf RunAfterJob} command in the Job resource
183 to schedule a Job nightly, or weekly that simply emails you a message saying
184 that Bacula is still running. For example, I have setup the following Job in
185 my Director's configuration file: 
186
187 \footnotesize
188 \begin{verbatim}
189 Schedule {
190   Name = "Watchdog"
191   Run = Level=Full sun-sat at 6:05
192 }
193 Job {
194   Name = "Watchdog"
195   Type = Admin
196   Client=Watchdog
197   FileSet="Verify Set"
198   Messages = Standard
199   Storage = DLTDrive
200   Pool = Default
201   Schedule = "Watchdog"
202   RunAfterJob = "/home/kern/bacula/bin/watchdog %c %d"
203 }
204 Client {
205   Name = Watchdog
206   Address = rufus
207   FDPort = 9102
208   Catalog = Verify
209   Password = ""
210   File Retention = 1day
211   Job Retention = 1 month
212   AutoPrune = yes
213 }
214 \end{verbatim}
215 \normalsize
216
217 Where I established a schedule to run the Job nightly. The Job itself is type
218 {\bf Admin} which means that it doesn't actually do anything, and I've defined
219 a FileSet, Pool, Storage, and Client, all of which are not really used (and
220 probably don't need to be specified). The key aspect of this Job is the
221 command: 
222
223 \footnotesize
224 \begin{verbatim}
225   RunAfterJob = "/home/kern/bacula/bin/watchdog %c %d"
226 \end{verbatim}
227 \normalsize
228
229 which runs my "watchdog" script. As an example, I have added the Job codes
230 \%c and \%d which will cause the Client name and the Director's name to be
231 passed to the script. For example, if the Client's name is {\bf Watchdog} and
232 the Director's name is {\bf main-dir} then referencing \$1 in the script would
233 get {\bf Watchdog} and referencing \$2 would get {\bf main-dir}. In this case,
234 having the script know the Client and Director's name is not really useful,
235 but in other situations it may be. 
236
237 You can put anything in the watchdog script. In my case, I like to monitor the
238 size of my catalog to be sure that {\bf Bacula} is really pruning it. The
239 following is my watchdog script: 
240
241 \footnotesize
242 \begin{verbatim}
243 #!/bin/sh
244 cd /home/kern/mysql/var/bacula
245 du . * |
246 /home/kern/bacula/bin/bsmtp  \
247    -f "\(Bacula\) abuse@whitehouse.com" -h mail.yyyy.com \
248    -s "Bacula running" abuse@whitehouse.com
249 \end{verbatim}
250 \normalsize
251
252 If you just wish to send yourself a message, you can do it with: 
253
254 \footnotesize
255 \begin{verbatim}
256 #!/bin/sh
257 cd /home/kern/mysql/var/bacula
258 /home/kern/bacula/bin/bsmtp  \
259    -f "\(Bacula\) abuse@whitehouse.com" -h mail.yyyy.com \
260    -s "Bacula running" abuse@whitehouse.com <<END-OF-DATA
261 Bacula is still running!!!
262 END-OF-DATA
263 \end{verbatim}
264 \normalsize
265
266 \section{Maintaining a Valid Bootstrap File}
267 \label{bootstrap}
268 \index[general]{Maintaining a Valid Bootstrap File }
269 \index[general]{File!Maintaining a Valid Bootstrap }
270
271 By using a \borgxrlinkdocument{WriteBootstrap}{writebootstrap}{main}{chapter} record in each of your
272 Director's Job resources (\mainman{}), you can constantly maintain a
273 \borgxrlinkdocument{bootstrap}{BootstrapChapter}{main}{chapter} file that will enable you to
274 recover the state of your system as of the last backup without having the
275 Bacula catalog. This permits you to more easily recover from a disaster that
276 destroys your Bacula catalog. 
277
278 When a Job resource has a {\bf WriteBootstrap} record, Bacula will maintain
279 the designated file (normally on another system but mounted by NFS) with up to
280 date information necessary to restore your system. For example, in my
281 Director's configuration file, I have the following record: 
282
283 \footnotesize
284 \begin{verbatim}
285  Write Bootstrap = "/mnt/deuter/files/backup/client-name.bsr"
286 \end{verbatim}
287 \normalsize
288
289 where I replace {\bf client-name} by the actual name of the client that is
290 being backed up. Thus, Bacula automatically maintains one file for each of my
291 clients. The necessary bootstrap information is appended to this file during
292 each {\bf Incremental} backup, and the file is totally rewritten during each
293 {\bf Full} backup. 
294
295 Note, one disadvantage of writing to an NFS mounted volume as I do is
296 that if the other machine goes down, the OS will wait forever on the fopen()
297 call that Bacula makes. As a consequence, Bacula will completely stall until
298 the machine exporting the NFS mounts comes back up. A possible solution to this
299 problem was provided by Andrew Hilborne, and consists of using the {\bf soft}
300 option instead of the {\bf hard} option when mounting the NFS volume, which is
301 typically done in {\bf /etc/fstab}/. The NFS documentation explains these
302 options in detail. However, I found that with the {\bf soft} option 
303 NFS disconnected frequently causing even more problems.
304
305 If you are starting off in the middle of a cycle (i.e. with Incremental
306 backups) rather than at the beginning (with a Full backup), the {\bf
307 bootstrap} file will not be immediately valid as it must always have the
308 information from a Full backup as the first record. If you wish to synchronize
309 your bootstrap file immediately, you can do so by running a {\bf restore}
310 command for the client and selecting a full restore, but when the restore
311 command asks for confirmation to run the restore Job, you simply reply no,
312 then copy the bootstrap file that was written to the location specified on the
313 {\bf Write Bootstrap} record. The restore bootstrap file can be found in {\bf
314 restore.bsr} in the working directory that you defined. In the example given
315 below for the client {\bf rufus}, my input is shown in bold. Note, the JobId
316 output has been partially truncated to fit on the page here: 
317
318 \footnotesize
319 \begin{verbatim}
320 (in the Console program)
321 *restore
322 First you select one or more JobIds that contain files
323 to be restored. You will then be presented several methods
324 of specifying the JobIds. Then you will be allowed to
325 select which files from those JobIds are to be restored.
326 To select the JobIds, you have the following choices:
327      1: List last 20 Jobs run
328      2: List Jobs where a given File is saved
329      3: Enter list of JobIds to select
330      4: Enter SQL list command
331      5: Select the most recent backup for a client
332      6: Cancel
333 Select item:  (1-6): 5
334 The defined Client resources are:
335      1: Minimatou
336      2: Rufus
337      3: Timmy
338 Select Client (File daemon) resource (1-3): 2
339 The defined FileSet resources are:
340      1: Other Files
341 Item 1 selected automatically.
342 +-------+------+-------+---------+---------+------+-------+------------+
343 | JobId | Levl | Files | StrtTim | VolName | File | SesId | VolSesTime |
344 +-------+------+-------+---------+---------+------+-------+------------+
345 | 2     | F    | 84    |  ...    | test1   | 0    | 1     | 1035645259 |
346 +-------+------+-------+---------+---------+------+-------+------------+
347 You have selected the following JobId: 2
348 Building directory tree for JobId 2 ...
349 The defined Storage resources are:
350      1: File
351 Item 1 selected automatically.
352 You are now entering file selection mode where you add and
353 remove files to be restored. All files are initially added.
354 Enter "done" to leave this mode.
355 cwd is: /
356 $ done
357 84 files selected to restore.
358 Run Restore job
359 JobName:    kernsrestore
360 Bootstrap:  /home/kern/bacula/working/restore.bsr
361 Where:      /tmp/bacula-restores
362 FileSet:    Other Files
363 Client:     Rufus
364 Storage:    File
365 JobId:      *None*
366 OK to run? (yes/mod/no): no
367 quit
368 (in a shell window)
369 cp ../working/restore.bsr /mnt/deuter/files/backup/rufus.bsr
370 \end{verbatim}
371 \normalsize
372
373 \section{Rejected Volumes After a Crash}
374 \label{RejectedVolumes}
375 \index[general]{Crash!Rejected Volumes After a }
376 \index[general]{Rejected Volumes After a Crash }
377
378 Bacula keeps a count of the number of files on each Volume in its Catalog
379 database so that before appending to a tape, it can verify that the number of
380 files are correct, and thus prevent overwriting valid data. If the Director or
381 the Storage daemon crashes before the job has completed, the tape will contain
382 one more file than is noted in the Catalog, and the next time you attempt to
383 use the same Volume, Bacula will reject it due to a mismatch between the
384 physical tape (Volume) and the catalog. 
385
386 The easiest solution to this problem is to label a new tape and start fresh.
387 If you wish to continue appending to the current tape, you can do so by using
388 the {\bf update} command in the console program to change the {\bf Volume
389 Files} entry in the catalog. A typical sequence of events would go like the
390 following: 
391
392 \footnotesize
393 \begin{verbatim}
394 - Bacula crashes
395 - You restart Bacula
396 \end{verbatim}
397 \normalsize
398
399 Bacula then prints: 
400
401 \footnotesize
402 \begin{verbatim}
403 17-Jan-2003 16:45 rufus-dir: Start Backup JobId 13,
404                   Job=kernsave.2003-01-17_16.45.46
405 17-Jan-2003 16:45 rufus-sd: Volume test01 previously written,
406                   moving to end of data.
407 17-Jan-2003 16:46 rufus-sd: kernsave.2003-01-17_16.45.46 Error:
408                   I cannot write on this volume because:
409                   The number of files mismatch! Volume=11 Catalog=10
410 17-Jan-2003 16:46 rufus-sd: Job kernsave.2003-01-17_16.45.46 waiting.
411                    Cannot find any appendable volumes.
412 Please use the "label"  command to create a new Volume for:
413     Storage:      SDT-10000
414     Media type:   DDS-4
415     Pool:         Default
416 \end{verbatim}
417 \normalsize
418
419 (note, lines wrapped for presentation)
420 The key here is the line that reads: 
421
422 \footnotesize
423 \begin{verbatim}
424   The number of files mismatch! Volume=11 Catalog=10
425 \end{verbatim}
426 \normalsize
427
428 It says that Bacula found eleven files on the volume, but that the catalog
429 says there should be ten. When you see this, you can be reasonably sure that
430 the SD was interrupted while writing before it had a chance to update the
431 catalog. As a consequence, you can just modify the catalog count to eleven,
432 and even if the catalog contains references to files saved in file 11,
433 everything will be OK and nothing will be lost. Note that if the SD had
434 written several file marks to the volume, the difference between the Volume
435 count and the Catalog count could be larger than one, but this is unusual. 
436
437 If on the other hand the catalog is marked as having more files than Bacula
438 found on the tape, you need to consider the possible negative consequences of
439 modifying the catalog. Please see below for a more complete discussion of
440 this. 
441
442 Continuing with the example of {\bf Volume = 11 Catalog = 10}, to enable to
443 Bacula to append to the tape, you do the following: 
444
445 \footnotesize
446 \begin{verbatim}
447 update
448 Update choice:
449      1: Volume parameters
450      2: Pool from resource
451      3: Slots from autochanger
452 Choose catalog item to update (1-3): 1
453 Defined Pools:
454      1: Default
455      2: File
456 Select the Pool (1-2):
457 +-------+---------+--------+---------+-----------+------+----------+------+-----+
458 | MedId | VolName | MedTyp | VolStat | VolBytes  | Last | VolReten | Recy | Slt |
459 +-------+---------+--------+---------+-----------+------+----------+------+-----+
460 | 1     | test01  | DDS-4  | Error   | 352427156 | ...  | 31536000 | 1    | 0   |
461 +-------+---------+--------+---------+-----------+------+----------+------+-----+
462 Enter MediaId or Volume name: 1
463 \end{verbatim}
464 \normalsize
465
466 (note table output truncated for presentation) First, you chose to update the
467 Volume parameters by entering a {\bf 1}. In the volume listing that follows,
468 notice how the VolStatus is {\bf Error}. We will correct that after changing
469 the Volume Files. Continuing, you respond 1, 
470
471 \footnotesize
472 \begin{verbatim}
473 Updating Volume "test01"
474 Parameters to modify:
475      1: Volume Status
476      2: Volume Retention Period
477      3: Volume Use Duration
478      4: Maximum Volume Jobs
479      5: Maximum Volume Files
480      6: Maximum Volume Bytes
481      7: Recycle Flag
482      8: Slot
483      9: Volume Files
484     10: Pool
485     11: Done
486 Select parameter to modify (1-11): 9
487 Warning changing Volume Files can result
488 in loss of data on your Volume
489 Current Volume Files is: 10
490 Enter new number of Files for Volume: 11
491 New Volume Files is: 11
492 Updating Volume "test01"
493 Parameters to modify:
494      1: Volume Status
495      2: Volume Retention Period
496      3: Volume Use Duration
497      4: Maximum Volume Jobs
498      5: Maximum Volume Files
499      6: Maximum Volume Bytes
500      7: Recycle Flag
501      8: Slot
502      9: Volume Files
503     10: Pool
504     11: Done
505 Select parameter to modify (1-10): 1
506 \end{verbatim}
507 \normalsize
508
509 Here, you have selected {\bf 9} in order to update the Volume Files, then you
510 changed it from {\bf 10} to {\bf 11}, and you now answer {\bf 1} to change the
511 Volume Status. 
512
513 \footnotesize
514 \begin{verbatim}
515 Current Volume status is: Error
516 Possible Values are:
517      1: Append
518      2: Archive
519      3: Disabled
520      4: Full
521      5: Used
522      6: Read-Only
523 Choose new Volume Status (1-6): 1
524 New Volume status is: Append
525 Updating Volume "test01"
526 Parameters to modify:
527      1: Volume Status
528      2: Volume Retention Period
529      3: Volume Use Duration
530      4: Maximum Volume Jobs
531      5: Maximum Volume Files
532      6: Maximum Volume Bytes
533      7: Recycle Flag
534      8: Slot
535      9: Volume Files
536     10: Pool
537     11: Done
538 Select parameter to modify (1-11): 11
539 Selection done.
540 \end{verbatim}
541 \normalsize
542
543 At this point, you have changed the Volume Files from {\bf 10} to {\bf 11} to
544 account for the last file that was written but not updated in the database,
545 and you changed the Volume Status back to {\bf Append}. 
546
547 This was a lot of words to describe something quite simple. 
548
549 The {\bf Volume Files} option exists only in version 1.29 and later, and you
550 should be careful using it. Generally, if you set the value to that which
551 Bacula said is on the tape, you will be OK, especially if the value is one
552 more than what is in the catalog. 
553
554 Now lets consider the case: 
555
556 \footnotesize
557 \begin{verbatim}
558   The number of files mismatch! Volume=10 Catalog=12
559 \end{verbatim}
560 \normalsize
561
562 Here the Bacula found fewer files on the volume than what is marked in the
563 catalog. Now, in this case, you should hesitate a lot before modifying the count
564 in the catalog, because if you force the catalog from 12 to 10, Bacula will
565 start writing after the file 10 on the tape, possibly overwriting valid data,
566 and if you ever try to restore any of the files that the catalog has marked as
567 saved on Files 11 and 12, all chaos will break out. In this case, you will
568 probably be better off using a new tape. In fact, you might want to see what
569 files the catalog claims are actually stored on that Volume, and back them up
570 to another tape and recycle this tape. 
571
572 \section{Security Considerations}
573 \label{security}
574 \index[general]{Considerations!Security }
575 \index[general]{Security Considerations }
576
577 Only the File daemon needs to run with root permission (so that it can access
578 all files). As a consequence, you may run your Director, Storage daemon, and
579 MySQL or PostgreSQL database server as non-root processes. Version 1.30 has
580 the {\bf -u} and the {\bf -g} options that allow you to specify a userid and
581 groupid on the command line to be used after Bacula starts. 
582
583 As of version 1.33, thanks to Dan Langille, it is easier to configure the
584 Bacula Director and Storage daemon to run as non-root. 
585
586 You should protect the Bacula port addresses (normally 9101, 9102, and 9103)
587 from outside access by a firewall or other means of protection to prevent
588 unauthorized use of your daemons. 
589
590 You should ensure that the configuration files are not world readable since
591 they contain passwords that allow access to the daemons. Anyone who can access
592 the Director using a console program can restore any file from a backup
593 Volume. 
594
595 You should protect your Catalog database. If you are using SQLite, make sure
596 that the working directory is readable only by root (or your Bacula userid),
597 and ensure that {\bf bacula.db} has permissions {\bf -rw-r\verb:--:r\verb:--:} (i.e. 640) or
598 more strict. If you are using MySQL or PostgreSQL, please note that the Bacula
599 setup procedure leaves the database open to anyone. At a minimum, you should
600 assign the user {\bf bacula} a userid and add it to your Director's
601 configuration file in the appropriate Catalog resource. 
602
603 If you use the make\_catalog\_backup script provided by Bacula, remember that
604 you should take care when supplying passwords on the command line.  Read the
605 \ilink{Backing Up Your Bacula
606 Database - Security Considerations }{BackingUpBaculaSecurityConsiderations}
607 section for more information.
608
609 \section{Creating Holiday Schedules}
610 \label{holiday}
611 \index[general]{Schedules!Creating Holiday }
612 \index[general]{Creating Holiday Schedules }
613
614 If you normally change tapes every day or at least every Friday, but Thursday
615 is a holiday, you can use a trick proposed by Lutz Kittler to ensure that no
616 job runs on Thursday so that you can insert Friday's tape and be sure it will
617 be used on Friday. To do so, define a {\bf RunJobBefore} script that normally
618 returns zero, so that the Bacula job will normally continue. You can then
619 modify the script to return non-zero on any day when you do not want Bacula to
620 run the job. 
621
622 \section{Automatic Labeling Using Your Autochanger}
623 \label{autolabel}
624 \index[general]{Automatic Labeling Using Your Autochanger }
625 \index[general]{Autochanger!Automatic Labeling Using Your }
626
627 If you have an autochanger but it does not support barcodes, using a "trick"
628 you can make Bacula automatically label all the volumes in your autochanger's
629 magazine. 
630
631 First create a file containing one line for each slot in your autochanger that
632 has a tape to be labeled. The line will contain the slot number a colon (:)
633 then the Volume name you want to use. For example, create a file named {\bf
634 volume-list}, which contains: 
635
636 \footnotesize
637 \begin{verbatim}
638 1:Volume001
639 2:TestVolume02
640 5:LastVolume
641 \end{verbatim}
642 \normalsize
643
644 The records do not need to be in any order and you don't need to mention all
645 the slots. Normally, you will have a consistent set of Volume names and a
646 sequential set of numbers for each slot you want labeled. In the example
647 above, I've left out slots 3 and 4 just as an example. Now, modify your {\bf
648 mtx-changer} script and comment out all the lines in the {\bf list)} case by
649 putting a \# in column 1. Then add the following two lines: 
650
651 \footnotesize
652 \begin{verbatim}
653   cat <absolute-path>/volume-list
654   exit 0
655 \end{verbatim}
656 \normalsize
657
658 so that the whole case looks like: 
659
660 \footnotesize
661 \begin{verbatim}
662   list)
663 #
664 # commented out lines
665    cat <absolute-path>/volume-list
666    exit 0
667    ;;
668 \end{verbatim}
669 \normalsize
670
671 where you replace \lt{}absolute-path\gt{} with the full path to the
672 volume-list file. Then using the console, you enter the following command: 
673
674 \footnotesize
675 \begin{verbatim}
676    label barcodes
677 \end{verbatim}
678 \normalsize
679
680 and Bacula will proceed to mount the autochanger Volumes in the list and label
681 them with the Volume names you have supplied. Bacula will think that the list
682 was provided by the autochanger barcodes, but in reality, it was you who
683 supplied the \lt{}barcodes\gt{}. 
684
685 If it seems to work, when it finishes, enter: 
686
687 \footnotesize
688 \begin{verbatim}
689    list volumes
690 \end{verbatim}
691 \normalsize
692
693 and you should see all the volumes nicely created. 
694
695 \section{Backing Up Portables Using DHCP}
696 \label{DNS}
697 \index[general]{DHCP!Backing Up Portables Using }
698 \index[general]{Backing Up Portables Using DHCP }
699
700 You may want to backup laptops or portables that are not always connected to
701 the network. If you are using DHCP to assign an IP address to those machines
702 when they connect, you will need to use the Dynamic Update capability of DNS
703 to assign a name to those machines that can be used in the Address field of
704 the Client resource in the Director's conf file. 
705
706 \section{Going on Vacation}
707 \label{Vacation}
708 \index[general]{Vacation!Going on }
709 \index[general]{Going on Vacation }
710
711 At some point, you may want to be absent for a week or two and you want to
712 make sure Bacula has enough tape left so that the backups will complete. You
713 start by doing a {\bf list volumes} in the Console program: 
714
715 \footnotesize
716 \begin{verbatim}
717 list volumes
718  
719 Using default Catalog name=BackupDB DB=bacula
720 Pool: Default
721 +---------+---------------+-----------+-----------+----------------+-
722 | MediaId | VolumeName    | MediaType | VolStatus |       VolBytes |
723 +---------+---------------+-----------+-----------+----------------+-
724 |      23 | DLT-30Nov02   | DLT8000   | Full      | 54,739,278,128 |
725 |      24 | DLT-21Dec02   | DLT8000   | Full      | 56,331,524,629 |
726 |      25 | DLT-11Jan03   | DLT8000   | Full      | 67,863,514,895 |
727 |      26 | DLT-02Feb03   | DLT8000   | Full      | 63,439,314,216 |
728 |      27 | DLT-03Mar03   | DLT8000   | Full      | 66,022,754,598 |
729 |      28 | DLT-04Apr03   | DLT8000   | Full      | 60,792,559,924 |
730 |      29 | DLT-28Apr03   | DLT8000   | Full      | 62,072,494,063 |
731 |      30 | DLT-17May03   | DLT8000   | Full      | 65,901,767,839 |
732 |      31 | DLT-07Jun03   | DLT8000   | Used      | 56,558,490,015 |
733 |      32 | DLT-28Jun03   | DLT8000   | Full      | 64,274,871,265 |
734 |      33 | DLT-19Jul03   | DLT8000   | Full      | 64,648,749,480 |
735 |      34 | DLT-08Aug03   | DLT8000   | Full      | 64,293,941,255 |
736 |      35 | DLT-24Aug03   | DLT8000   | Append    |  9,999,216,782 |
737 +---------+---------------+-----------+-----------+----------------+
738 \end{verbatim}
739 \normalsize
740
741 Note, I have truncated the output for presentation purposes. What is
742 significant, is that I can see that my current tape has almost 10 Gbytes of
743 data, and that the average amount of data I get on my tapes is about 60
744 Gbytes. So if I go on vacation now, I don't need to worry about tape capacity
745 (at least not for short absences). 
746
747 Equally significant is the fact that I did go on vacation the 28th of June
748 2003, and when I did the {\bf list volumes} command, my current tape at that
749 time, DLT-07Jun03 MediaId 31, had 56.5 Gbytes written. I could see that the
750 tape would fill shortly. Consequently, I manually marked it as {\bf Used} and
751 replaced it with a fresh tape that I labeled as DLT-28Jun03, thus assuring
752 myself that the backups would all complete without my intervention. 
753
754 \section{Exclude Files on Windows Regardless of Case}
755 \label{Case}
756 \index[general]{Exclude Files on Windows Regardless of Case}
757 % TODO: should this be put in the win32 chapter?
758 % TODO: should all these tips be placed in other chapters?
759
760 This tip was submitted by Marc Brueckner who wasn't sure of the case of some
761 of his files on Win32, which is case insensitive. The problem is that Bacula
762 thinks that {\bf /UNIMPORTANT FILES} is different from {\bf /Unimportant
763 Files}. Marc was aware that the file exclusion permits wild-cards. So, he
764 specified: 
765
766 \footnotesize
767 \begin{verbatim}
768 "/[Uu][Nn][Ii][Mm][Pp][Oo][Rr][Tt][Aa][Nn][Tt] [Ff][Ii][Ll][Ee][Ss]"
769 \end{verbatim}
770 \normalsize
771
772 As a consequence, the above exclude works for files of any case. 
773
774 Please note that this works only in Bacula Exclude statement and not in
775 Include. 
776
777 \section{Executing Scripts on a Remote Machine}
778 \label{RemoteExecution}
779 \index[general]{Machine!Executing Scripts on a Remote }
780 \index[general]{Executing Scripts on a Remote Machine }
781
782 This tip also comes from Marc Brueckner. (Note, this tip is probably outdated
783 by the addition of {\bf ClientRunBeforJob} and {\bf ClientRunAfterJob} Job
784 records, but the technique still could be useful.) First I thought the "Run
785 Before Job" statement in the Job-resource is for executing a script on the
786 remote machine (the machine to be backed up). (Note, this is possible as mentioned
787 above by using {\bf ClientRunBeforJob} and {\bf ClientRunAfterJob}).
788 It could be useful to execute
789 scripts on the remote machine e.g. for stopping databases or other services
790 while doing the backup. (Of course I have to start the services again when the
791 backup has finished) I found the following solution: Bacula could execute
792 scripts on the remote machine by using ssh. The authentication is done
793 automatically using a private key. First you have to generate a keypair. I've
794 done this by: 
795
796 \footnotesize
797 \begin{verbatim}
798 ssh-keygen -b 4096 -t dsa -f Bacula_key
799 \end{verbatim}
800 \normalsize
801
802 This statement may take a little time to run. It creates a public/private key
803 pair with no passphrase. You could save the keys in /etc/bacula. Now you have
804 two new files : Bacula\_key which contains the private key and Bacula\_key.pub
805 which contains the public key. 
806
807 Now you have to append the Bacula\_key.pub file to the file authorized\_keys
808 in the \textbackslash{}root\textbackslash{}.ssh directory of the remote
809 machine. Then you have to add (or uncomment) the line 
810
811 \footnotesize
812 \begin{verbatim}
813 AuthorizedKeysFile           %h/.ssh/authorized_keys
814 \end{verbatim}
815 \normalsize
816
817 to the sshd\_config file on the remote machine. Where the \%h stands for the
818 home-directory of the user (root in this case). 
819
820 Assuming that your sshd is already running on the remote machine, you can now
821 enter the following on the machine where Bacula runs: 
822
823 \footnotesize
824 \begin{verbatim}
825 ssh -i Bacula_key  -l root <machine-name-or-ip-address> "ls -la"
826 \end{verbatim}
827 \normalsize
828
829 This should execute the "ls -la" command on the remote machine. 
830
831 Now you could add lines like the following to your Director's conf file: 
832
833 \footnotesize
834 \begin{verbatim}
835 ...
836 Run Before Job = ssh -i /etc/bacula/Bacula_key 192.168.1.1 \
837                  "/etc/init.d/database stop"
838 Run After Job = ssh -i /etc/bacula/Bacula_key 192.168.1.1 \
839                  "/etc/init.d/database start"
840 ...
841 \end{verbatim}
842 \normalsize
843
844 Even though Bacula version 1.32 and later has a ClientRunBeforeJob, the ssh method still
845 could be useful for updating all the Bacula clients on several remote machines
846 in a single script. 
847
848 \section{Recycling All Your Volumes}
849 \label{recycle}
850 \index[general]{Recycling All Your Volumes }
851 \index[general]{Volumes!Recycling All Your }
852
853 This tip comes from Phil Stracchino. 
854
855 If you decide to blow away your catalog and start over, the simplest way to
856 re-add all your prelabeled tapes with a minimum of fuss (provided you don't
857 care about the data on the tapes) is to add the tape labels using the console
858 {\bf add} command, then go into the catalog and manually set the VolStatus of
859 every tape to {\bf Recycle}. 
860
861 The SQL command to do this is very simple, either use your vendor's
862 command line interface (mysql, postgres, sqlite, ...) or use the sql
863 command in the Bacula console:
864
865 \footnotesize
866 \begin{verbatim}
867 update Media set VolStatus='Recycle';
868 \end{verbatim}
869 \normalsize
870
871 Bacula will then ignore the data already stored on the tapes and just re-use
872 each tape without further objection. 
873
874 \section{Backing up ACLs on ext3 or XFS filesystems}
875 \label{ACLs}
876 \index[general]{Filesystems!Backing up ACLs on ext3 or XFS }
877 \index[general]{Backing up ACLs on ext3 or XFS filesystems }
878
879 This tip comes from Volker Sauer. 
880
881 Note, this tip was given prior to implementation of ACLs in Bacula (version
882 1.34.5). It is left here because dumping/displaying ACLs can still be useful
883 in testing/verifying that Bacula is backing up and restoring your ACLs
884 properly. Please see the 
885 \ilink{aclsupport}{ACLSupport} FileSet option in the
886 configuration chapter of this manual. 
887
888 For example, you could dump the ACLs to a file with a script similar to the
889 following: 
890
891 \footnotesize
892 \begin{verbatim}
893 #!/bin/sh
894 BACKUP_DIRS="/foo /bar"
895 STORE_ACL=/root/acl-backup
896 umask 077
897 for i in $BACKUP_DIRS; do
898  cd $i /usr/bin/getfacl -R --skip-base .>$STORE_ACL/${i//\//_}
899 done
900 \end{verbatim}
901 \normalsize
902
903 Then use Bacula to backup {\bf /root/acl-backup}. 
904
905 The ACLs could be restored using Bacula to the {\bf /root/acl-backup} file,
906 then restored to your system using: 
907
908 \footnotesize
909 \begin{verbatim}
910 setfacl --restore/root/acl-backup
911 \end{verbatim}
912 \normalsize
913
914 \section{Total Automation of Bacula Tape Handling}
915 \label{automate}
916 \index[general]{Handling!Total Automation of Bacula Tape }
917 \index[general]{Total Automation of Bacula Tape Handling }
918
919 This tip was provided by Alexander Kuehn. 
920
921 \elink{Bacula}{http://www.bacula.org/} is a really nice backup program except
922 that the manual tape changing requires user interaction with the bacula
923 console. 
924
925 Fortunately I can fix this.
926 NOTE!!! This suggestion applies for people who do *NOT* have tape autochangers
927 and must change tapes manually.!!!!! 
928
929 Bacula supports a variety of tape changers through the use of mtx-changer
930 scripts/programs. This highly flexible approach allowed me to create 
931 \elink{this shell script}{http://www.bacula.org/en/rel-manual/mtx-changer.txt} which does the following:
932 % TODO: We need to include this in book appendix and point to it.
933 % TODO:
934 Whenever a new tape is required it sends a mail to the operator to insert the
935 new tape. Then it waits until a tape has been inserted, sends a mail again to
936 say thank you and let's bacula continue its backup.
937 So you can schedule and run backups without ever having to log on or see the
938 console.
939 To make the whole thing work you need to create a Device resource which looks
940 something like this ("Archive Device", "Maximum Changer Wait", "Media
941 Type" and "Label media" may have different values): 
942
943 \footnotesize
944 \begin{verbatim}
945 Device {
946    Name=DDS3
947    Archive Device = # use yours not mine! ;)/dev/nsa0
948    Changer Device = # not really required/dev/nsa0
949    Changer Command = "# use this (maybe change the path)!
950          /usr/local/bin/mtx-changer %o %a %S"
951    Maximum Changer Wait = 3d          # 3 days in seconds
952    AutomaticMount = yes;              # mount on start
953    AlwaysOpen = yes;                  # keep device locked
954    Media Type = DDS3                  # it's just a name
955    RemovableMedia = yes;              #
956    Offline On Unmount = Yes;          # keep this too
957    Label media = Yes;                 #
958 }
959 \end{verbatim}
960 \normalsize
961
962 As the script has to emulate the complete wisdom of a mtx-changer it has an
963 internal "database" containing where which tape is stored, you can see this on
964 the following line:
965
966 \footnotesize
967 \begin{verbatim}
968 labels="VOL-0001 VOL-0002 VOL-0003 VOL-0004 VOL-0005 VOL-0006
969 VOL-0007 VOL-0008 VOL-0009 VOL-0010 VOL-0011 VOL-0012"
970 \end{verbatim}
971 \normalsize
972
973 The above should be all on one line, and it effectively tells Bacula that
974 volume "VOL-0001" is located in slot 1 (which is our lowest slot), that
975 volume "VOL-0002" is located in slot 2 and so on..
976 The script also maintains a logfile (/var/log/mtx.log) where you can monitor
977 its operation.
978
979 \section{Running Concurrent Jobs}
980 \label{ConcurrentJobs}
981 \index[general]{Jobs!Running Concurrent}
982 \index[general]{Running Concurrent Jobs}
983 \index[general]{Concurrent Jobs}
984
985 Bacula can run multiple concurrent jobs, but the default configuration files
986 do not enable it. Using the {\bf Maximum Concurrent Jobs} directive, you
987 can configure how many and which jobs can be run simultaneously. 
988 The Director's default value for {\bf Maximum Concurrent Jobs} is "1".
989
990 To initially setup concurrent jobs you need to define {\bf Maximum Concurrent Jobs} in 
991 the Director's configuration file (bacula-dir.conf) in the 
992 Director, Job, Client, and Storage resources.
993
994 Additionally the File daemon, and the Storage daemon each have their own
995 {\bf Maximum Concurrent Jobs} directive that sets the overall maximum
996 number of concurrent jobs the daemon will run.  The default for both the
997 File daemon and the Storage daemon is "20".
998
999 For example, if you want two different jobs to run simultaneously backing up
1000 the same Client to the same Storage device, they will run concurrently only if
1001 you have set {\bf Maximum Concurrent Jobs} greater than one in the Director
1002 resource, the Client resource, and the Storage resource in bacula-dir.conf. 
1003
1004 We recommend that you read the \ilink{Data
1005 Spooling}{SpoolingChapter} of this manual first, then test your multiple
1006 concurrent backup including restore testing before you put it into
1007 production.
1008
1009 Below is a super stripped down bacula-dir.conf file showing you the four
1010 places where the the file must be modified to allow the same job {\bf
1011 NightlySave} to run up to four times concurrently. The change to the Job
1012 resource is not necessary if you want different Jobs to run at the same time,
1013 which is the normal case. 
1014
1015 \footnotesize
1016 \begin{verbatim}
1017 #
1018 # Bacula Director Configuration file -- bacula-dir.conf
1019 #
1020 Director {
1021   Name = rufus-dir
1022   Maximum Concurrent Jobs = 4
1023   ...
1024 }
1025 Job {
1026   Name = "NightlySave"
1027   Maximum Concurrent Jobs = 4
1028   Client = rufus-fd
1029   Storage = File
1030   ...
1031 }
1032 Client {
1033   Name = rufus-fd
1034   Maximum Concurrent Jobs = 4
1035   ...
1036 }
1037 Storage {
1038   Name = File
1039   Maximum Concurrent Jobs = 4
1040   ...
1041 }
1042 \end{verbatim}
1043 \normalsize