-
Notifications
You must be signed in to change notification settings - Fork 3
/
bacula-statusjobs.sh
executable file
·73 lines (61 loc) · 2.26 KB
/
bacula-statusjobs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
# $Id: bacula-statusjobs.sh,v 1.1 2006-06-21 11:08:25 turbo Exp $
if [ -f "/etc/bacula/.conn_details" ]; then
. /etc/bacula/.conn_details
else
echo "Config file /etc/bacula/.conn_details does not exists!"
exit 1
fi
# --------------
help () {
echo "Usage: `basename $0` <-c [client]> <-j [jobname]>"
echo "Options: -h,--help Show this help"
echo " -c,--client Backup client"
echo " -j,--job Backup client job name"
exit 1
}
# --------------
# Get the CLI options...
client="%" ; jobname="%"
if [ -n "$1" ]; then
TEMP=`getopt -o ahc:j: --long help,all,client:,job: -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-a|-all) client="%" ; jobname="%" ; shift ;;
-h|--help) help ;;
-c|--client) client="`echo $2`%" ; shift 2 ;;
-j|--job) jobname="`echo $2`%" ; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;
esac
done
fi
# ==============================================================================
if [ "$CATALOG" = "mysql" ]; then
COMMAND="mysql -h $HOST -u $USERNAME --password=$PASSWORD $DB -BNr -e "
else
echo "PostgreSQL not yet availible. Please edit $0"
exit 1
fi
# Output a header
# Pumba_System 2005-09-29 01:09:41 2005-09-29 01:16:22 1690 861142479
printf "%-18s %-22s %-22s %-6s %-13s\n" Jobname Jobstart Jobend SDFiles SDBytes
# Get clients
$COMMAND "SELECT ClientId,Name FROM Client WHERE Name LIKE '$client'" | \
while read line_clients; do
set -- `echo $line_clients`
id=$1 ; name=$2
# Setup query to retreive status for all jobs on this client
QUERY="SELECT Name,StartTime,EndTime,JobFiles,JobBytes FROM Job WHERE \
ClientId=$id AND JobErrors=0 AND NOT (Name='RestoreFiles') AND NOT (Name='Backup_Old') \
AND Name LIKE '$jobname' ORDER BY Name,StartTime"
# Get status for all jobs on this client
$COMMAND "$QUERY" | \
while read line_jobs; do
set -- `echo $line_jobs`
# Pumba_System 2005-09-29 01:09:41 2005-09-29 01:16:22 1690 861142479
name=$1 ; start_date=$2 ; start_time=$3 ; end_date=$4 ; end_time=$5 ; files=$6 ; bytes=$7
printf "%-18s %-10s %-8s %-10s %-8s %6s %13s\n" $name $start_date $start_time $end_date $end_time $files $bytes
done
done