Last active
March 5, 2025 09:54
-
-
Save zentavr/f597c81036e02432f38687e1386c46d5 to your computer and use it in GitHub Desktop.
Prune && Truncate unused File Media Volumes in Bacula
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hints: | |
* https://rem.co/blog/2015/01/15/bacula-purging-and-deleting-old-volumes/index.html | |
# List Volumes | |
list volumes | |
list volumes pool="File Pool one for percona-3.ti.local" | |
# Update pool | |
update pool="MySQL Pool for percona-1.ti.local" | |
# Update volumes (just put `update` and follow the wizard) | |
# Purges the volumes | |
prune expired volume=* yes | |
# Frees the size on disk | |
truncate mediatype=File allpools storage="FS_on_backup.ti.local" | |
# Delete volume from catalog | |
delete volume=Files-one--svn.servupdate.com-0582 yes | |
# Delete volume from catalog in bash | |
for vol in $(echo 'list volumes pool="File Pool DRBD-Drive for docker.servupdate.com"' | bconsole | grep "^|.*Purged" | awk -F'|' '{ print $3 }'); do echo "Dropping $vol"; echo "delete volume=$vol yes" | bconsole; done | |
# Drop files on the disk less than 4k: | |
find . -type f -size -4096c -name '*svn.example.com*' -print0 | xargs -0 rm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Current script purges and deletes the volumes of Bacula which are expired. | |
set -e | |
set -x | |
DATADIR=$1 | |
if [[ -z "${DATADIR}" ]]; then | |
echo "No datadir was provided" | |
exit 1 | |
fi | |
if [[ ! -d "${DATADIR}" ]]; then | |
echo "No datadir is available" | |
exit 1 | |
fi | |
BCONSOLE=$(which bconsole) | |
POOLS=$(echo "list volumes" | ${BCONSOLE} | egrep "^Pool:" | sed 's/^Pool: //g') | |
( | |
IFS=$'\n' | |
for POOL in ${POOLS}; do | |
echo "Updating pool -> \"${POOL}\"" | |
echo "update pool=\"${POOL}\"" | ${BCONSOLE} 1>/dev/null | |
done | |
) | |
# 14: All Volumes from all Pools | |
echo "Updating all volumes from all pools" | |
${BCONSOLE} 1>/dev/null <<DATA | |
update volume | |
14 | |
DATA | |
echo "Purging all expired volumed" | |
echo "prune expired volume=* yes" | ${BCONSOLE} 1>/dev/null | |
( | |
IFS=$'\n' | |
for POOL in ${POOLS}; do | |
echo "Modifying the pool -> ${POOL}" | |
PURGED_VOLUMES=$(echo "list volumes pool=\"${POOL}\"" | ${BCONSOLE} 2>/dev/null | egrep "^\|.*\|$" | tail -n +2 | cut -d'|' -f3,4 | egrep "Purged" | cut -d'|' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') | |
for VOLUME in ${PURGED_VOLUMES}; do | |
echo " ....deleting ${VOLUME} from bacula catalog" | |
echo "delete volume=${VOLUME} yes" | ${BCONSOLE} 1>/dev/null | |
echo " ....removing the file from the filesystem with 'rm'" | |
rm -f "/data/backup/${VOLUME}" | |
done | |
done | |
) | |
echo "That's all folks." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment