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