Veeam Backup & Replication is a great tool for backing up your virtual environment. U can use it to backup certain virtual machines or your whole environment by simply creating backup jobs in which u add virtual machines. Veeam has the option which sends an e-mail if a backup was successful or failed.

Sadly there is one thing I couldn’t find and it’s an option to check which virtual machines are being backed up and which are not in a virtual environment.

After some thinking I decided to combine Veeam and PowerCLI as a solution to my problem.

When a job is created there is an advanced option to add a note to a virtual machine which can be used for scripts.

When creating a job click “Advanced” when the following screen appears.

Once the advanced settings open, go to the notifications tab and select “Set successful backup details to this VM attribute”. Change the value from “Notes” to “Backup”.

Every time the job finishes successful Veeam will add an annotation called “Backup” to the virtual machine as seen on the picture below.

Below is a script which will collect all virtual machines in the defined vCenter and run a check on the backup annotation. This will perform a check if the backup was successful in the past 2 days. Finally it will send an overview in plain text via mail.

Please change the required settings on top of the script!

# Set the vCenter Server
$vcenter = "localhost"
# Set the SMTP Server address
$SMTPSRV = "<SMTP SERVER>"
# Set the Email address to receive from
$EmailFrom = "veeam@foonet.be"
# Set the Email address to send the email to
$EmailTo = "<RECEIVER>"
# Set the Email subject
$EmailSubject = "Veeam Backup Information"

# SMTPmail function
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body) {
	$mailer = new-object Net.Mail.SMTPclient($smtpserver)
	$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
	$msg.IsBodyHTML = $false
	$mailer.send($msg)
}

# Get Backedup function
function Get-Backedup ($vm) {
	$val = $vm.CustomFields |where {$_.key -eq "Backup" } | select -Property Value
	$today = Get-Date -Format "d/MM/yyyy"
	$yesterday = get-date -format "d/MM/yyyy" -displayhint date ((get-date).adddays(-1))
	$backupDate = $val.Value
	if ( $backupDate -like "*$today*" -or $backupDate -like "*$yesterday*"  ) {
		$res = 1
	} else {
		$res = 0
	} 
	return ( $res )
}

Connect-VIServer $vcenter | Out-Null

$vms = Get-VM

$resultok=@()
$resultnotok=@()

foreach ($vm in $vms) {
	if (Get-Backedup($vm)) {
		$resultok += "$vm `r`n"
	} else {
		$resultnotok += "$vm `r`n"
	}
}

$body = "==================================================`r`n"
$body += "Backup report $vcenter:`r`n"
$body += "==================================================`r`n`r`n"
$body += "The following VMs have NOT been backed up:`r`n"
$body += "---------------------------------------------------------------`r`n"
$body += $resultnotok | Sort-Object
$body += "`r`n`r`nThe following VMs have been backed up:`r`n"
$body += "--------------------------------------------------------`r`n"
$body += $resultok | Sort-Object

send-SMTPmail -to $EmailTo -from $EmailFrom -subject $EmailSubject -smtpserver $SMTPSRV -body $body

That’s it. Feel free to improve the script or give hints and tips!

VMware vSphere is a very nice piece of virtualization software.

Sadly there are a few things that can go wrong and I had the “luck” to hit one of those. Waking up on a morning to notice that 4 VM’s are offline because of the ESXi host going down (hardware failure) isn’t something you want to wake up with. The worst news was that it was a new host which hadn’t been added to a cluster yet so no HA :-(.Thank god I run the machines from a storage!

After adding the storage to another ESXi host I was looking for a way to boot the machines from the new ESXi host. The problem was that vCenter saw the hosts as disconnected and VMotion wasn’t possible. Joy?

Thank god (again?) for SSH access on the machine. So I logged into the machine and managed to boot the machines on the new host by using the following command:

vim-cmd -H hostname_of_new_hypervisor /vmfs/volumes/datastorename/vm-dir/vm.vmx start

Weird thing about this: vCenter (which wasn’t able to do anything with the machines) did see the hosts being moved and changed them to the new ESXi host.