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