Recycling Algorithm

When a Job needs a Volume and no appendable, recycled or purged is available, Bacula starts the recycling algorithm pruning Jobs and Files for the oldest Volume in the pool used by the job. After the Volume is pruned, and if the Recycle flag is on (Recycle=yes) for that Volume, Bacula will relabel it and write new data on it.

As mentioned above, there are two key points for getting a Volume to be recycled. First, the Volume must no longer be marked Append (there are a number of directives to automatically make this change), and second since the last write on the Volume, one or more of the Retention periods must have expired so that there are no more catalog backup job records that reference that Volume. Once both those conditions are satisfied, the volume can be marked Purged and hence recycled.

The algorithm described below assumes that AutoPrune is enabled, that Recycling is turned on, and that you have defined appropriate Retention periods, or used the defaults for all these items.

  • If the request is for an Autochanger device, look only for Volumes in the Autochanger (i.e. with InChanger set and that have the correct Storage device).

  • Search the Pool for a Volume with VolStatus=Append (if there is more than one, the Volume with the oldest date last written is chosen. If two have the same date then the one with the lowest MediaId is chosen).

  • Search the Pool for a Volume with VolStatus=Recycle and the InChanger flag is set true (if there is more than one, the Volume with the oldest date last written is chosen. If two have the same date then the one with the lowest MediaId is chosen).

  • Search the Pool for a Volume with VolStatus=Purged and try recycling any purged Volumes.

  • Prune volumes applying Volume retention period (Volumes with VolStatus or are pruned). Note, when all the File and Job records are pruned from a Volume, the Volume will be marked and this may be prior to the expiration of the Volume retention period.

  • Prune the oldest Volume if RecycleOldestVolume=yes (the Volume with the oldest LastWritten date and VolStatus equal to or is chosen). This record ensures that all retention periods are properly respected.

  • Purge the oldest Volume if PurgeOldestVolume=yes (the Volume with the oldest LastWritten date and VolStatus equal to or is chosen). We strongly recommend against the use of PurgeOldestVolume as it can quite easily lead to loss of current backup data.

  • Search for a Volume in the Scratch Pool (the default Scratch pool or another Scratch Pool defined for the pool) and if found move it to the current Pool for the Job and use it. Note, when the Scratch Volume is moved into the current Pool, the basic Pool defaults are applied as if it is a newly labeled Volume (equivalent to an update volume from pool command).

  • If we were looking for Volumes in the Autochanger, go back to step 2 above, but this time, look for any Volume whether or not it is in the Autochanger.

  • Attempt to create a new Volume if automatic labeling is enabled and the maximum number of Volumes is not reached.

  • Give up and ask operator.

The above occurs when Bacula has finished writing a Volume or when no Volume is present in the drive.

On the other hand, if you have inserted a different Volume after the last job, and Bacula recognizes the Volume as valid, the Storage daemon will request authorization from the Director to use this Volume. In this case, if you have set Recycle CurrentVolume=yes and the Volume is marked as Used or Full, Bacula will prune the volume and if all jobs were removed during the pruning (respecting the retention periods), the Volume will be recycled and re-used.

If you want to strictly observe the Volume Retention Period under all circumstances – i.e. you have a Volume with critical data, you must set Recycle=no. However, in doing so, you must manually do the recycling of the Volume for it to be used again.

The recycling algorithm in this case is:

  • If the VolStatus is Append or Recycle is set, the volume will be used.

  • If Recycle Current Volume is set and the volume is marked, or Bacula will prune the volume (applying the retention period). If all Jobs are pruned from the volume, it will be recycled.

This permits users to manually change the Volume every day and load volumes in an order different from what is in the catalog, and if the volume does not contain a current copy of your backup data, it will be used.

A few points to keep in mind:

  1. If a pool doesn’t have maximum volumes defined then Bacula will prefer to demand new volumes over forcibly purging older volumes.

  2. If volumes become free through pruning, then they get marked as and are immediately available for recycling – these will be used in preference to creating new volumes.

  3. If the Job, File, and Volume retention periods are different, then it’s common to see a volume with no files or jobs listed in the database, but which is still not marked as Purged, if Autoprune is set to no in the pool resource.

See also

Go to Recycle Status.

Go back to the Volume Recycling chapter.

Go back to the Storage Space Management chapter.

Go back to the main Bacula Enterprise chapter.