Some Shell Script & PHP Reports
  • Post category:Uncategorized
  • Post comments:0 Comments

With shell script it is possible to do anything, and PHP makes easy to display Bacula information in any Internet browser.

1. Real Time Job Speed (Storage)

Sample output, automatically refreshed every second.

Writing: Full Backup job BackupLibreOffice JobId=335 Volume="Vol-0038"
Files=6,137 Bytes=94,374,514 AveBytes/sec=2,859,833 LastBytes/sec=2,859,833
--
Writing: Full Backup job BackupLibreOffice JobId=336 Volume="Vol-0038"
Files=5,101 Bytes=19,010,555 AveBytes/sec=1,118,267 LastBytes/sec=1,118,267
--
Writing: Full Backup job BackupLibreOffice JobId=337 Volume="Vol-0038"
Files=2,716 Bytes=2,346,155 AveBytes/sec=156,410 LastBytes/sec=156,410
--
Writing: Full Backup job BackupLibreOffice JobId=338 Volume="Vol-0038"
Files=2,147 Bytes=1,900,566 AveBytes/sec=158,380 LastBytes/sec=158,380
--
Writing: Full Backup job BackupLibreOffice JobId=339 Volume="Vol-0038"
Files=2,232 Bytes=1,932,744 AveBytes/sec=161,062 LastBytes/sec=161,062

PHP file content:

<meta http-equiv="refresh" content="1">
<?php
$output = shell_exec('echo status storage |bconsole |grep -A 3 Writing |grep -v -e spool -e pool');
echo "<pre>$output</pre>";
?>

2. Last 2 Days Jobs Summary

Sample Output:

Bacula Summary 2016-03-01
-
Last two days Error Terminated Jobs:
-
+---------------------------------------------------------------------------------------------------------------------------------------------+
| JobId |     Job Name     |    Start Time    |    Type    |   Level   |   Files   |   Size in B  | Job Status |
+---------------------------------------------------------------------------------------------------------------------------------------------+
| 333 | BackupLibreOffice | 2016-02-29 15:51:49 | B | F | 6,607 | 109,006,683 | Incomplete |
| 344 | Bkp_ACME_FileServer | 2016-03-01 16:46:48 | B | F | 26,253 | 859,522,562 | Fatal Error |
| 345 | Bkp_ACME_ERP | 2016-03-01 16:46:51 | B | F | 26,253 | 859,522,562 | Fatal Error |
+---------------------------------------------------------------------------------------------------------------------------------------------+
Jobs with error: 1
Jobs OK: 7
+---------------------------------------------------------------------------------------------------------------------------------------------+

Para habilitar, criamos o script que gera as informações (dê permissão de execução):

# /etc/bacula/sctips/summary.sh
TODAY=$(date +%Y-%m-%d)
YESTERDAY=$(date +%Y-%m-%d --date="1 day ago")

# Lista Jobs ontem e Hoje
echo "list jobs joberrors" |bconsole | grep -E "$TODAY|YESTERDAY" > /tmp/listjobs2dias
echo "list jobs jobstatus=T" |bconsole | grep -E "$TODAY|YESTERDAY" > /tmp/listjobs2diasOK

QTDERR=$(wc -l < /tmp/listjobs2dias)
QTDOK=$(wc -l < /tmp/listjobs2diasOK)

echo "Bacula Summary" $TODAY
echo "-"
echo "Last two days Error Terminated Jobs:"
echo "-"
echo "+---------------------------------------------------------------------------------------------------------------------------------------------+"
echo "| JobId |     Job Name     |    Start Time    |    Type    |   Level   |   Files   |   Size in B  | Job Status |"
echo "+---------------------------------------------------------------------------------------------------------------------------------------------+"
cat /tmp/listjobs2dias |sed s/'| T '/'| OK with Warning'/g |sed s/'| f '/'| Fatal Error'/g |sed s/'| I '/'| Incomplete '/g
echo "+---------------------------------------------------------------------------------------------------------------------------------------------+"
echo "Jobs with error:" $QTDERR
echo "Jobs OK:" $QTDOK
echo "+---------------------------------------------------------------------------------------------------------------------------------------------+"

Then we can create a PHP file to call the script (normally in /var/www/html):

<?php
$output = shell_exec('/etc/bacula/scripts/sumario.sh');
echo "<pre>$output</pre>";
?>

 3. Storage Backup Jobs usage per Group

Sample Output:

|    Sum in GB | Costumer      |    Qty |  Server                       |            GB|
|      3.20 GB | ACME          |      4 |                               |              |
|              |               |        |  Bkp_ACME_FileServer     	|       0.80 GB|
|              |               |        |  Bkp_ACME_ERP            	|       0.80 GB|
|              |               |        |  Bkp_ACME_FileServer     	|       0.80 GB|
|              |               |        |  Bkp_ACME_ERP            	|       0.80 GB|
|      0.00 GB | Costumer2     |      1 |                               |              |
|              |               |        |  Bkp_Costumer2_DataBases 	|       0.00 GB|

In order to this script work its a must to change backup Jobs name and put the grouping clausule (e.g.: owner of the server name) between underscores (_). E.g.:

Bkp_Constumer_Arquivos

Then we create the script (we must also give execution permission):

#!/bin/bash
# /etc/bacula/scripts/group.sh

echo "list jobs"|bconsole |tail -n +9 > /tmp/listajobs
Clientes=$(cut -sf2 -d_ /tmp/listajobs | sort | uniq)
printf '| %12s | %-13s | %6s | %-29s | %13s|n' " Sum in GB" Costumer Qty " Server" GB
for Cliente in $Clientes
do
 Regs=$(grep _$Cliente_ /tmp/listajobs)
 Qtd=$(wc -l <<< "$Regs")
 Tot=$(cut -f8 -d | <<< "$Regs" | tr -d , | paste -s -d+ | bc)
 Tot=$(bc <<< "scale=2; $Tot / 1073741824")
 Servs=
 LC_ALL=C printf '| %9.2f GB | %-13s | %6d | %29s | %12s |n' $Tot $Cliente $Qtd ' ' ' '
 IFS=$'n' Compl=($(paste <(cut -f3 -d| <<< "$Regs") <(cut -f8 -d | <<< "$Regs" | tr -d , | xargs -i echo 'scale=2; {}/1073741824' | bc | sed 's/^./0./' | LC_ALL=C xargs -n1 printf '| %10.2f GB|n')))
 for i in ${!Compl[@]}
 do
 printf '| %12s | %13s | %51sn' ' ' ' ' $(echo | ${Compl[i]})
 done
 #read
done

Then we can create a PHP file to call the script (normally in /var/www/html) so we can fetch information using any Internet browser:

<?php
$output = shell_exec('/etc/bacula/scripts/group.sh');
echo "<pre>$output</pre>";
?>

 

 

Disponível em: pt-brPortuguês (Portuguese (Brazil))enEnglish

Leave a Reply