#! /bin/sh
BCSCRIPT=/tmp/bconsolescript
QUERY="SELECT volumename FROM media ORDER BY volumename ASC;"
rm -f "$BCSCRIPT"
for vol in `su  -c 'psql -c "$QUERY" bacula' postgres | tail -n +3 | head -n -2` ; do 
    echo "prune volume=$vol yes" >>"$BCSCRIPT" ;
done
for storage in `echo ".storage" | bconsole -n | grep 'File'` ; do 
    echo "purge volume action=all storage=$storage allpools" >>"$BCSCRIPT" ;
done
bconsole -n <"$BCSCRIPT" >/dev/null


