Sometimes when a Veeam Backup doesn’t finish properly the snapshot that was created by Veeam is not deleted. There is a lot of reasons for a Backup does not end properly and the snapshot not removed. Most of them is a timeout between Veeam Backup Server and the vCenter/Storage. In this blog post, we will delete Veeam ghost backup snapshots with PowerCLI.
A virtual disk stuck in a Veeam Proxy can also trigger this. In this blog post Removing Veeam ghost snapshots, I have explained how to release any Virtual Disk that is stuck in a Veeam Proxy. In this blog post, we will delete with PowerCLI.
If backup administrators do not track this, you could get VMs with dozens of snapshots from Veeam. Veeam will not able to delete the previous one (from the day before), create another backup snapshot and then is not possible to delete again.
I have seen VMs with more than 60 snapshots, because of Veeam Backup Snapshots and then is very difficult to consolidate the disks and fix it.
Note: If you have a VM with dozes of Veeam Backups Snapshots don’t use this script, use the above previous blog post and removed manually.
The next script we can use to search for any Veeam Backup snapshots (using argument VEEAM BACKUP*) with the creating date (we usually should set to -1, will search snapshots created from the previous day), but we can also use to find any snapshot existing in the vCenter or Cluster. Using all search, we can search for snapshots for example, that have more than a week (-7 days).
For safe side, the script will only list the Snapshots will not delete them automatically. To list and delete the snapshot you need to uncomment the delete section.
PowerCLI Script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
####################################################################### # Created by: Luciano Patrão # # Date: 23-03-2017 # # Updated: 25/11/2018 # # Search for Veeam Snapshots (or by creating date) and delete them # ####################################################################### Get-Module –ListAvailable VM* | Import-Module cls ###### Credentials and vCenter connection ###### $vCenter = 'vCenterIP or DNS Name' ### You an connect to a vCenter IP/DNS Name or connect directly to ESXi host. $user = "vCenter USER" $pwd = "USER password" Connect-VIServer $vCenter -User $user -Password $pwd ### vCenter Server Name(FQNP) $vCentName = [system.net.dns]::GetHostByAddress($vCenter).hostname ################################################ ### Search all Cluster and VMs in the vCenter. $VMs = Get-VM ### Search Snapshots by vCenter Cluster. #$VMs = Get-Cluster "vCenter Cluster" | Get-VM foreach ($VM in $VMs) { $AllSnapshots= Get-Snapshot -VM $VM foreach ($Snapshot in $AllSnapshots) { If ($Snapshot.Name -like “VEEAM BACKUP*” -and $Snapshot.Created -lt (Get-Date).AddDays(-1)) ### If you want to search all Snapshots, not only the ones created by Veeam. #If ($Snapshot.Created -lt (Get-Date).AddDays(-7)) { Write-Host "VM -> " $VM.Name, Write-Host " Snapshot Name: " $Snapshot.Name Write-Host " Snapshot Data: " $Snapshot.Created Write-Host "Remove Snapthot :" $Snapshot.Name -ForegroundColor Red Write-Host "Remove Snapthot :" $Snapshot.description -ForegroundColor blue ### Option to delete the Snapshots. #Remove-Snapshot -snapshot $Snapshot -confirm:$false -ErrorAction SilentlyContinue #Write-Host "" #Start-Sleep -s 30 } } } Disconnect-VIServer -Server $vCenter -Force -Confirm:$false |
Search options:
By name vs date:
The above script was created to find Veeam Snapshots and delete them, but like is in the comments inside the script, it can also be used to find all snapshots existing in the vCenter or a specific Cluster. We just need to comment the line: “If ($Snapshot.Name -like “VEEAM BACKUP*” -and $Snapshot.Created -lt (Get-Date).AddDays(-1))” and then uncomment the line: “If ($Snapshot.Created -lt (Get-Date).AddDays(-7))” to search for all snapshots that have the creating date 7 days behind (will list all snapshots at least one week old).
If you want to search older snapshots (like 30 days old), change the setting to (-30). This setting will list all snapshots older than 30 days. Any snapshot that was created in the last 30 days will not be listed or deleted.
All VMs vs one Cluster:
By default, the script will search for all VMs, regardless if exists one, or more vCenter Clusters. If needed to search in a particular cluster then comment the line: “$VMs = Get-VM” and uncomment the line: “$VMs = Get-Cluster “vCenter Cluster” | Get-VM” and add the Cluster name.
By default the above script and options, only list the VMs and the snapshots information, the script does not delete the snapshots. Check the next section to enable delete the option.
Delete snapshots:
For safe side, deletion of the snapshots is disabled (commented). After you check the list of VMs that have the snapshots and you are sure that you want to delete them, uncomment all bellow section ### Option to delete the Snapshots (do not uncomment this line, only the next lines).
Note: Please be patience when the script is deleting snapshots, this can take some time (monitor the snapshot deletion in the vCenter).
Note: Share this article, if you think it is worth sharing.
Leave a Reply