Saturday, 17 June 2017

Bash Script To List Number Of Backups In VDP For Each Client

There might be situations where you have like a handful of VMs with multiple restore data, and you want to know how many restore data is available for each of these clients. Perhaps, you would like to determine if you could perform some maintenance and get rid of few of them that are having a large number of backups to free up some space.

If you connect to VDP from the regular Web Client plugin, you will have to select each of the VM and then scroll to count, note that the GUI does not include a section to number to list. This would be a tedious task if you have 20+ VMs with backups in a varying range of 10-20+

You can use this below simple bash script to get this done. This will basically list out all the clients protected by VDP and number of backups present within each client.

#!/bin/bash

clear
 
# Print purpose of script
echo -e "\nAvailable number of backups for each client protected by VDP\n"

# Save vCenter hostname to a variable
vcenter_name=$(cat /usr/local/vdr/etc/vcenterinfo.cfg | grep vcenter-hostname | cut -d '=' -f 2)

# List clients in GSAN and save to variable
client_list=$(avmgr getl --path=/$vcenter_name/VirtualMachines | awk '{print $2}' | tail -n+2)

# List Backups for each of the registered client
count=1 # For Sl.No increment

for i in $client_list
# Begin For
do
        number_of_backup=$(avmgr getb --path=/$vcenter_name/VirtualMachines/$i | tail -n+2 | wc -l)
        printf "\n$count. For $(echo $i | cut -d '_' -f 1) the number of backups available are: $number_of_backup"
        ((count++)) #Increment Sl.No
done

# Done with For

echo
echo

You should see an output similar to:

Available number of backups for each client protected by VDP

1. For VM-A the number of backups available are: 3
2. For VM-B the number of backups available are: 3
3. For VM-C the number of backups available are: 3
4. For window the number of backups available are: 8

If you think, you would like some more information along with this, then leave a comment. I will further develop this script as needed. Hope this helps.