I’ve been wanting to write this entry for a long time. The goal is to easily address how to reduce how much disk space you are using for backups. Usually this sort of thing sneaks up on you when you get an email saying the storage daemon is is waiting for you to label a new volume.
You can run out of disk space for a few reasons:
- You actually filled the disk that your backup volumes live on.
- You have set the maximum number of volumes in the pool resource.
This entry will explain everything you need to know to quickly make disk space.
IMPORTANT: One of the most important things to understand about bacula is that under normal circumstances it does not delete backed up data. It will recycle a disk volume (ie re-use it) or it will truncate a disk volume to almost zero but it will NOT remove a disk volume. You have to use operating system commands ( rm ) to accomplish this if it is your goal.
Terms / Quick Tips
- Catalog : This is the database (PostgreSQL or MySQL) that holds all of the metadata about your backups; which files are backedup, how many copies, when.. etc
- File : In this context we mean a file that you’ve backed up.
- Job : A job is a “backup”. Essentially a collection of files you have backed up for a specific client machine.
- Volume : The media to which your backups are stored on. A volume can be a tape, or it can be a file that lives on your system.
- Retention : Bacula has 3 retention times. They are for files, jobs and volumes. Please be absolutely clear on this next sentence; retention time specifies how long records about files/jobs/volumes will be stored in the catalog. It does not relate in any way to the retention of backed up data. That is another step. Keep reading. It should be noted that the retention period count down starts for files and jobs when the last file is written to a volume and for volumes after the append status has been changed to an other status such as full, used or purged.
- Pruning : This action means removing metadata about jobs/files/volumes from the catalog. Usually this is done to manage the size of the catalog. If your catalog gets too large it can impact the speed of backups and restores. Pruning can be done manually or automatically but it always respects retention periods.
- Purging : This action is similar to pruning except it does not respect retention limits in any way. Use this with extreme caution.
- Truncate ( on purge ) : Truncate means to reduce the size of a disk volume to the size of a volume headers. (About 200 bytes). This will reduce consumed disk space on your system but will not delete a volume. After a volume has been marked as purged, you can run the following command manually in bconsole or via a RunScript entery in your Catalogbackup for example. Effecivly it means that each time the catalog is backed up, any purged volumes wil have their size reduced to zero: “purge volume action=truncate storage=File allpools”
- Delete : The delete command goes one step further than purge in so much as it will remove the volume records from the catalog as well.
- Recycle : When a volume is marked as available for recycling it means that bacula is allowed to overwrite anything within this volume. That does NOT mean that the volume is useless, it just means that nothing in the catalog points to it any more. If you are ever suspect that a volume might contain something then before it gets reused, copy it somewhere else and use bscan to scan the contents of the volume. Here are the conditions under which a volume can be recycled
- All retention periods must be expired. Including the volume retention.
- The volume must be pruned.
- Bacula will find the oldest purged volume, if the “can be recycled” flag is set and the file status is NOT Append, then bacula will write new data on this volume.
So the Terms above really do summarize all you need to know but I must recommend the following “light” reading if you really want a solid grasp on things..
*New – Sweet Bacula Cheat Sheet
How to reduce disk usage
This is why you are here, and once you digest the above terms and quick tips, making space in a hurry is really quite simple.
The steps are as follows.
- Find the volume(s) in your pool that was written to the longest time ago.
- Prune those volume, or if you are in a real hurry and very sure of your self just purge them. IE: if you prune them but they hold files who’s retention period have not expired, the volumes will not get marked as purged and will not be able to be safley deleted)
- Decision time
- You can use the “delete” command to delete the volumes (which removes their meta data from the catalog) and then remove them from the file system using ‘rm’
- You can issue “purge volume action=truncate storage=File allpools” which will reduce the size of the volumes to about 200 bytes. This means you regain disk space AND there is an available volume left over for bacula to start putting new data into.
You can accomplish the above steps either manually or you can script them. I’ll leave scripting them an excercise to the reader, however here are some links that do it that you may find useful. If you read the source you’ll very quickly see what they are trying to accomplish.
How to prevent running out of disk space in the first place…
Well, its not rocket science. Math. Essentially you should impose an artificial limit on how much space your bacula volumes can take up. So that in a real pinch you can define an extra volume or 2 to keep backups trucking whilst you do some catalog/volume maintenance. I’m using 10% as an example here, but you can use your own.
"Total Disk space in Gigs" - "10% of total disk space in gigs" = "Space available for backups"
"Space available for backups in gigs" / "Size of volume you select in gigs" = "Max Number of volumes"
Now what do we do with that number? Its really simple, edit the pool definition for where these volumes are stored and add the “Maximum Volume Bytes” and “Maximum Volume” directives. Like this:
Name = File
Pool Type = Backup
Recycle = yes # Bacula can automatically recycle Volumes
AutoPrune = yes # Prune expired volumes
Volume Retention = 6 months
Maximum Volumes = 1600 # Limit number of Volumes in Pool
Maximum Volume Bytes = 5G
Label Format = “002_bacula5_”
Recycle Oldest Volume = yes
Then open up bconsole and type “reload”. Then “update pool” and select your pool. This command will update the catalog with the settings you defined in the director configuration file.