Monday, 17 July 2017

Bash Script To Determine Backup Protocol

In vSphere Data Protection, you have couple of backup protocols. SAN mode, HotAdd, NBD and NBD over SSL. HotAdd is always the recommended protocol, as data handling and transfer is much faster than the rest. If your backups are running slow, then the first thing we will check is the backup protocol mode. Then we will move further to VDP load and finally the VMFS / Array performance.

If you have few VMs, you can easily find out the protocol type from the logs. However, if you have a ton of VMs and would like to determine the protocol, then you can use this script that I have written.
https://github.com/happycow92/shellscripts/blob/master/backup-protocol-type.sh

#!/bin/bash
clear
IFS=$(echo -en "\n\b")
echo "This script should be executed on a proxy machine"
echo "Checking current Machine......"
directory="/usr/local/vdr"
if [ ! -d "$directory" ]
then
printf "Current machine is Proxy machine"
else
printf "Current machine is VDP Server"
fi
echo && echo
sleep 2s
echo -e "--------------------------------------------------------"
echo -e "| Client Name | Backup Type | Proxy Used |"
echo -e "--------------------------------------------------------"
cd /usr/local/avamarclient/var
backupLogList=$(ls -lh | grep -i "vmimagew.log\|vmimagel.log" | awk '{for (i=1; i<=8; i++) $i=""; print $0}' | sed 's/^ *//')
for i in $backupLogList
do
clientName=$(cat $i | grep -i "<11982>" | awk '{print $NF}' | cut -d '/' -f 1)
protocolType=$(cat $i | grep -i "<9675>" | awk '{print $7}' | head -n 1)
proxyName=$(cat $i | grep -i "<11979>" | cut -d ',' -f 2)
if [ "$protocolType" == "hotadd" ]
then
protocol="hotadd"
elif [ "$protocolType" == "nbdssl" ]
then
protocol="nbdssl"
elif [ "$protocolType" == "nbd" ]
then
protocol="nbd"
else
protocol="SAN Mode"
fi
printf "| %-20s| %14s| %12s|\n" "$clientName" "$protocolType" "$proxyName"
done
echo && echo
Few things:
> The script must be always executed on a proxy machine. If your VDP is using internal proxy, then run it on the VDP machine itself.
> If you are using one or more External Proxy, then you need to run this on each of the proxy machines.
> Note, this will work on 6.x VDP and above.

I have added an IFS (Internal Field Separator) to handle spaces in backup job names. The rough version of script had issues handling spaces in job names.

It's a very lightweight script, takes seconds to execute and does not make any changes to your system.

Hope this helps.