Check for Orphaned Veeam Temporary Snapshots
For those using Veeam Backup & Replication in a vSphere environment perhaps backing up hundreds of virtual machines one of the important housekeeping items you may want to keep a check on is any Veeam temporary snapshots that may for whatever reason been left over from a backup run. I have seen cases where temporary snapshots get leftover for any number of reasons but typically there is a reason why the temporary snapshot doesn’t get deleted. This can cause issues down the road as any snapshot left running in production can deteriorate performance, and cause issues. It can also cause issues with future Veeam backups on a particular virtual machine. Thankfully, using PowerShell, we can quickly find a Veeam snapshot that might be leftover from a run that did not cleanly finish. Let’s look at how to check for orphaned Veeam temporary snapshots with PowerShell PowerCLI.
What causes the orphaned Veeam Temporary Snapshots?
When Veeam Backup & Replication starts the backup or replication job, it creates the “VEEAM BACKUP TEMPORARY SNAPSHOT”. According to an official Veeam KB article found here,ย In some cases the API command to remove the temporary snapshot is not received or not executed. This can be due to network connectivity issues between the Veeam Backup & Replication server and the vCenter Server or between vCenter and the ESXi host itself.ย Whatever the case, there is some interruption in the chain of commands that get communicated that prevents the temporary snapshot from getting deleted.
As shown below, the temporary snapshot size can be quite large on large disk layout virtual machines.
Check for Orphaned Veeam Temporary Snapshots
Make sure you are running the latest version of PowerCLI.ย In case you haven’t heard, there is a new way to install PowerCLI.ย Once you have PowerCLI loaded and current with the latest version, you should be good to go.ย The script is fairly simple and is just a modified version of checking for any snapshots with PowerCLI.ย You can set the “OlderThan” variable with the number of days that you want to count back.ย Any Veeam temporary snapshots should not hang around very long as these are created and deleted with each backup run.ย So, if you check for any Veeam Temporary snapshots that are older than a day even, you should be able to catch any that may have not been properly deleted.
The script currently just outputs to a txt file but the output can be formatted and customized as needed.ย With the output file, the script also has a section included that will email an attachment which is more helpful if you are scheduling it via a scheduled task, however, you can customize it as needed.
#Connect vCenter If ($Cred -eq $null) { $cred = get-credential } If ($vcenter -eq $null){ $vcenter = Read-Host -Prompt 'Enter vCenter Server Name' } $vi = connect-viserver $vcenter -credential $cred $CurrentDate = Get-Date $OlderThan = -1 $CheckSnapshotDate = $CurrentDate.AddDays($OlderThan) $VeeamSnapsOld = Get-VM | Get-Snapshot | Where {$_.Created -lt $CheckSnapshotDate -and $_.Name -like "VEEAM BACKUP TEMPORARY SNAPSHOT"} | Select-Object VM, Name, Created, SizeGB | sort-object SizeGB -descending $VeeamSnapsOld | out-file <file path.txt> if ($VeeamSnapsOld -ne $null) { send-mailmessage -from "<from email address>" -to "<to email address>" -subject "Veeam Snapshots" -body "There are old Veeam Snapshots detected" -smtpserver <SMTP server> -attachments <attach outfile> } disconnect-viserver -confirm:$false
Thoughts on how to Check for Orphaned Veeam Temporary Snapshots
Keeping a check on snapshots in general in a vSphere environment is something that as vSphere virtualization administrators we do on a daily basis or at least fairly often.ย If you are like me, having an automated mechanism to proactively discover and be alerted of existing snapshots is a much better way of handling discovering snapshot issues in an environment.ย Most of today’s modern data protection solutions utilize temporary snapshots to be able to copy data while the virtual machine is running.ย Keeping a check on these temporary snapshots ensures things will continue running smoothly.ย In the case of Veeam, it is always a good idea to check for orphaned Veeam temporary snapshots and using PowerCLI takes the heavy lifting out of the process.