]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/en/main/recycling.tex
Fix description of Volume Retention -- bug 1844
[bacula/docs] / docs / manuals / en / main / recycling.tex
1 %%
2 %%
3
4 \chapter{Automatic Volume Recycling}
5 \label{RecyclingChapter}
6 \index[general]{Recycling!Automatic Volume }
7 \index[general]{Automatic Volume Recycling }
8
9 By default, once Bacula starts writing a Volume, it can append to the
10 volume, but it will not overwrite the existing data thus destroying it.
11 However when Bacula {\bf recycles} a Volume, the Volume becomes available
12 for being reused, and Bacula can at some later time overwrite the previous
13 contents of that Volume.  Thus all previous data will be lost.  If the
14 Volume is a tape, the tape will be rewritten from the beginning.  If the
15 Volume is a disk file, the file will be truncated before being rewritten.
16
17 You may not want Bacula to automatically recycle (reuse) tapes.  This would
18 require a large number of tapes though, and in such a case, it is possible
19 to manually recycle tapes.  For more on manual recycling, see the section
20 entitled \ilink{Manually Recycling Volumes}{manualrecycling} below in this
21 chapter.
22
23 Most people prefer to have a Pool of tapes that are used for daily backups and
24 recycled once a week, another Pool of tapes that are used for Full backups
25 once a week and recycled monthly, and finally a Pool of tapes that are used
26 once a month and recycled after a year or two. With a scheme like this, the 
27 number of tapes in your pool or pools remains constant.
28
29 By properly defining your Volume Pools with appropriate Retention periods,
30 Bacula can manage the recycling (such as defined above) automatically. 
31
32 Automatic recycling of Volumes is controlled by four records in the {\bf
33 Pool} resource definition in the Director's configuration file. These four
34 records are: 
35
36 \begin{itemize}
37 \item AutoPrune = yes 
38 \item VolumeRetention = \lt{}time\gt{} 
39 \item Recycle = yes
40 \item RecyclePool = \lt{}APool\gt{} %(\textit{This require bacula 2.1.4 or greater})
41 \end{itemize}
42
43 The above three directives are all you need assuming that you fill
44 each of your Volumes then wait the Volume Retention period before 
45 reusing them, providing there is some non-pruned Jobs or Files on the
46 Volume.
47
48 If you want Bacula to stop using a Volume and recycle
49 it before it is full, you will need to use one or more additional 
50 directives such as:
51
52 \begin{itemize}
53 \item Use Volume Once = yes
54 \item Volume Use Duration = ttt
55 \item Maximum Volume Jobs = nnn
56 \item Maximum Volume Bytes = mmm
57 \end{itemize}
58
59 Please see below and 
60 the \ilink{Basic Volume Management}{DiskChapter} chapter
61 of this manual for more complete examples.  
62
63 Automatic recycling of Volumes is performed by Bacula only when it wants a
64 new Volume and no appendable Volumes are available in the Pool. It will then
65 search the Pool for any Volumes with the {\bf Recycle} flag set and the 
66 Volume Status is {\bf Purged}. At that point, it will choose the oldest 
67 purged volume and recycle it.
68
69 If there are no volumes with Status {\bf Purged}, then the recycling occurs
70 in two steps:
71
72 \smallskip
73 The first is that the Catalog for a Volume must be pruned of all Jobs (i.e.
74 Purged) and Files contained on that Volume.
75
76 \smallskip
77 The second step is the actual recycling of the Volume.  Only Volumes marked
78 {\bf Full} or {\bf Used} will be considerd for pruning.  The Volume will be
79 purged if the VolumeRetention period has expired.  When a Volume is marked
80 as Purged, it means that no Catalog records reference that Volume, and the
81 Volume can be recycled and reused even though the Volume Retention period
82 has not expired.  Until recycling actually occurs, the Volume data remains
83 intact.  If no Volumes can be found for recycling for any of the reasons
84 stated above, Bacula will request operator intervention (i.e.  it will ask
85 you to label a new volume).
86
87 A key point mentioned above, that can be a source of frustration, is that
88 Bacula will only recycle purged Volumes if there is no other appendable
89 Volume available, otherwise, it will always write to an appendable Volume
90 before recycling even if there are Volume marked as Purged.  This preserves
91 your data as long as possible.  So, if you wish to "force" Bacula to use a
92 purged Volume, you must first ensure that no other Volume in the Pool is
93 marked {\bf Append}.  If necessary, you can manually set a volume to {\bf
94 Full}.  The reason for this is that Bacula wants to preserve the data on
95 your old tapes (even though purged from the catalog) as long as absolutely
96 possible before overwriting it.  There are also a number of directives such
97 as
98 {\bf Volume Use Duration} that will automatically mark a volume as {\bf
99 Used} and thus no longer appendable.
100
101 \label{AutoPruning}
102 \section{Automatic Pruning}
103 \index[general]{Automatic Pruning}
104 \index[general]{Pruning!Automatic}
105
106 As Bacula writes files to tape, it keeps a list of files, jobs, and volumes
107 in a database called the catalog.  Among other things, the database helps
108 Bacula to decide which files to back up in an incremental or differential
109 backup, and helps you locate files on past backups when you want to restore
110 something.  However, the catalog will grow larger and larger as time goes
111 on, and eventually it can become unacceptably large.
112
113 Bacula's process for removing entries from the catalog is called Pruning.
114 The default is Automatic Pruning, which means that once a Job record
115 reaches a certain age (e.g.  30 days old) and a pruning occurs, it will be
116 removed from the catalog.  Note that Job records that are required for
117 current restore won't be removed automatically, and File records are needed
118 for VirtualFull and Accurate backups.  Once a job has been pruned, you can
119 still restore it from the backup Volume, provided that the Volume has not
120 been recycled, but one additional step is required: scanning the volume
121 with bscan.  The alternative to Automatic Pruning is Manual Pruning, in
122 which you explicitly tell Bacula to erase the catalog entries for a volume.
123 You'd usually do this when you want to reuse a Bacula volume, because
124 there's no point in keeping a list of files that USED TO BE on a volume.
125 Or, if the catalog is starting to get too big, you could prune the oldest
126 jobs to save space.  Manual pruning is done with the
127 \borgxrlink{prune}{ManualPruning}{console}{command} in the \consoleman{}
128  (thanks to Bryce Denney for the above explanation).
129
130 \section{Pruning Directives}
131 \index[general]{Pruning Directives }
132 \index[general]{Directives!Pruning }
133
134 There are three pruning durations.  All apply to catalog database records
135 and not to the actual data in a Volume.  The pruning (or retention)
136 durations are for: Volumes (Media records), Jobs (Job records), and Files
137 (File records).  The durations inter-depend a bit because if Bacula prunes
138 a Volume, it automatically removes all the Job records, and all the File
139 records.  Also when a Job record is pruned, all the File records for that
140 Job are also pruned (deleted) from the catalog.
141
142 Having the File records in the database means that you can examine all the
143 files backed up for a particular Job. They take the most space in the catalog
144 (probably 90-95\% of the total). When the File records are pruned, the Job
145 records can remain, and you can still examine what Jobs ran, but not the
146 details of the Files backed up. In addition, without the File records, you
147 cannot use the Console restore command to restore the files. 
148
149 When a Job record is pruned, the Volume (Media record) for that Job can still
150 remain in the database, and if you do a "list volumes", you will see the
151 volume information, but the Job records (and its File records) will no longer
152 be available. 
153
154 In each case, pruning removes information about where older files are, but it
155 also prevents the catalog from growing to be too large. You choose the
156 retention periods in function of how many files you are backing up and the
157 time periods you want to keep those records online, and the size of the
158 database. You can always re-insert the records (with 98\% of the original data)
159 by using "bscan" to scan in a whole Volume or any part of the volume that
160 you want. 
161
162 By setting {\bf AutoPrune} to {\bf yes} you will permit {\bf Bacula} to
163 automatically prune all Volumes in the Pool when a Job needs another Volume.
164 Volume pruning means removing records from the catalog. It does not shrink the
165 size of the Volume or affect the Volume data until the Volume gets
166 overwritten. When a Job requests another volume and there are no Volumes with
167 Volume Status {\bf Append} available, Bacula will begin volume pruning. This
168 means that all Jobs that are older than the {\bf VolumeRetention} period will
169 be pruned from every Volume that has Volume Status {\bf Full} or {\bf Used}
170 and has Recycle set to {\bf yes}. Pruning consists of deleting the
171 corresponding Job, File, and JobMedia records from the catalog database. No
172 change to the physical data on the Volume occurs during the pruning process.
173 When all files are pruned from a Volume (i.e. no records in the catalog), the
174 Volume will be marked as {\bf Purged} implying that no Jobs remain on the
175 volume. The Pool records that control the pruning are described below. 
176
177 \begin{description}
178
179 \item [AutoPrune = \lt{}yes|no\gt{}]
180    \index[console]{AutoPrune  }
181    If AutoPrune is set to  {\bf yes} (default), Bacula
182    will  automatically apply the Volume retention period when running a Job  and
183    it needs a new Volume but no appendable volumes are available.  At that point,
184    Bacula will prune all Volumes that can be pruned  (i.e. AutoPrune set) in an
185    attempt to find a usable volume. If  during the autoprune, all files are
186    pruned from the Volume, it  will be marked with VolStatus {\bf Purged}.  The
187    default is {\bf yes}. Note, that although the File and Job records may be 
188    pruned from the catalog, a Volume will be marked Purged (and hence 
189    ready for recycling) if the Volume status is Append, Full, Used, or Error.
190    If the Volume has another status, such as Archive, Read-Only, Disabled,
191    Busy, or Cleaning, the Volume status will not be changed to Purged.
192
193 \item [Volume Retention = \lt{}time-period-specification\gt{}]
194    \index[console]{Volume Retention}
195    The Volume Retention record defines the length of time that Bacula will
196    guarantee that the Volume is not reused counting from the time the last
197    job stored on the Volume terminated, providing that all the File records
198    on the Volume have not been pruned.  A key point is that this time
199    period is not even considered as long at the Volume remains appendable.
200    The Volume Retention period count down begins only when the Append
201    status has been changed to some othe status (Full, Used, Purged, ...).
202    Note, when all the File records have been removed that are on the
203    Volume, the Volume will marked Purged (i.e. it has no more valid
204    Files stored on it), and the Volume may be recycled even if the Volume
205    Retention period has not expired.
206
207    When this time period expires, and if {\bf AutoPrune} is set to {\bf
208    yes}, and a new Volume is needed, but no appendable Volume is available,
209    Bacula will prune (remove) Job records that are older than the specified
210    Volume Retention period even if the Job or File retention has not been
211    reached.
212
213    The Volume Retention period takes precedence over any Job Retention
214    period you have specified in the Client resource.  It should also be
215    noted, that the Volume Retention period is obtained by reading the
216    Catalog Database Media record rather than the Pool resource record.
217    This means that if you change the VolumeRetention in the Pool resource
218    record, you must ensure that the corresponding change is made in the
219    catalog by using the {\bf update pool} command.  Doing so will insure
220    that any new Volumes will be created with the changed Volume Retention
221    period.  Any existing Volumes will have their own copy of the Volume
222    Retention period that can only be changed on a Volume by Volume basis
223    using the {\bf update volume} command.
224
225    When all file catalog entries are removed from the volume,  its VolStatus is
226    set to {\bf Purged}. The files remain physically  on the Volume until the
227    volume is overwritten.  
228
229    Retention periods are specified in seconds,  minutes, hours, days, weeks,
230    months,  quarters, or years on the record. See the  
231    \ilink{Configuration chapter}{Time} of this  manual for
232    additional details of time specification.  
233
234 The default is 1 year. 
235 % TODO: if that is the format, should it be in quotes? decide on a style
236
237 \item [Recycle = \lt{}yes|no\gt{}]
238    \index[fd]{Recycle  }
239    This statement tells Bacula whether or not the particular Volume can be
240    recycled (i.e.  rewritten).  If Recycle is set to {\bf no} (the
241    default), then even if Bacula prunes all the Jobs on the volume and it
242    is marked {\bf Purged}, it will not consider the tape for recycling.  If
243    Recycle is set to {\bf yes} and all Jobs have been pruned, the volume
244    status will be set to {\bf Purged} and the volume may then be reused
245    when another volume is needed.  If the volume is reused, it is relabeled
246    with the same Volume Name, however all previous data will be lost.
247    \end{description}
248
249    It is also possible to "force" pruning of all Volumes in the Pool
250    associated with a Job by adding {\bf Prune Files = yes} to the Job resource. 
251
252 \label{Recycling}
253 \label{RecyclingAlgorithm}
254 \section{Recycling Algorithm}
255 \index[general]{Algorithm!Recycling }
256 \index[general]{Recycling Algorithm }
257
258 After all Volumes of a Pool have been pruned (as mentioned above, this happens
259 when a Job needs a new Volume and no appendable Volumes are available), Bacula
260 will look for the oldest Volume that is Purged (all Jobs and Files expired),
261 and if the {\bf Recycle} flag is on (Recycle=yes) for that Volume, Bacula will
262 relabel it and write new data on it. 
263
264 As mentioned above, there are two key points for getting a Volume
265 to be recycled. First, the Volume must no longer be marked Append (there
266 are a number of directives to automatically make this change), and second
267 since the last write on the Volume, one or more of the Retention periods
268 must have expired so that there are no more catalog backup job records
269 that reference that Volume.  Once both those conditions are satisfied,
270 the volume can be marked Purged and hence recycled.
271
272 The full algorithm that Bacula uses when it needs a new Volume is: 
273 \index[general]{New Volume Algorithm}
274 \index[general]{Algorithm!New Volume}
275
276 The algorithm described below assumes that AutoPrune is enabled,
277 that Recycling is turned on, and that you have defined
278 appropriate Retention periods, or used the defaults for all these
279 items. 
280
281 \begin{itemize}
282 \item If the request is for an Autochanger device, look only
283    for Volumes in the Autochanger (i.e. with InChanger set and that have
284    the correct Storage device).        
285 \item Search the Pool for a Volume with VolStatus=Append (if there is more
286    than one, the Volume with the oldest date last written is chosen.  If
287    two have the same date then the one with the lowest MediaId is chosen).
288 \item Search the Pool for a Volume with VolStatus=Recycle and the InChanger
289    flag is set true (if there is more than one, the Volume with the oldest
290    date last written is chosen.  If two have the same date then the one
291    with the lowest MediaId is chosen).
292 \item Try recycling any purged Volumes.
293 \item Prune volumes applying Volume retention period (Volumes with VolStatus 
294    Full, Used, or Append are pruned). Note, when all the File and Job
295    records are pruned from a Volume, the Volume may be marked Purged
296    prior to the expiration of the Volume retention period.
297 \item Search the Pool for a Volume with VolStatus=Purged 
298 \item If a Pool named "Scratch" exists, search for a Volume and if found
299    move it to the current Pool for the Job and use it. Note, when
300    the Scratch Volume is moved into the current Pool, the basic
301    Pool defaults are applied as if it is a newly labeled Volume
302    (equivalent to an {\bf update volume from pool} command).
303 \item If we were looking for Volumes in the Autochanger, go back to
304    step 2 above, but this time, look for any Volume whether or not
305    it is in the Autochanger.                   
306 \item Attempt to create a new Volume if automatic labeling is enabled.
307    However, if the maximum number of Volumes
308    specified for the pool is reached, a new Volume will not be created.
309 \item Prune the oldest Volume if RecycleOldestVolume=yes (the Volume with the
310    oldest LastWritten date and VolStatus equal to  Full, Recycle, Purged, Used,
311    or Append is chosen). This  record ensures that all retention periods are
312    properly respected. 
313 \item Purge the oldest Volume if PurgeOldestVolume=yes (the Volume  with the
314    oldest LastWritten date and VolStatus equal to  Full, Recycle, Purged, Used,
315    or Append is chosen). We strongly  recommend against the use of {\bf
316    PurgeOldestVolume} as it can quite easily lead to loss of current backup
317    data. 
318 \item Give up and ask operator. 
319 \end{itemize}
320
321 The above occurs when Bacula has finished writing a Volume or when no Volume
322 is present in the drive. 
323
324 On the other hand, if you have inserted a different Volume after the last job,
325 and Bacula recognizes the Volume as valid, it will request authorization from
326 the Director to use this Volume. In this case, if you have set {\bf Recycle
327 Current Volume = yes} and the Volume is marked as Used or Full, Bacula will
328 prune the volume and if all jobs were removed during the pruning (respecting
329 the retention periods), the Volume will be recycled and used. 
330
331 The recycling algorithm in this case is: 
332 \begin{itemize}
333 \item If the VolStatus is {\bf Append} or {\bf Recycle} 
334    is set, the volume  will be used.  
335 \item If {\bf Recycle Current Volume} is set and the  volume is marked {\bf
336    Full} or {\bf Used}, Bacula  will prune the volume (applying the retention
337    period).  If all Jobs are pruned from the volume, it will be  recycled. 
338 \end{itemize}
339
340 This permits users to manually change the Volume every day and load tapes in
341 an order different from what is in the catalog, and if the volume does not
342 contain a current copy of your backup data, it will be used. 
343
344 A few points from Alan Brown to keep in mind:
345
346 \begin{enumerate}
347 \item If a pool doesn't have maximum volumes defined then Bacula will prefer to 
348   demand new volumes over forcibly purging older volumes.
349
350 \item If volumes become free through pruning and the Volume retention period has
351   expired, then they get marked as "purged" and are immediately available for
352   recycling - these will be used in preference to creating new volumes.
353
354 \item If the Job, File, and Volume retention periods are different, then
355   it's common to see a tape with no files or jobs listed in the database,
356   but which is still not marked as "purged".
357 \end{enumerate}
358
359
360 \section{Recycle Status}
361 \index[general]{Status!Recycle }
362 \index[general]{Recycle Status }
363
364 Each Volume inherits the Recycle status (yes or no) from the Pool resource
365 record when the Media record is created (normally when the Volume is labeled).
366 This Recycle status is stored in the Media record of the Catalog. Using
367 the Console program, you may subsequently change the Recycle status for each
368 Volume. For example in the following output from {\bf list volumes}: 
369
370 \footnotesize
371 \begin{verbatim}
372 +----------+-------+--------+---------+------------+--------+-----+
373 | VolumeNa | Media | VolSta | VolByte | LastWritte | VolRet | Rec |
374 +----------+-------+--------+---------+------------+--------+-----+
375 | File0001 | File  | Full   | 4190055 | 2002-05-25 | 14400  | 1   |
376 | File0002 | File  | Full   | 1896460 | 2002-05-26 | 14400  | 1   |
377 | File0003 | File  | Full   | 1896460 | 2002-05-26 | 14400  | 1   |
378 | File0004 | File  | Full   | 1896460 | 2002-05-26 | 14400  | 1   |
379 | File0005 | File  | Full   | 1896460 | 2002-05-26 | 14400  | 1   |
380 | File0006 | File  | Full   | 1896460 | 2002-05-26 | 14400  | 1   |
381 | File0007 | File  | Purged | 1896466 | 2002-05-26 | 14400  | 1   |
382 +----------+-------+--------+---------+------------+--------+-----+
383 \end{verbatim}
384 \normalsize
385
386 all the volumes are marked as recyclable, and the last Volume, {\bf
387 File0007} has been purged, so it may be immediately recycled.  The other
388 volumes are all marked recyclable and when their Volume Retention period
389 (14400 seconds or four hours) expires, they will be eligible for pruning,
390 and possibly recycling.  Even though Volume {\bf File0007} has been purged,
391 all the data on the Volume is still recoverable.  A purged Volume simply
392 means that there are no entries in the Catalog.  Even if the Volume Status
393 is changed to {\bf Recycle}, the data on the Volume will be recoverable.
394 The data is lost only when the Volume is re-labeled and re-written.
395
396 To modify Volume {\bf File0001} so that it cannot be recycled, you use the
397 {\bf update volume pool=File} command in the console program, or simply {\bf
398 update} and Bacula will prompt you for the information. 
399
400 \footnotesize
401 \begin{verbatim}
402 +----------+------+-------+---------+-------------+-------+-----+
403 | VolumeNa | Media| VolSta| VolByte | LastWritten | VolRet| Rec |
404 +----------+------+-------+---------+-------------+-------+-----+
405 | File0001 | File | Full  | 4190055 | 2002-05-25  | 14400 | 0   |
406 | File0002 | File | Full  | 1897236 | 2002-05-26  | 14400 | 1   |
407 | File0003 | File | Full  | 1896460 | 2002-05-26  | 14400 | 1   |
408 | File0004 | File | Full  | 1896460 | 2002-05-26  | 14400 | 1   |
409 | File0005 | File | Full  | 1896460 | 2002-05-26  | 14400 | 1   |
410 | File0006 | File | Full  | 1896460 | 2002-05-26  | 14400 | 1   |
411 | File0007 | File | Purged| 1896466 | 2002-05-26  | 14400 | 1   |
412 +----------+------+-------+---------+-------------+-------+-----+
413 \end{verbatim}
414 \normalsize
415
416 In this case, {\bf File0001} will never be automatically recycled. The same
417 effect can be achieved by setting the Volume Status to Read-Only. 
418
419 As you have noted, the Volume Status (VolStatus) column in the 
420 catalog database contains the current status of the Volume, which
421 is normally maintained automatically by Bacula. To give you an
422 idea of some of the values it can take during the life cycle of
423 a Volume, here is a picture created by Arno Lehmann:
424
425 \footnotesize
426 \begin{verbatim}
427 A typical volume life cycle is like this:
428
429               because job count or size limit exceeded
430       Append  ---------------------------------------->  Used
431         ^                                                  |
432         | First Job writes to        Retention time passed |
433         | the volume                   and recycling takes |
434         |                                            place |
435         |                                                  v
436       Recycled <-------------------------------------- Purged
437                      Volume is selected for reuse
438
439 \end{verbatim}
440 \normalsize
441
442
443 \section{Making Bacula Use a Single Tape}
444 \label{singletape}
445 \index[general]{Tape!Making Bacula Use a Single}
446 \index[general]{Making Bacula Use a Single Tape}
447
448 Most people will want Bacula to fill a tape and when it is full, a new tape
449 will be mounted, and so on.  However, as an extreme example, it is possible
450 for Bacula to write on a single tape, and every night to rewrite it.  To
451 get this to work, you must do two things: first, set the VolumeRetention to
452 less than your save period (one day), and the second item is to make Bacula
453 mark the tape as full after using it once.  This is done using {\bf
454 UseVolumeOnce = yes}.  If this latter record is not used and the tape is
455 not full after the first time it is written, Bacula will simply append to
456 the tape and eventually request another volume.  Using the tape only once,
457 forces the tape to be marked
458 {\bf Full} after each use, and the next time {\bf Bacula} runs, it will
459 recycle the tape. 
460
461 An example Pool resource that does this is: 
462
463 \footnotesize
464 \begin{verbatim}
465 Pool {
466   Name = DDS-4
467   Use Volume Once = yes
468   Pool Type = Backup
469   AutoPrune = yes
470   VolumeRetention = 12h # expire after 12 hours
471   Recycle = yes
472 }
473 \end{verbatim}
474 \normalsize
475
476 \section{Daily, Weekly, Monthly Tape Usage Example}
477 \label{usageexample}
478 \index[general]{Daily, Weekly, Monthly Tape Usage Example }
479 \index[general]{Example!Daily Weekly Monthly Tape Usage }
480
481 This example is meant to show you how one could define a fixed set of volumes
482 that Bacula will rotate through on a regular schedule. There are an infinite
483 number of such schemes, all of which have various advantages and
484 disadvantages. 
485
486 We start with the following assumptions: 
487
488 \begin{itemize}
489 \item A single tape has more than enough capacity to do  a full save.  
490 \item There are ten tapes that are used on a daily basis  for incremental
491    backups. They are prelabeled Daily1 ...  Daily10.  
492 \item There are four tapes that are used on a weekly basis  for full backups.
493    They are labeled Week1 ... Week4.  
494 \item There are 12 tapes that are used on a monthly basis  for full backups.
495    They are numbered Month1 ... Month12  
496 \item A full backup is done every Saturday evening (tape inserted  Friday
497    evening before leaving work).  
498 \item No backups are done over the weekend (this is easy to  change).  
499 \item The first Friday of each month, a Monthly tape is used for  the Full
500    backup.  
501 \item Incremental backups are done Monday - Friday (actually  Tue-Fri
502    mornings). 
503 % TODO: why this "actually"? does this need to be explained?
504    \end{itemize}
505
506 We start the system by doing a Full save to one of the weekly volumes or one
507 of the monthly volumes. The next morning, we remove the tape and insert a
508 Daily tape. Friday evening, we remove the Daily tape and insert the next tape
509 in the Weekly series. Monday, we remove the Weekly tape and re-insert the
510 Daily tape. On the first Friday of the next month, we insert the next Monthly
511 tape in the series rather than a Weekly tape, then continue. When a Daily tape
512 finally fills up, {\bf Bacula} will request the next one in the series, and
513 the next day when you notice the email message, you will mount it and {\bf
514 Bacula} will finish the unfinished incremental backup. 
515
516 What does this give? Well, at any point, you will have the last complete
517 Full save plus several Incremental saves. For any given file you want to
518 recover (or your whole system), you will have a copy of that file every day
519 for at least the last 14 days. For older versions, you will have at least three
520 and probably four Friday full saves of that file, and going back further, you
521 will have a copy of that file made on the beginning of the month for at least
522 a year. 
523
524 So you have copies of any file (or your whole system) for at least a year, but
525 as you go back in time, the time between copies increases from daily to weekly
526 to monthly. 
527
528 What would the Bacula configuration look like to implement such a scheme? 
529
530 \footnotesize
531 \begin{verbatim}
532 Schedule {
533   Name = "NightlySave"
534   Run = Level=Full Pool=Monthly 1st sat at 03:05
535   Run = Level=Full Pool=Weekly 2nd-5th sat at 03:05
536   Run = Level=Incremental Pool=Daily tue-fri at 03:05
537 }
538 Job {
539   Name = "NightlySave"
540   Type = Backup
541   Level = Full
542   Client = LocalMachine
543   FileSet = "File Set"
544   Messages = Standard
545   Storage = DDS-4
546   Pool = Daily
547   Schedule = "NightlySave"
548 }
549 # Definition of file storage device
550 Storage {
551   Name = DDS-4
552   Address = localhost
553   SDPort = 9103
554   Password = XXXXXXXXXXXXX
555   Device = FileStorage
556   Media Type = 8mm
557 }
558 FileSet {
559   Name = "File Set"
560   Include { 
561     Options { signature=MD5 }
562     File = fffffffffffffffff
563   }
564   Exclude  { File=*.o }
565 }
566 Pool {
567   Name = Daily
568   Pool Type = Backup
569   AutoPrune = yes
570   VolumeRetention = 10d   # recycle in 10 days
571   Maximum Volumes = 10
572   Recycle = yes
573 }
574 Pool {
575   Name = Weekly
576   Use Volume Once = yes
577   Pool Type = Backup
578   AutoPrune = yes
579   VolumeRetention = 30d  # recycle in 30 days (default)
580   Recycle = yes
581 }
582 Pool {
583   Name = Monthly
584   Use Volume Once = yes
585   Pool Type = Backup
586   AutoPrune = yes
587   VolumeRetention = 365d  # recycle in 1 year
588   Recycle = yes
589 }
590 \end{verbatim}
591 \normalsize
592
593 \section{ Automatic Pruning and Recycling Example}
594 \label{PruningExample}
595 \index[general]{Automatic Pruning and Recycling Example }
596 \index[general]{Example!Automatic Pruning and Recycling }
597
598 Perhaps the best way to understand the various resource records that come into
599 play during automatic pruning and recycling is to run a Job that goes through
600 the whole cycle. If you add the following resources to your Director's
601 configuration file: 
602
603 \footnotesize
604 \begin{verbatim}
605 Schedule {
606   Name = "30 minute cycle"
607   Run = Level=Full Pool=File Messages=Standard Storage=File
608          hourly at 0:05
609   Run = Level=Full Pool=File Messages=Standard Storage=File
610          hourly at 0:35
611 }
612 Job {
613   Name = "Filetest"
614   Type = Backup
615   Level = Full
616   Client=XXXXXXXXXX
617   FileSet="Test Files"
618   Messages = Standard
619   Storage = File
620   Pool = File
621   Schedule = "30 minute cycle"
622 }
623 # Definition of file storage device
624 Storage {
625   Name = File
626   Address = XXXXXXXXXXX
627   SDPort = 9103
628   Password = XXXXXXXXXXXXX
629   Device = FileStorage
630   Media Type = File
631 }
632 FileSet {
633   Name = "File Set"
634   Include { 
635     Options { signature=MD5 }
636     File = fffffffffffffffff
637   }
638   Exclude  { File=*.o }
639 }
640 Pool {
641   Name = File
642   Use Volume Once = yes
643   Pool Type = Backup
644   LabelFormat = "File"
645   AutoPrune = yes
646   VolumeRetention = 4h
647   Maximum Volumes = 12
648   Recycle = yes
649 }
650 \end{verbatim}
651 \normalsize
652
653 Where you will need to replace the {\bf ffffffffff}'s by the appropriate files
654 to be saved for your configuration. For the FileSet Include, choose a
655 directory that has one or two megabytes maximum since there will probably be
656 approximately eight copies of the directory that {\bf Bacula} will cycle through. 
657
658 In addition, you will need to add the following to your Storage daemon's
659 configuration file: 
660
661 \footnotesize
662 \begin{verbatim}
663 Device {
664   Name = FileStorage
665   Media Type = File
666   Archive Device = /tmp
667   LabelMedia = yes;
668   Random Access = Yes;
669   AutomaticMount = yes;
670   RemovableMedia = no;
671   AlwaysOpen = no;
672 }
673 \end{verbatim}
674 \normalsize
675
676 With the above resources, Bacula will start a Job every half hour that saves a
677 copy of the directory you chose to /tmp/File0001 ... /tmp/File0012. After 4
678 hours, Bacula will start recycling the backup Volumes (/tmp/File0001 ...). You
679 should see this happening in the output produced. Bacula will automatically
680 create the Volumes (Files) the first time it uses them. 
681
682 To turn it off, either delete all the resources you've added, or simply
683 comment out the {\bf Schedule} record in the {\bf Job} resource. 
684
685 \section{Manually Recycling Volumes}
686 \label{manualrecycling}
687 \index[general]{Volumes!Manually Recycling }
688 \index[general]{Manually Recycling Volumes }
689
690 Although automatic recycling of Volumes is implemented in version 1.20 and
691 later (see the 
692 \ilink{Automatic Recycling of Volumes}{RecyclingChapter} chapter of
693 this manual), you may want to manually force reuse (recycling) of a Volume. 
694
695 Assuming that you want to keep the Volume name, but you simply want to write
696 new data on the tape, the steps to take are: 
697
698 \begin{itemize}
699 \item Use the {\bf update volume} command in the Console to  ensure that the
700    {\bf Recycle} field is set to {\bf 1}  
701 \item Use the {\bf purge jobs volume} command in the Console  to mark the
702    Volume as {\bf Purged}. Check by using  {\bf list volumes}. 
703 \end{itemize}
704
705 Once the Volume is marked Purged, it will be recycled the next time a Volume
706 is needed. 
707
708 If you wish to reuse the tape by giving it a new name, follow the following
709 steps: 
710
711 \begin{itemize}
712 \item Use the {\bf purge jobs volume} command in the Console  to mark the
713    Volume as {\bf Purged}. Check by using  {\bf list volumes}.  
714 \item In Bacula version 1.30 or greater, use the Console  {\bf relabel}
715    command to relabel the Volume. 
716 \end{itemize}
717
718 Please note that the relabel command applies only to tape Volumes. 
719
720 For Bacula versions prior to 1.30 or to manually relabel the Volume, use the
721 instructions below: 
722
723 \begin{itemize}
724 \item Use the {\bf delete volume} command in the Console  to delete the Volume
725    from the Catalog.  
726 \item If a different tape is mounted, use the {\bf unmount}  command,
727    remove the tape, and insert the tape to be  renamed.  
728 \item Write an EOF mark in the tape using the following  commands: 
729
730 \footnotesize
731 \begin{verbatim}
732   mt -f /dev/nst0 rewind
733   mt -f /dev/nst0 weof
734 \end{verbatim}
735 \normalsize
736
737 where you replace {\bf /dev/nst0} with the appropriate  device name on your
738 system.  
739 \item Use the {\bf label} command to write a new label to  the tape and to
740    enter it in the catalog. 
741 \end{itemize}
742
743 Please be aware that the {\bf delete} command can be dangerous. Once it is
744 done, to recover the File records, you must either restore your database as it
745 was before the {\bf delete} command, or use the {\bf bscan} utility program to
746 scan the tape and recreate the database entries.