To validate virtual machines with Veeam backup configured and retrieve the schedule details from both VMware and Veeam, you can use a PowerShell script that leverages both VMware’s PowerCLI and Veeam’s PowerShell Snap-in.
Here’s a script the PS script to accomplishes this task:
# Install VMware PowerCLI module and Veeam PowerShell Snap-in if not already installed
# Make sure you have the required permissions to access VMware and Veeam resources
# Load VMware PowerCLI module
Import-Module VMware.PowerCLI
# Load Veeam PowerShell Snap-in
Add-PSSnapin VeeamPSSnapin
# Connect to vCenter Server
$vcServer = "vCenter_Server_Name"
Connect-VIServer -Server $vcServer
# Function to get VMware VM Backup Schedule Details
function Get-VMBackupSchedule {
Param (
[Parameter(Mandatory = $true)]
[string]$VMName
)
$vm = Get-VM -Name $VMName
$vmView = $vm | Get-View
$schedule = $vmView.Config.ScheduledHardwareUpgradeInfo
if ($schedule -ne $null) {
Write-Output "VMware VM Backup Schedule for $VMName:"
Write-Output "Backup Time: $($schedule.UpgradePolicy.Time)"
Write-Output "Backup Day: $($schedule.UpgradePolicy.DayOfWeek)"
Write-Output "--------------------------------------------"
} else {
Write-Output "VMware VM Backup Schedule not configured for $VMName."
}
}
# Function to get Veeam VM Backup Schedule Details
function Get-VeeamBackupSchedule {
Param (
[Parameter(Mandatory = $true)]
[string]$VMName
)
$backupJob = Get-VBRJob | Where-Object { $_.GetObjectsInJob() -match $VMName }
if ($backupJob -ne $null) {
Write-Output "Veeam VM Backup Schedule for $VMName:"
Write-Output "Backup Job Name: $($backupJob.Name)"
Write-Output "Backup Time: $($backupJob.Options.TimeOptions.StartTimes[0].ToString('HH:mm'))"
Write-Output "Backup Day: $($backupJob.Options.ScheduleOptions.ScheduleDailyOptions.DayOfWeek)"
Write-Output "--------------------------------------------"
} else {
Write-Output "Veeam VM Backup Schedule not configured for $VMName."
}
}
# Get all VMs from vCenter Server
$allVMs = Get-VM
# Loop through each VM and validate Veeam backup configuration and get schedules
foreach ($vm in $allVMs) {
Write-Output "Checking VM: $($vm.Name)"
Get-VMBackupSchedule -VMName $vm.Name
Get-VeeamBackupSchedule -VMName $vm.Name
}
# Disconnect from vCenter Server
Disconnect-VIServer -Server $vcServer -Confirm:$false
This script connects to the vCenter Server using VMware PowerCLI and Veeam PowerShell Snap-in, then it retrieves all the virtual machines from vCenter. For each VM, it checks if there is a backup schedule configured in both VMware and Veeam. If a schedule is found, it displays the backup time and day for both VMware and Veeam backups. If no schedule is configured, it indicates that the backup schedule is not set up for that VM.
Make sure to replace “vCenter_Server_Name” with the name or IP address of your vCenter Server. Also, ensure that you have installed VMware PowerCLI and Veeam PowerShell Snap-in before running the script. Additionally, the script assumes you have the necessary permissions to access VMware and Veeam resources. If you encounter any issues, verify your permissions and module installations.
Python script that accomplishes the same task:
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import veeam
# Function to get VMware VM Backup Schedule Details
def get_vmware_backup_schedule(vm):
backup_schedule = vm.config.scheduledHardwareUpgradeInfo
if backup_schedule:
print(f"VMware VM Backup Schedule for {vm.name}:")
print(f"Backup Time: {backup_schedule.upgradePolicy.time}")
print(f"Backup Day: {backup_schedule.upgradePolicy.dayOfWeek}")
print("--------------------------------------------")
else:
print(f"VMware VM Backup Schedule not configured for {vm.name}.")
# Function to get Veeam VM Backup Schedule Details
def get_veeam_backup_schedule(vm):
backup_jobs = veeam.get_vm_jobs(vm.name)
if backup_jobs:
for job in backup_jobs:
print(f"Veeam VM Backup Schedule for {vm.name}:")
print(f"Backup Job Name: {job.name}")
print(f"Backup Time: {job.start_time.strftime('%H:%M')}")
print(f"Backup Day: {job.schedule['DayOfWeek']}")
print("--------------------------------------------")
else:
print(f"Veeam VM Backup Schedule not configured for {vm.name}.")
# Connect to vCenter Server
def connect_vcenter(server, username, password):
context = None
if hasattr(ssl, "_create_unverified_context"):
context = ssl._create_unverified_context()
service_instance = SmartConnect(
host=server, user=username, pwd=password, sslContext=context
)
atexit.register(Disconnect, service_instance)
return service_instance
def main():
vcenter_server = "vCenter_Server_Name"
vcenter_username = "vCenter_Username"
vcenter_password = "vCenter_Password"
try:
# Connect to vCenter Server
service_instance = connect_vcenter(vcenter_server, vcenter_username, vcenter_password)
# Get all VMs from vCenter Server
content = service_instance.RetrieveContent()
container = content.rootFolder
view_type = [vim.VirtualMachine]
recursive = True
containerView = content.viewManager.CreateContainerView(container, view_type, recursive)
vms = containerView.view
# Loop through each VM and validate Veeam backup configuration and get schedules
for vm in vms:
print(f"Checking VM: {vm.name}")
get_vmware_backup_schedule(vm)
get_veeam_backup_schedule(vm)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
Before running the script, make sure to replace “vCenter_Server_Name,” “vCenter_Username,” and “vCenter_Password” with the appropriate credentials for your vCenter Server. Also, ensure you have installed the pyVmomi and pyVeeam libraries using pip:
pip install pyVmomi
pip install pyVeeam
The script connects to the vCenter Server using pyVmomi, retrieves all the virtual machines, and then checks for backup schedules using both pyVmomi and pyVeeam libraries. If backup schedules are found, it prints the details for both VMware and Veeam backups. If no schedules are configured, it indicates that the backup schedule is not set up for that VM.