I wrote a little bash script that demonstrates how to query to bacula tables in postgresql database and purge volumes for a given job. The same can be accomplished for mysql
In the example below, I am searching for job ID 8431.
-----------code-----------------
#!/bin/bash
volumes=`psql -U bacula bacula -c "select distinct media.volumename from media,jobmedia where jobmedia.mediaid = media.mediaid and jobmedia.jobid=8431 order by media.volumename;" | grep -v volumename | grep -v '(' | grep -v '-'`
for vol in $volumes
do
echo "Purging volume $vol"
/usr/sbin/bconsole << EOF
purge volume=$vol
EOF