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