Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
Team,
I am trying to calculate the snaps size total of volumes name with common pattern. It works fine when all the snaps size are in GB but doesn't work when there are mixed sizes such as MB and KB. My code
$mypattern = read-host "Please enter common pattern to search the volumes (a sample pattern may like 'cluster_a_store') "
[int] $snaps2del = read-host "Please enter number of snaps to delete "
Get-NcVol | ?{ $_.Name -match $mypattern} |Foreach {
$measure = Get-NcSnapshot $_.Name |sort-object -Property Created -Descending |select-object -Last $snaps2del | Measure-Object Total -Sum }
$totalSpace = ConvertTo-FormattedNumber $measure.Sum DataSize "0.0"
Write-Host "Space recovered by deleting those snaps will be: " $totalSpace -ForegroundColor Yellow
Thanks
Solved! See The Solution
Hi
i palyed with it a bit and i get accurate results i think. can you share your output ?
PS C:\Windows\system32> Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 9 Name Volume Vserver Created Total Cumulative Dependency ---- ------ ------- ------- ----- ---------- ---------- hourly.2018-10-07_1405 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 8.8 GB 36.3 GB hourly.2018-10-07_1505 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.1 MB 36.3 GB hourly.2018-10-07_1605 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 16.9 MB 36.3 GB hourly.2018-10-07_1705 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.6 MB 36.3 GB hourly.2018-10-07_1805 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.2 MB 36.4 GB hourly.2018-10-07_1905 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 2.0 MB 36.4 GB hourly.2018-10-07_2005 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 1.1 MB 36.4 GB hourly.2018-10-07_2105 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 916.0 KB 36.4 GB hourly.2018-10-07_2205 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 4.9 MB 36.4 GB busy PS C:\Windows\system32> $mysum = (Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 9 | Measure-Object Total -Sum).Sum PS C:\Windows\system32> ConvertTo-FormattedNumber $mysum DataSize "0.000" 8.845 GB PS C:\Windows\system32> Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 12 Name Volume Vserver Created Total Cumulative Dependency ---- ------ ------- ------- ----- ---------- ---------- hourly.2018-10-07_1105 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 6.3 MB 27.5 GB hourly.2018-10-07_1205 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 6.8 MB 27.5 GB hourly.2018-10-07_1305 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 11.5 MB 27.5 GB hourly.2018-10-07_1405 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 8.8 GB 36.3 GB hourly.2018-10-07_1505 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.1 MB 36.3 GB hourly.2018-10-07_1605 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 16.9 MB 36.3 GB hourly.2018-10-07_1705 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.6 MB 36.3 GB hourly.2018-10-07_1805 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.2 MB 36.4 GB hourly.2018-10-07_1905 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 2.0 MB 36.4 GB hourly.2018-10-07_2005 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 1.1 MB 36.4 GB hourly.2018-10-07_2105 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 916.0 KB 36.4 GB hourly.2018-10-07_2205 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 4.9 MB 36.4 GB busy PS C:\Windows\system32> $mysum = (Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 12 | Measure-Object Total -Sum).Sum PS C:\Windows\system32> ConvertTo-FormattedNumber $mysum DataSize "0.000" 8.869 GB PS C:\Windows\system32> #calc the diffrence between the SUMs PS C:\Windows\system32> 69-45 24 PS C:\Windows\system32> #calc the added snapshot form the last output total.. PS C:\Windows\system32> 6.3+6.8+11.5 24.6
Hi
i palyed with it a bit and i get accurate results i think. can you share your output ?
PS C:\Windows\system32> Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 9 Name Volume Vserver Created Total Cumulative Dependency ---- ------ ------- ------- ----- ---------- ---------- hourly.2018-10-07_1405 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 8.8 GB 36.3 GB hourly.2018-10-07_1505 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.1 MB 36.3 GB hourly.2018-10-07_1605 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 16.9 MB 36.3 GB hourly.2018-10-07_1705 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.6 MB 36.3 GB hourly.2018-10-07_1805 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.2 MB 36.4 GB hourly.2018-10-07_1905 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 2.0 MB 36.4 GB hourly.2018-10-07_2005 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 1.1 MB 36.4 GB hourly.2018-10-07_2105 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 916.0 KB 36.4 GB hourly.2018-10-07_2205 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 4.9 MB 36.4 GB busy PS C:\Windows\system32> $mysum = (Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 9 | Measure-Object Total -Sum).Sum PS C:\Windows\system32> ConvertTo-FormattedNumber $mysum DataSize "0.000" 8.845 GB PS C:\Windows\system32> Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 12 Name Volume Vserver Created Total Cumulative Dependency ---- ------ ------- ------- ----- ---------- ---------- hourly.2018-10-07_1105 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 6.3 MB 27.5 GB hourly.2018-10-07_1205 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 6.8 MB 27.5 GB hourly.2018-10-07_1305 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 11.5 MB 27.5 GB hourly.2018-10-07_1405 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 8.8 GB 36.3 GB hourly.2018-10-07_1505 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.1 MB 36.3 GB hourly.2018-10-07_1605 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 16.9 MB 36.3 GB hourly.2018-10-07_1705 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.6 MB 36.3 GB hourly.2018-10-07_1805 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 7.2 MB 36.4 GB hourly.2018-10-07_1905 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 2.0 MB 36.4 GB hourly.2018-10-07_2005 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 1.1 MB 36.4 GB hourly.2018-10-07_2105 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 916.0 KB 36.4 GB hourly.2018-10-07_2205 SVMSVMSVM_SVMSVM... SVMSVMSVM 07/10/2018 4.9 MB 36.4 GB busy PS C:\Windows\system32> $mysum = (Get-NcVol -Controller $g | select -last 1| Get-NcSnapshot | select -last 12 | Measure-Object Total -Sum).Sum PS C:\Windows\system32> ConvertTo-FormattedNumber $mysum DataSize "0.000" 8.869 GB PS C:\Windows\system32> #calc the diffrence between the SUMs PS C:\Windows\system32> 69-45 24 PS C:\Windows\system32> #calc the added snapshot form the last output total.. PS C:\Windows\system32> 6.3+6.8+11.5 24.6
Thanks for looking into this GidonMarcus.
You are selecting snaps from one volume. My question is oldest 3 snaps from each volume matches my pattern. I figured it that closing curly bracket for "foreach" loop was in the wrong place and I wasn't getting the each volume total added to full total. My modified version.
$mypattern = read-host "Please enter common pattern to search the volumes (a sample pattern may like 'cluster_a_store') "
[int] $snaps2del = read-host "Please enter number of snaps to delete "
[long]$measure = 0
[long]$snapsTotal = 0
Get-NcVol | ?{ $_.Name -match $mypattern -and $_.Name -NotMatch "vault"} |Foreach {
$measure = (Get-NcSnapshot $($_.Name) |sort-object -Property Created -Descending |select-object -Last $snaps2del | Measure-Object Total -Sum).sum
$snapsTotal = $measure + $snapsTotal }
$totalSpace = ConvertTo-FormattedNumber $snapsTotal DataSize "0.00"
Write-Host "Space recovered by deleting those snaps will be: " $totalSpace -ForegroundColor Yellow
Thanks again for your time.