I'm looking for a script that can give a report of all snapshots that have been created and removed in the past 48 hours on all datastores. Basiclly what I'm trying to do is set up time line of our backups for when snapshots are created on each VM and what datastore the snapshot was created on and the size of the snapshot. The issue we have is our datastores are grossly over provissioned (setup before I started here) and no budget for additional storage at this time. We have been having issue with datastores filling up during backups due to snapshots. I'm looking at changing the location of where the snapshots are created to a dedicated LUN different from the default Virtual Machine folder. I want to get a idea of when the snapshots are being created, Size of the snapshot, when removed, in a 48 hour window.
Any ideas on how this can be done?
I can look at the backup program and see when the VM started the backup process, but it does not tell me what data store the vm is on and what other VM's are currently being backed up on that same data store. Also Storage DRS may move VM's around and now cause issues with I/O when multiple snapshots are created on the same lun at the same time.
I'm just trying to get a better idea and a good way to create a visual report to show my managers why the data stores are filling up due to the backups.
Thank you
You could do something like this
$taskNames = 'CreateSnapshot_Task','RemoveSnapshot_task'
Get-VIEvent -Start (Get-Date).AddDays(-2) -MaxSamples ([int]::MaxValue) |
where{$_ -is [VMware.Vim.TaskEvent] -and $taskNames -contains $_.Info.Name} |
Sort-Object -Property CreatedTime |
Select CreatedTime,UserName,
@{N='VM';E={$_.VM.Name}},
@{N='Datastore';E={(Get-View -Id $_.Vm.Vm -Property 'Config.Files.SnapshotDirectory').Config.Files.SnapshotDirectory}},
@{N='Task';E={$_.FullFormattedMessage}}
The size of the snapshot is problematic, since the snapshot is already removed when you run the report.
If the snapshot still exists, you could calculate the total size of the snapshot.
See for example my UML diagram your VM, vdisks and snapshots, you could use the same logic to get the total size of the latest snapshot.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
$taskNames = 'CreateSnapshot_Task','RemoveSnapshot_task'
Get-VIEvent -Start (Get-Date).AddDays(-2) -MaxSamples ([int]::MaxValue) |
where{$_ -is [VMware.Vim.TaskEvent] -and $taskNames -contains $_.Info.Name} |
Sort-Object -Property CreatedTime |
Select CreatedTime,UserName,
@{N='VM';E={$_.VM.Name}},
@{N='Datastore';E={(Get-View -Id $_.Vm.Vm -Property 'Config.Files.SnapshotDirectory').Config.Files.SnapshotDirectory}},
@{N='Task';E={$_.FullFormattedMessage}}
The size of the snapshot is problematic, since the snapshot is already removed when you run the report.
If the snapshot still exists, you could calculate the total size of the snapshot.
See for example my UML diagram your VM, vdisks and snapshots, you could use the same logic to get the total size of the latest snapshot.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thank you for the reply. I have been trying a script somewhat similar, but it was not giving the expected results.
#
foreach ($snap in Get-VM)
{$snapevent = Get-VIEvent -Entity $snap.VM -Types Info -Finish $snap.Created -MaxSamples 1 | Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'}
if ($snapevent -ne $null){Write-Host ( "VM: "+ $snap.VM + ". Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + " by " + $snapevent.UserName +".")}
else {Write-Host ("VM: "+ $snap.VM + ". Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + ". This event is not in vCenter events database")}}
#
Your script is giving me the expected information, Thank you for the script!
I knew it was going to be an issue getting the sizes of the snapshots that have already been removed. I figured maybe someone had a clever script that was able to find that hidden information. I wish there was better reporting/information on snapshots since these can have a big impact on your storage if too many are created or removed at the same time when backups are being run. It would be nice to see this information and show how it ties to high I/O and Latency during the back up window. This can also show why the backups, at times take longer to complete when snapshots are taking longer to create or remove. I have been taking to our management about using SAN based snapshots for our VM backups (1500 vm's and about 77TB of total data ) but I need to build my case on it. I have a lot of work here to do to clean up these issues and poor design.
Travis
You could also look at the "usage" on the datastores involved during the backup window.
This will not show you per individual snapshot, but it should show which datastores are reaching hihg watermarks.
Have a look at Datastore usage statistics
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I do have a script that runs several times during the day and during the backups to get TotalSpace, UsedSpace, FreeSpace, ProvisionedSpace and Number of VM's per data store. The problem is the datastores are already at the high water mark before the backups kick in. That's why I'm looking at having all the snapshots be created on a dedicated LUN(s) that are separate from the Default Virtual Machine Folder. We are very tight on space, and grossly over provisioned, I'm trying to find out how many extra LUNS would be needed for the snapshots (how many snapshots are created at the same time) and how much space would be needed for concurrent snapshots, per snapshot LUN. Unfortunately this is what I have inherited, and I'm trying to keep things running until I can get approval for additional storage, redesign of the backups and correcting provisioning policies. along with installing actual monitoring and reporting software.
Is there a way to combine vrops metrics of snapshot size into this script? Vrealize will have the five minute stats on snapshot size.