Forum Discussion

DPeaco's avatar
DPeaco
Moderator
26 days ago

Script for listing Policy name and vm host name?

Greetings,
Has anyone found a way to get the vm hostname/display name from a VMWare Intelligent Policy that uses a vmquery to find the vm host to backup?
I'd like to script this so I can feed it a list of about 500 servers / vm's  and verify that they are in an active backup policy and the backups are running.

Anybody done this already on Linux via bash script and NetBackup commands?

7 Replies

  • Hi DPeaco​ 

    With a list of VMware policies, I'd simply use the nbdiscover command to run for each to get the list of hosts included. You can then compare to your input list. The basic command you would use is "nbdicscover -includedonly -noxmloutput -policy <VMwarePolicy>".

    Also - recall, that with each backup, the VMware custom attribute NB_LAST_BACKUP is updated by NetBackup with the time/date, host and policy - this may be a better way to find the information you need. With a quick google I found this powershell script that apparently can get this information from vCenter (use at you own risk) https://community.broadcom.com/vmware-cloud-foundation/question/need-a-script-to-copy-the-attribute-value-as-tag

    Cheers

    • DPeaco's avatar
      DPeaco
      Moderator

      davidmoline​ 
      Thanks for your info and your reply. I have used nbdiscover a few times but my issue with that is that we have MANY vmw servers and nbdiscover takes about 26 hours to finish the policy list, as long as it doesn't hang somewhere in the list of policies. I have scrubbed the output of bpdbjobs for active clients from the past 24 hours. That seems to be a much faster way to grab a client host name.
      I'm still thinking and searching for a decent way to automate this process so that it will continue to benefit my team, even after I retire next year. :) 

  • Well, I haven’t done that yet, since I don’t really need it — but NetBackup scripting always excites me.
    Do you just need help with the commands you need to run, or are you looking for a full script?
    Unfortunately, I don’t have time at the moment to create and test a complete script, but I’d be happy to help you with the necessary commands.

    • DPeaco's avatar
      DPeaco
      Moderator

      StefanosM​ 
      No, not looking for a full script as I write my own. I know this:

      /usr/openv/netbackup/bin/admincmd/bppllist -U -verbose -allpolicies | egrep '^Policy Name|Active' | awk '/Active.*yes/{print x};{x=$3}'

      should provide me a list of Active backup policies. I also realize that I can maybe use something like this?

      /usr/openv/netbackup/bin/admincmd/bppllist vmw_backup_policy_mon -l -verbose | grep Displayname | awk -v RS='Displayname' '{print}' | awk -F"\"" '{print $2}'

      I've written several scripts and while I'm not an expert in script writing, what I have written sits in production processes today. Some have been running for several years. I've learned to try and automate or script as much as I can to take the "grind" out of the daily grind tasks. ;) 

  • Scripting is a personal thing — everyone has their own style.
    So I’ll give you the commands I would use, and I’m sure you can adjust them to fit your needs.
    Since I like to log every step — often with more info than I actually need — I always create a temporary folder and write the output of every command there.
    At the end, I archive the folder into a .tar.gz file and move it to a logs directory.

    1. create a list of vmware active poilicies. 
      create list of policy, active, type and filter or clients (you will need jq command)
      /usr/openv/netbackup/bin/admincmd/bppllist  -json | jq -r '.policies[] 
        | select(.pinfo.active == 0 and .pinfo.PolicyTypeText == "VMware") 
        | "\(.class_name) \(.pinfo.active) \(.pinfo.PolicyTypeText) \(.include[])"' 

      cat the output and print only the first column
      awk '{print $1}'

    2. for every policyname run the command davidmoline​  give you. it is the only way to create the vmware list of what will be included in the backup.
      nbdicscover -includedonly -noxmloutput -policy <VMwarePolicy>
    3. run the bpimagelist command to get the list of successfull vms for the last $x hours. Comparing the two list will give you the failed VMs. 
      bpimagelist -pt VMware -hoursago $x |grep IMAGE |awk '{print $2}' |sort -u
      I personally ran the same using bpdbjobs and was able to get both the successful and unsuccessful VMs.
      However, it requires some logic to determine whether a failed backup was retried and eventually succeeded.
      sdate=`date +%m/%d/%Y -d "1 day ago"`
      datex=`echo ${sdate} 08:00`

      bpdbjobs -all_columns -t ${datex} |awk -F"," '{if ( $22 == "40" ) print $0}'  > ${temp}/backup_list.txt
      cat ${temp}/backup_list.txt |awk -F"," '{if ( $2 == 0 && $3 == 3 && $4 == 0 ) print $0}'|awk -F"," '{print $5","$6","$7}' > ${temp}/success.txt
      cat ${temp}/backup_list.txt |awk -F"," '{if ( $2 == 0 && $3 == 3 && $4 != 0 ) print $0}'|awk -F"," '{print $5","$6","$7}' > ${temp}/unsuccess.txt
    4. To check if all VMs are included in backup policies, you can use bpVMutil.
      This command generates a list of all VMs (with many details) from all vCenters and saves it to /tmp.
      You can then compare this list with the output of nbdicscover to identify which VMs are not selected for backup.
      bpVMutil 0 NOCACHE 0 
      cat the output and |grep DN


    I have a customer with 10 vCenters and more than 1500 VMs. All commands complete within acceptable timeframes.
    I had to resolve network connectivity issues to eliminate downtimes.
    For some policies, I restrict vCenter usage through the policy’s advanced properties.

    If you are experiencing time constraints, you can use the bpimage or bpdbjobs commands to get a list of VMs that had backups run, and then compare that with the output of bpVMutil.
    The advantage of the bpVMutil command is that the VM list is refreshed every time it runs.
    If you use a static VM list (for example, from RVTools), it may miss newly added VMs.

    If you have mixed policies and use filters along with static VM names, then it’s best to use bpimage or bpdbjobs.

    I believe I haven’t forgotten anything. I would like to hear your thoughts.

    Off topic,
    what happened to the VIP and other badges?

    • DPeaco's avatar
      DPeaco
      Moderator

      StefanosM​ 
      Off topic,
      what happened to the VIP and other badges?

      Good question, was wondering that myself.

    • DPeaco's avatar
      DPeaco
      Moderator

      10 vcenters. That would be nice. Last count was 168 and the count of VM's is climbing faster every day.
      I do like your style in scripting StefanosM​ !
      There are many things I'd like to script to help me and my team in daily workloads. IMHO, it's like trying to get information OUT of NBU IT Analytics. I know the information is in there, but getting the useful info OUT of there that is meaningful to the team AND to leadership? Is yet another challenge.
      Picture 4 backup admins - all treading water each day with our noses just above the surface of the water. That's where we live every day. Good thing I'm retiring early next year. ;)