Muitas vezes ocorre que por algum erro, o Bacula gera centenas de volumes com erros, e para excluí-los é necessário executar manualmente no bconsole um comando para excluir volume por volume.
Para facilitar e automatizar esta tarefa é possível utilizar um shell script:
Download do script
wget -c https://raw.githubusercontent.com/wanderleihuttel/bacula-utils/master/conf/scripts/_delete_multiples_volumes.sh -O /usr/local/bin/_delete_multiples_volumes.sh chmod a+x /usr/local/bin/_delete_multiples_volumes.sh
O script
#!/bin/bash ####################################### bconsole=$(which bconsole) clear echo "--------------------------------------------" echo " Script to delete volumes in mass" echo " Author: Wanderlei Hüttel" echo " Email: wanderlei.huttel@gmail.com" echo " Version: 1.1 - 12/11/2018" echo "--------------------------------------------" echo "" echo "list pools" | ${bconsole} | grep "[+||]" read -p "Enter the name of the Pool that you would like to delete the volumes: " pool echo "Selected Pool: ${pool}" echo "" read -p "Enter the status of the volumes you would like to check (Error, Used, Full, Append, Recycled): " volstatus arraycount=$(echo "list media pool=${pool}" | ${bconsole} | grep "|" | grep -v "MediaId" | grep "${volstatus}" | cut -d "|" -f3 | sed 's/ //g' | wc -l) echo "" for volname in $(echo "list media pool=${pool}" | ${bconsole} | grep "|" | grep -v "MediaId" | grep "${volstatus}" | cut -d "|" -f3 | sed 's/ //g'); do echo " ${volname}" ; done echo "" if [ ${arraycount} == "0" ]; then echo -e "No volumes found with status '${volstatus}'n" echo -e "Operation aborted!n" exit else echo -e "${arraycount} volumes was found with status '${volstatus}'n" fi read -p "Are you sure you want to delete all ${arraycount} volumes? This operation is irreversible! (Y-Yes / N-No) " confirm if [ "${confirm}" == "y" ] || [ "${confirm}" == "Y" ]; then for volname in $(echo "list media pool=${pool}" | ${bconsole} | grep "|" | grep -v "MediaId" | grep "${volstatus}" | cut -d "|" -f3 | sed 's/ //g'); do echo "delete volume=${volname} pool=${pool} yes" ; # Uncomment the line below to exclude the volumes in the catalog #echo "delete volume=${volname} pool=${pool} yes" | ${bconsole} ; # Uncomment the line below and change the path of storage to remove volume from the disk also # rm -f /path/to/storage/${volname} done echo -e "Operation finished with success!n" else echo -e "Operation aborted!n" fi
Antes de executar o script
Existem duas linhas no arquivo que por medidas de segurança estão comentadas. Então é possível executar o script sem nenhuma modificação. Então execute uma primeira vez e certifique-se que de os volumes que serão excluídos são os corretos e só depois descomente as linhas do script.
Substitua o caminho “/path/to/storage” pelo diretório físico onde estão os volumes caso para excluir os volumes do disco também (só em caso de backup em disco)
Descomentar as linhas abaixo no script # echo "delete volume=${volname} pool=${pool} yes" | ${bconsole} ; # rm -f /path/to/storage/${volname}
Executando o script
+--------+--------------+---------+---------+----------------+--------------+---------+----------+ | poolid | name | numvols | maxvols | maxvolbytes | volretention | enabled | pooltype | +--------+--------------+---------+---------+----------------+--------------+---------+----------+ | 2 | Scratch | 0 | 0 | 0 | 31,536,000 | 1 | Backup | | 6 | Diaria | 15 | 15 | 4,000,000,000 | 31,536,000 | 1 | Backup | | 7 | Semanal | 25 | 25 | 4,000,000,000 | 31,536,000 | 1 | Backup | | 8 | Mensal | 70 | 70 | 4,000,000,000 | 31,536,000 | 1 | Backup | | 11 | Pool-Temp | 0 | 100 | 10,000,000,000 | 31,536,000 | 1 | Backup | | 13 | VM | 25 | 25 | 10,000,000,000 | 31,536,000 | 1 | Backup | | 14 | Pool-Default | 0 | 100 | 10,000,000,000 | 31,536,000 | 1 | Backup | +--------+--------------+---------+---------+----------------+--------------+---------+----------+ 1) Enter the name of the Pool that you would like to delete the volumes: Diaria # <= Digitar o nome da Pool 2) Enter the status of the volumes you would like to check (Error, Used, Full, Append, Recycled): Error # <= Digitar o estado do volume Volume-Diario-0001 Volume-Diario-0002 Volume-Diario-0003 Volume-Diario-0004 4 volumes was found with status 'Error' 3) Are you sure you want to delete all 4 volumes? This operation is irreversible! (Y-Yes / N-No) # <= Confirmar delete volume=Volume-Diario-0001 pool=Diaria yes delete volume=Volume-Diario-0002 pool=Diaria yes delete volume=Volume-Diario-0003 pool=Diaria yes delete volume=Volume-Diario-0004 pool=Diaria yes Operation finished with success!
Disponível em: PortuguêsEnglish (Inglês)Español (Espanhol)