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