]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/en/main/catmaintenance.tex
3efa6d578bb19eee4151a1171304cdbfc8ba97a4
[bacula/docs] / docs / manuals / en / main / catmaintenance.tex
1 %%
2 %%
3
4 \chapter{Catalog Maintenance}
5 \label{CatMaintenanceChapter}
6 \index[general]{Maintenance!Catalog }
7 \index[general]{Catalog Maintenance }
8
9 Without proper setup and maintenance, your Catalog may continue to grow
10 indefinitely as you run Jobs and backup Files, and/or it may become
11 very inefficient and slow. How fast the size of your
12 Catalog grows depends on the number of Jobs you run and how many files they
13 backup. By deleting records within the database, you can make space available
14 for the new records that will be added during the next Job. By constantly
15 deleting old expired records (dates older than the Retention period), your
16 database size will remain constant. 
17
18 If you started with the default configuration files, they already contain
19 reasonable defaults for a small number of machines (less than 5), so if you
20 fall into that case, catalog maintenance will not be urgent if you have a few
21 hundred megabytes of disk space free. Whatever the case may be, some knowledge
22 of retention periods will be useful. 
23 \label{Retention}
24
25 \section{Setting Retention Periods}
26 \index[general]{Setting Retention Periods }
27 \index[general]{Periods!Setting Retention }
28
29 {\bf Bacula} uses three Retention periods: the {\bf File Retention} period,
30 the {\bf Job Retention} period, and the {\bf Volume Retention} period. Of
31 these three, the File Retention period is by far the most important in
32 determining how large your database will become. 
33
34 The {\bf File Retention} and the {\bf Job Retention} are specified in each
35 Client resource as is shown below. The {\bf Volume Retention} period is
36 specified in the Pool resource, and the details are given in the next chapter
37 of this manual. 
38
39 \begin{description}
40
41 \item [File Retention = \lt{}time-period-specification\gt{}]
42    \index[general]{File Retention  }
43    The  File Retention record defines the length of time that  Bacula will keep
44 File records in the Catalog database.  When this time period expires, and if
45 {\bf AutoPrune} is set to {\bf yes}, Bacula will prune (remove) File records
46 that  are older than the specified File Retention period. The pruning  will
47 occur at the end of a backup Job for the given Client.  Note that the Client
48 database record contains a copy of the  File and Job retention periods, but
49 Bacula uses the  current values found in the Director's Client resource to  do
50 the pruning.  
51
52 Since File records in the database account for probably 80 percent of the 
53 size of the database, you should carefully determine exactly what File
54 Retention period you need. Once the File records have been removed from
55 the database, you will no longer be able to restore individual files
56 in a Job. However, with Bacula version 1.37 and later, as long as the
57 Job record still exists, you will be able to restore all files in the
58 job.
59
60 Retention periods are specified in seconds, but as a convenience, there are
61 a number of modifiers that permit easy specification in terms of minutes,
62 hours, days, weeks, months, quarters, or years on the record.  See the
63 \ilink{ Configuration chapter}{Time} of this manual for additional details
64 of modifier specification.
65
66 The default File retention period is 60 days.  
67
68 \item [Job Retention = \lt{}time-period-specification\gt{}]
69    \index[general]{Job Retention  }
70    The Job Retention record defines the length of time that {\bf Bacula}
71 will keep Job records in the Catalog database.  When this time period
72 expires, and if {\bf AutoPrune} is set to {\bf yes} Bacula will prune
73 (remove) Job records that are older than the specified Job Retention
74 period.  Note, if a Job record is selected for pruning, all associated File
75 and JobMedia records will also be pruned regardless of the File Retention
76 period set.  As a consequence, you normally will set the File retention
77 period to be less than the Job retention period.
78
79 As mentioned above, once the File records are removed from the database,
80 you will no longer be able to restore individual files from the Job.
81 However, as long as the Job record remains in the database, you will be
82 able to restore all the files backuped for the Job (on version 1.37 and 
83 later). As a consequence, it is generally a good idea to retain the Job
84 records much longer than the File records.
85
86 The retention period is specified in seconds, but as a convenience, there
87 are a number of modifiers that permit easy specification in terms of
88 minutes, hours, days, weeks, months, quarters, or years.  See the \ilink{
89 Configuration chapter}{Time} of this manual for additional details of
90 modifier specification.
91
92 The default Job Retention period is 180 days.  
93
94 \item [AutoPrune = \lt{}yes/no\gt{}]
95    \index[general]{AutoPrune  }
96    If AutoPrune is set to  {\bf yes} (default), Bacula will  automatically apply
97 the File retention period and the Job  retention period for the Client at the
98 end of the Job.  
99
100 If you turn this off by setting it to {\bf no}, your  Catalog will grow each
101 time you run a Job. 
102 \end{description}
103
104 \label{CompactingMySQL}
105 \section{Compacting Your MySQL Database}
106 \index[general]{Database!Compacting Your MySQL }
107 \index[general]{Compacting Your MySQL Database }
108
109 Over time, as noted above, your database will tend to grow. I've noticed that
110 even though Bacula regularly prunes files, {\bf MySQL} does not effectively
111 use the space, and instead continues growing. To avoid this, from time to
112 time, you must compact your database. Normally, large commercial database such
113 as Oracle have commands that will compact a database to reclaim wasted file
114 space. MySQL has the {\bf OPTIMIZE TABLE} command that you can use, and SQLite
115 version 2.8.4 and greater has the {\bf VACUUM} command. We leave it to you to
116 explore the utility of the {\bf OPTIMIZE TABLE} command in MySQL. 
117
118 All database programs have some means of writing the database out in ASCII
119 format and then reloading it. Doing so will re-create the database from
120 scratch producing a compacted result, so below, we show you how you can do
121 this for MySQL, PostgreSQL and SQLite. 
122
123 For a {\bf MySQL} database, you could write the Bacula database as an ASCII
124 file (bacula.sql) then reload it by doing the following: 
125
126 \footnotesize
127 \begin{verbatim}
128 mysqldump -f --opt bacula > bacula.sql
129 mysql bacula < bacula.sql
130 rm -f bacula.sql
131 \end{verbatim}
132 \normalsize
133
134 Depending on the size of your database, this will take more or less time and a
135 fair amount of disk space. For example, if I cd to the location of the MySQL
136 Bacula database (typically /opt/mysql/var or something similar) and enter: 
137
138 \footnotesize
139 \begin{verbatim}
140 du bacula
141 \end{verbatim}
142 \normalsize
143
144 I get {\bf 620,644} which means there are that many blocks containing 1024
145 bytes each or approximately 635 MB of data. After doing the {\bf mysqldump}, I
146 had a bacula.sql file that had {\bf 174,356} blocks, and after doing the {\bf
147 mysql} command to recreate the database, I ended up with a total of {\bf
148 210,464} blocks rather than the original {\bf 629,644}. In other words, the
149 compressed version of the database took approximately one third of the space
150 of the database that had been in use for about a year. 
151
152 As a consequence, I suggest you monitor the size of your database and from
153 time to time (once every six months or year), compress it. 
154
155 \label{DatabaseRepair}
156 \label{RepairingMySQL}
157 \section{Repairing Your MySQL Database}
158 \index[general]{Database!Repairing Your MySQL }
159 \index[general]{Repairing Your MySQL Database }
160
161 If you find that you are getting errors writing to your MySQL database, or
162 Bacula hangs each time it tries to access the database, you should consider
163 running MySQL's database check and repair routines. The program you need to
164 run depends on the type of database indexing you are using. If you are using
165 the default, you will probably want to use {\bf myisamchk}. For more details
166 on how to do this, please consult the MySQL document at: 
167 \elink{
168 http://www.mysql.com/doc/en/Repair.html}
169 {http://www.mysql.com/doc/en/Repair.html}. 
170
171 If the errors you are getting are simply SQL warnings, then you might try
172 running dbcheck before (or possibly after) using the MySQL database repair
173 program. It can clean up many of the orphaned record problems, and certain
174 other inconsistencies in the Bacula database. 
175
176 A typical cause of MySQL database problems is if your partition fills. In
177 such a case, you will need to create additional space on the partition or
178 free up some space then repair the database probably using {\bf myisamchk}.
179 Recently my root partition filled and the MySQL database was corrupted.
180 Simply running {\bf myisamchk -r} did not fix the problem. However,
181 the following script did the trick for me:
182
183 \footnotesize
184 \begin{verbatim}
185 #!/bin/sh
186 for i in *.MYD ; do
187   mv $i x${i}
188   t=`echo $i | cut -f 1 -d '.' -`
189   mysql bacula <<END_OF_DATA
190 set autocommit=1;
191 truncate table $t;
192 quit
193 END_OF_DATA
194   cp x${i} ${i}
195   chown mysql:mysql ${i}
196   myisamchk -r ${t}
197 done
198 \end{verbatim}
199 \normalsize
200
201 I invoked it with the following commands:
202
203 \footnotesize
204 \begin{verbatim}
205 cd /var/lib/mysql/bacula
206 ./repair
207 \end{verbatim}
208 \normalsize
209
210 Then after ensuring that the database was correctly fixed, I did:
211 \footnotesize
212 \begin{verbatim}
213 cd /var/lib/mysql/bacula
214 rm -f x*.MYD
215 \end{verbatim}
216 \normalsize
217
218 \section{MySQL Table is Full}
219 \index[general]{Database!MySQL Table is Full}
220 \index[general]{MySQL Table is Full}
221
222 If you are running into the error {\bf The table 'File' is full ...}, 
223 it is probably because on version 4.x MySQL, the table is limited by   
224 default to a maximum size of 4 GB and you have probably run into
225 the limit. The solution can be found at:
226 \elink{http://dev.mysql.com/doc/refman/5.0/en/full-table.html}
227 {http://dev.mysql.com/doc/refman/5.0/en/full-table.html}
228
229 You can display the maximum length of your table with:
230
231 \footnotesize
232 \begin{verbatim}
233 mysql bacula
234 SHOW TABLE STATUS FROM bacula like "File";
235 \end{verbatim}
236 \normalsize
237
238 If the column labeled "Max\_data\_length" is around 4Gb, this is likely
239 to be the source of your problem, and you can modify it with:
240
241 \footnotesize
242 \begin{verbatim}
243 mysql bacula
244 ALTER TABLE File MAX_ROWS=281474976710656;
245 \end{verbatim}
246 \normalsize
247
248 Alternatively you can modify your /etc/my.conf file before creating the
249 Bacula tables, and in the [mysqld] section set:
250
251 \footnotesize                                 
252 \begin{verbatim}
253 set-variable = myisam_data_pointer_size=6
254 \end{verbatim}
255 \normalsize
256
257 The above myisam data pointer size must be made before you create your
258 Bacula tables or it will have no effect.
259
260 The row and pointer size changes should already be the default on MySQL
261 version 5.x, so making these changes should only be necessary on MySQL 4.x
262 depending on the size of your catalog database.
263
264 \section{MySQL Server Has Gone Away}
265 \index[general]{Database!MySQL Server Has Gone Away}
266 \index[general]{MySQL Server Has Gone Away}
267 If you are having problems with the MySQL server disconnecting or with
268 messages saying that your MySQL server has gone away, then please read
269 the MySQL documentation, which can be found at:
270
271 \elink{http://dev.mysql.com/doc/refman/5.0/en/gone-away.html}
272 {http://dev.mysql.com/doc/refman/5.0/en/gone-away.html}
273
274 \section{MySQL Temporary Tables}
275 When doing backups with large numbers of files, MySQL creates some
276 temporary tables.  When these tables are small they can be held in
277 system memory, but as they approach some size, they
278 spool off to disk.  The default location for these temp tables is
279 /tmp.  Once that space fills up, Bacula daemons such as the Storage
280 daemon doing spooling can get strange errors. E.g.
281
282 \footnotesize                                 
283 \begin{verbatim}
284 Fatal error: spool.c:402 Spool data read error.
285 Fatal error: backup.c:892 Network send error to SD. ERR=Connection reset by
286 peer
287 \end{verbatim}
288 \normalsize
289
290 What you need to do is setup MySQL to use a different (larger) temp
291 directory, which can be set in the /etc/my.cnf with these variables
292 set:
293
294 \footnotesize                                 
295 \begin{verbatim}
296   tmpdir=/path/to/larger/tmpdir
297   bdb_tmpdir=/path/to/larger/tmpdir
298 \end{verbatim}
299 \normalsize
300
301 \label{RepairingPSQL}
302 \section{Repairing Your PostgreSQL Database}
303 \index[general]{Database!Repairing Your PostgreSQL }
304 \index[general]{Repairing Your PostgreSQL Database }
305
306 The same considerations apply that are indicated above for MySQL. That is,
307 consult the PostgreSQL documents for how to repair the database, and also
308 consider using Bacula's dbcheck program if the conditions are reasonable for
309 using (see above). 
310
311 \label{DatabasePerformance}
312 \section{Database Performance Issues}
313 \index[general]{Database Performance Issues}
314 \index[general]{Performance!Database}
315
316 There are a considerable number of ways each of the databases can be
317 tuned to improve the performance. Going from an untuned database to one
318 that is properly tuned can make a difference of a factor of 100 or more
319 in the time to insert or search for records.
320
321 For each of the databases, you may get significant improvements by adding
322 additional indexes. The comments in the Bacula make\_xxx\_tables give some
323 indications as to what indexes may be appropriate.  Please see below
324 for specific instructions on checking indexes.
325
326 For MySQL, what is very important is to use the examine the    
327 my.cnf file (usually in /etc/my.cnf).
328 You may obtain significant performances by switching to
329 the my-large.cnf or my-huge.cnf files that come with the MySQL source
330 code.
331
332 For SQLite3, one significant factor in improving the performance is
333 to ensure that there is a "PRAGMA synchronous = NORMAL;" statement.
334 This reduces the number of times that the database flushes the in memory
335 cache to disk. There are other settings for this PRAGMA that can 
336 give even further performance improvements at the risk of a database
337 corruption if your system crashes.
338
339 For PostgreSQL, you might want to consider turning fsync off.  Of course
340 doing so can cause corrupted databases in the event of a machine crash.
341 There are many different ways that you can tune PostgreSQL, the
342 following document discusses a few of them:
343 \elink{
344 http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html}
345 {http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html}.
346
347 There is also a PostgreSQL FAQ question number 3.3 that may
348 answer some of your questions about how to improve performance
349 of the PostgreSQL engine:
350 \elink{
351 http://www.postgresql.org/docs/faqs.FAQ.html\#3.3}
352 {http://www.postgresql.org/docs/faqs.FAQ.html\#3.3}.
353 % TODO: verify above is correct. is this okay for book?
354
355 Also for PostgreSQL, look at what "effective\_cache\_size". For a 2GB memory 
356 machine, you probably want to set it at 131072, but don't set it too high.
357 In addition, for a 2GB system, work\_mem = 256000 and
358 maintenance\_work\_mem = 256000 seem to be reasonable values.  Make
359 sure your checkpoint\_segments is set to at least 8.
360
361
362
363 \section{Performance Issues Indexes}
364 \index[general]{Database Performance Issues Indexes}
365 \index[general]{Performance!Database}
366 One of the most important considerations for improving performance on
367 the Bacula database is to ensure that it has all the appropriate indexes.
368 Several users have reported finding that their database did not have
369 all the indexes in the default configuration.  In addition, you may
370 find that because of your own usage patterns, you need additional indexes.
371
372 The most important indexes for performance are the two indexes on the
373 {\bf File} table.  The first index is on {\bf FileId} and is automatically
374 made because it is the unique key used to access the table.  The other
375 one is the (JobId, PathId, Filename) index.  If these Indexes
376 are not present, your performance may suffer a lot.
377
378 \subsection{PostgreSQL Indexes}
379 On PostgreSQL, you can check to see if you have the proper indexes using
380 the following commands:
381
382 \footnotesize
383 \begin{verbatim}
384 psql bacula
385 select * from pg_indexes where tablename='file';
386 \end{verbatim}
387 \normalsize
388
389 If you do not see output that indicates that all three indexes
390 are created, you can create the two additional indexes using:
391
392 \footnotesize
393 \begin{verbatim}
394 psql bacula
395 CREATE INDEX file_jobid_idx on file (jobid);
396 CREATE INDEX file_jpf_idx on file (jobid, pathid, filenameid);
397 \end{verbatim}
398 \normalsize
399
400 Make sure that you doesn't have an index on File (filenameid, pathid).
401
402 \subsection{MySQL Indexes}
403 On MySQL, you can check if you have the proper indexes by:
404
405 \footnotesize
406 \begin{verbatim}
407 mysql bacula
408 show index from File;
409 \end{verbatim}
410 \normalsize
411
412 If the indexes are not present, especially the JobId index, you can
413 create them with the following commands:
414
415 \footnotesize
416 \begin{verbatim}
417 mysql bacula
418 CREATE INDEX file_jobid_idx on File (JobId);
419 CREATE INDEX file_jpf_idx on File (JobId, FilenameId, PathId);
420 \end{verbatim}
421 \normalsize
422
423 Though normally not a problem, you should ensure that the indexes 
424 defined for Filename and Path are both set to 255 characters. Some users 
425 reported performance problems when their indexes were set to 50 characters.
426 To check, do:
427
428 \footnotesize
429 \begin{verbatim}
430 mysql bacula
431 show index from Filename;
432 show index from Path;
433 \end{verbatim}
434 \normalsize
435
436 and what is important is that for Filename, you have an index with
437 Key\_name "Name" and Sub\_part "255". For Path, you should have a Key\_name
438 "Path" and Sub\_part "255".  If one or the other does not exist or the
439 Sub\_part is less that 255, you can drop and recreate the appropriate
440 index with:
441
442 \footnotesize
443 \begin{verbatim}
444 mysql bacula
445 DROP INDEX Path on Path;
446 CREATE INDEX Path on Path (Path(255));
447
448 DROP INDEX Name on Filename;
449 CREATE INDEX Name on Filename (Name(255));
450 \end{verbatim}
451 \normalsize
452
453
454 \subsection{SQLite Indexes}
455 On SQLite, you can check if you have the proper indexes by:
456
457 \footnotesize
458 \begin{verbatim}
459 sqlite <path>/bacula.db
460 select * from sqlite_master where type='index' and tbl_name='File';
461 \end{verbatim}
462 \normalsize
463
464 If the indexes are not present, especially the JobId index, you can
465 create them with the following commands:
466
467 \footnotesize
468 \begin{verbatim}
469 sqlite <path>/bacula.db
470 CREATE INDEX file_jobid_idx on File (JobId);
471 CREATE INDEX file_jfp_idx on File (JobId, PathId, FilenameId);
472 \end{verbatim}
473 \normalsize
474
475
476
477 \label{CompactingPostgres}
478 \section{Compacting Your PostgreSQL Database}
479 \index[general]{Database!Compacting Your PostgreSQL }
480 \index[general]{Compacting Your PostgreSQL Database }
481
482 Over time, as noted above, your database will tend to grow. I've noticed that
483 even though Bacula regularly prunes files, PostgreSQL has a {\bf VACUUM}
484 command that will compact your database for you. Alternatively you may want to
485 use the {\bf vacuumdb} command, which can be run from a cron job. 
486
487 All database programs have some means of writing the database out in ASCII
488 format and then reloading it. Doing so will re-create the database from
489 scratch producing a compacted result, so below, we show you how you can do
490 this for PostgreSQL. 
491
492 For a {\bf PostgreSQL} database, you could write the Bacula database as an
493 ASCII file (bacula.sql) then reload it by doing the following: 
494
495 \footnotesize
496 \begin{verbatim}
497 pg_dump -c bacula > bacula.sql
498 cat bacula.sql | psql bacula
499 rm -f bacula.sql
500 \end{verbatim}
501 \normalsize
502
503 Depending on the size of your database, this will take more or less time and a
504 fair amount of disk space. For example, you can {\bf cd} to the location of
505 the Bacula database (typically /usr/local/pgsql/data or possible
506 /var/lib/pgsql/data) and check the size. 
507
508 There are certain PostgreSQL users who do not recommend the above 
509 procedure. They have the following to say:
510 PostgreSQL does not
511 need to be dumped/restored to keep the database efficient.  A normal
512 process of vacuuming will prevent the database from every getting too
513 large.  If you want to fine-tweak the database storage, commands such
514 as VACUUM FULL, REINDEX, and CLUSTER exist specifically to keep you
515 from having to do a dump/restore.
516
517 Finally, you might want to look at the PostgreSQL documentation on
518 this subject at
519 \elink{http://www.postgresql.org/docs/8.1/interactive/maintenance.html}
520 {http://www.postgresql.org/docs/8.1/interactive/maintenance.html}.  
521
522 \section{Compacting Your SQLite Database}
523 \index[general]{Compacting Your SQLite Database }
524 \index[general]{Database!Compacting Your SQLite }
525
526 First please read the previous section that explains why it is necessary to
527 compress a database. SQLite version 2.8.4 and greater have the {\bf Vacuum}
528 command for compacting the database. 
529
530 \footnotesize
531 \begin{verbatim}
532 cd {\bf working-directory}
533 echo 'vacuum;' | sqlite bacula.db
534 \end{verbatim}
535 \normalsize
536
537 As an alternative, you can use the following commands, adapted to your system:
538
539
540 \footnotesize
541 \begin{verbatim}
542 cd {\bf working-directory}
543 echo '.dump' | sqlite bacula.db > bacula.sql
544 rm -f bacula.db
545 sqlite bacula.db < bacula.sql
546 rm -f bacula.sql
547 \end{verbatim}
548 \normalsize
549
550 Where {\bf working-directory} is the directory that you specified in the
551 Director's configuration file. Note, in the case of SQLite, it is necessary to
552 completely delete (rm) the old database before creating a new compressed
553 version. 
554
555 \section{Migrating from SQLite to MySQL or PostgreSQL}
556 \index[general]{MySQL!Migrating from SQLite to }
557 \index[general]{Migrating from SQLite to MySQL or PostgreSQL}
558
559 You may begin using Bacula with SQLite then later find that you want to switch
560 to MySQL or Postgres for any of a number of reasons: SQLite tends to use more
561 disk than MySQL; when the database is corrupted it is often more catastrophic
562 than with MySQL or PostgreSQL.  Several users have succeeded in converting by
563 exporting the SQLite data and then processing it with Perl scripts prior to
564 putting it into MySQL or PostgreSQL. This is, however, not a simple process.
565 Scripts are available on bacula source distribution under
566 \texttt{examples/database}.
567
568 \label{BackingUpBacula}
569 \section{Backing Up Your Bacula Database}
570 \index[general]{Backing Up Your Bacula Database }
571 \index[general]{Database!Backing Up Your Bacula }
572
573 If ever the machine on which your Bacula database crashes, and you need to
574 restore from backup tapes, one of your first priorities will probably be to
575 recover the database. Although Bacula will happily backup your catalog
576 database if it is specified in the FileSet, this is not a very good way to do
577 it, because the database will be saved while Bacula is modifying it. Thus the
578 database may be in an instable state. Worse yet, you will backup the database
579 before all the Bacula updates have been applied. 
580
581 To resolve these problems, you need to backup the database after all the backup
582 jobs have been run. In addition, you will want to make a copy while Bacula is
583 not modifying it. To do so, you can use two scripts provided in the release
584 {\bf make\_catalog\_backup} and {\bf delete\_catalog\_backup}. These files
585 will be automatically generated along with all the other Bacula scripts. The
586 first script will make an ASCII copy of your Bacula database into {\bf
587 bacula.sql} in the working directory you specified in your configuration, and
588 the second will delete the {\bf bacula.sql} file. 
589
590 The basic sequence of events to make this work correctly is as follows: 
591
592 \begin{itemize}
593 \item Run all your nightly backups  
594 \item After running your nightly backups, run a Catalog backup Job  
595 \item The Catalog backup job must be scheduled after your last nightly backup 
596
597 \item You use {\bf RunBeforeJob} to create the ASCII  backup file and {\bf
598    RunAfterJob} to clean up 
599 \end{itemize}
600
601 Assuming that you start all your nightly backup jobs at 1:05 am (and that they
602 run one after another), you can do the catalog backup with the following
603 additional Director configuration statements: 
604
605 \footnotesize
606 \begin{verbatim}
607 # Backup the catalog database (after the nightly save)
608 Job {
609   Name = "BackupCatalog"
610   Type = Backup
611   Client=rufus-fd
612   FileSet="Catalog"
613   Schedule = "WeeklyCycleAfterBackup"
614   Storage = DLTDrive
615   Messages = Standard
616   Pool = Default
617   # WARNING!!! Passing the password via the command line is insecure.
618   # see comments in make_catalog_backup for details.
619   RunBeforeJob = "/home/kern/bacula/bin/make_catalog_backup"
620   RunAfterJob  = "/home/kern/bacula/bin/delete_catalog_backup"
621   Write Bootstrap = "/home/kern/bacula/working/BackupCatalog.bsr"
622 }
623 # This schedule does the catalog. It starts after the WeeklyCycle
624 Schedule {
625   Name = "WeeklyCycleAfterBackup
626   Run = Level=Full sun-sat at 1:10
627 }
628 # This is the backup of the catalog
629 FileSet {
630   Name = "Catalog"
631   Include {
632     Options {
633       signature=MD5
634     }
635     File = \lt{}working_directory\gt{}/bacula.sql
636   }
637 }
638 \end{verbatim}
639 \normalsize
640
641 Be sure to write a bootstrap file as in the above example. However, it is preferable
642 to write or copy the bootstrap file to another computer. It will allow
643 you to quickly recover the database backup should that be necessary.  If
644 you do not have a bootstrap file, it is still possible to recover your
645 database backup, but it will be more work and take longer. 
646
647
648 \label{BackingUpBaculaSecurityConsiderations}
649 \section{Security considerations}
650 \index[general]{Backing Up Your Bacula Database - Security Considerations }
651 \index[general]{Database!Backing Up Your Bacula Database - Security Considerations }
652
653 We provide make\_catalog\_backup as an example of what can be used to backup
654 your Bacula database.  We expect you to take security precautions relevant
655 to your situation.  make\_catalog\_backup is designed to take a password on
656 the command line.  This is fine on machines with only trusted users.  It is
657 not acceptable on machines without trusted users.  Most database systems
658 provide a alternative method, which does not place the password on the
659 command line.
660
661 The make\_catalog\_backup script contains some warnings about how to use it. Please
662 read those tips.
663
664 To help you get started, we know PostgreSQL has a password file,
665 \elink{
666 .pgpass}{http://www.postgresql.org/docs/8.2/static/libpq-pgpass.html}, and
667 we know MySQL has
668 \elink{ .my.cnf}{http://dev.mysql.com/doc/refman/4.1/en/password-security.html}.
669
670 Only you can decide what is appropriate for your situation. We have provided
671 you with a starting point.  We hope it helps.
672
673
674 \label{BackingUPOtherDBs}
675 \section{Backing Up Third Party Databases}
676 \index[general]{Backing Up Third Party Databases }
677 \index[general]{Databases!Backing Up Third Party }
678
679 If you are running a database in production mode on your machine, Bacula will
680 happily backup the files, but if the database is in use while Bacula is
681 reading it, you may back it up in an unstable state. 
682
683 The best solution is to shutdown your database before backing it up, or use
684 some tool specific to your database to make a valid live copy perhaps by
685 dumping the database in ASCII format. I am not a database expert, so I cannot
686 provide you advice on how to do this, but if you are unsure about how to
687 backup your database, you might try visiting the Backup Central site, which
688 has been renamed Storage Mountain (www.backupcentral.com). In particular,
689 their 
690 \elink{ Free Backup and Recovery
691 Software}{http://www.backupcentral.com/toc-free-backup-software.html} page has
692 links to scripts that show you how to shutdown and backup most major
693 databases. 
694 \label{Size}
695
696 \section{Database Size}
697 \index[general]{Size!Database }
698 \index[general]{Database Size }
699
700 As mentioned above, if you do not do automatic pruning, your Catalog will grow
701 each time you run a Job. Normally, you should decide how long you want File
702 records to be maintained in the Catalog and set the {\bf File Retention}
703 period to that time. Then you can either wait and see how big your Catalog
704 gets or make a calculation assuming approximately 154 bytes for each File
705 saved and knowing the number of Files that are saved during each backup and
706 the number of Clients you backup. 
707
708 For example, suppose you do a backup of two systems, each with 100,000 files.
709 Suppose further that you do a Full backup weekly and an Incremental every day,
710 and that the Incremental backup typically saves 4,000 files. The size of your
711 database after a month can roughly be calculated as: 
712
713 \footnotesize
714 \begin{verbatim}
715    Size = 154 * No. Systems * (100,000 * 4 + 10,000 * 26)
716 \end{verbatim}
717 \normalsize
718
719 where we have assumed four weeks in a month and 26 incremental backups per month.
720 This would give the following: 
721
722 \footnotesize
723 \begin{verbatim}
724    Size = 154 * 2 * (100,000 * 4 + 10,000 * 26)
725 or
726    Size = 308 * (400,000 + 260,000)
727 or
728    Size = 203,280,000 bytes
729 \end{verbatim}
730 \normalsize
731
732 So for the above two systems, we should expect to have a database size of
733 approximately 200 Megabytes. Of course, this will vary according to how many
734 files are actually backed up. 
735
736 Below are some statistics for a MySQL database containing Job records for five
737 Clients beginning September 2001 through May 2002 (8.5 months) and File
738 records for the last 80 days. (Older File records have been pruned). For these
739 systems, only the user files and system files that change are backed up. The
740 core part of the system is assumed to be easily reloaded from the Red Hat rpms.
741
742
743 In the list below, the files (corresponding to Bacula Tables) with the
744 extension .MYD contain the data records whereas files with the extension .MYI
745 contain indexes. 
746
747 You will note that the File records (containing the file attributes) make up
748 the large bulk of the number of records as well as the space used (459 Mega
749 Bytes including the indexes). As a consequence, the most important Retention
750 period will be the {\bf File Retention} period. A quick calculation shows that
751 for each File that is saved, the database grows by approximately 150 bytes. 
752
753 \footnotesize
754 \begin{verbatim}
755       Size in
756        Bytes   Records    File
757  ============  =========  ===========
758           168          5  Client.MYD
759         3,072             Client.MYI
760   344,394,684  3,080,191  File.MYD
761   115,280,896             File.MYI
762     2,590,316    106,902  Filename.MYD
763     3,026,944             Filename.MYI
764           184          4  FileSet.MYD
765         2,048             FileSet.MYI
766        49,062      1,326  JobMedia.MYD
767        30,720             JobMedia.MYI
768       141,752      1,378  Job.MYD
769        13,312             Job.MYI
770         1,004         11  Media.MYD
771         3,072             Media.MYI
772     1,299,512     22,233  Path.MYD
773       581,632             Path.MYI
774            36          1  Pool.MYD
775         3,072             Pool.MYI
776             5          1  Version.MYD
777         1,024             Version.MYI
778 \end{verbatim}
779 \normalsize
780
781 This database has a total size of approximately 450 Megabytes. 
782
783 If we were using SQLite, the determination of the total database size would be
784 much easier since it is a single file, but we would have less insight to the
785 size of the individual tables as we have in this case. 
786
787 Note, SQLite databases may be as much as 50\% larger than MySQL databases due
788 to the fact that all data is stored as ASCII strings. That is even binary
789 integers are stored as ASCII strings, and this seems to increase the space
790 needed.