Monday, 23 November 2015

Snap Reserve Resizer

Mark II of SnapReserveCalculator from this post - Re-sizing Volume Snapshot Reserve Calculator - just a bit prettier and more user-friendly. Still just a calculator though!

Image: SnapReserveResizer in action!
The Script

## +++++ Snapshot Reserve Resizer +++++ ##
Function Wr{ Param([String]$Echo,[String]$Ink = "WHITE"); IF($Echo){ Write-Host $Echo -ForegroundColor $Ink -NoNewLine } ELSE { Write-Host } }
Function TrapOut{ Wr "Not a valid value!" Red; Wr; EXIT }; Wr

Wr "+++++ Snapshot Reserve Resizer +++++" Magenta; Wr; Wr
Wr "To Health Check Snapshot Reserve ::>" Green; Wr
Wr "vol show -snapshot-space-used > 100 -type RW -fields percent-snapshot-space,snapshot-space-used" Cyan; Wr; Wr
Wr "For any volumes with over 100% snapshot reserve, obtain this info ::>" Green; Wr
Wr "vol show -volume VOLNAME -fields size,percent-used,percent-snapshot-space,snapshot-space-used" Cyan; Wr; Wr

Trap {TrapOut}
Wr "..................... Volume size : " Green; [Double]$VolumeSize      = Read-Host
Wr "............. Percent volume full : " Green; [Double]$PercVolSizeUsed = Read-Host
Wr "........ Percent snapshot reserve : " Green; [Double]$PercSnapRes     = Read-Host
Wr "... Percent snapshot reserve used : " Green; [Double]$PercSnapResUsed = Read-Host; Wr
Wr "......... NEW percent volume full : " Cyan;  [Double]$NewVolPercFull  = Read-Host
Wr "NEW percent snapshot reserve used : " Cyan;  [Double]$NewSnapResPerc  = Read-Host; Wr

[Double]$SizeUsedBySnapshots = ($VolumeSize * $PercSnapRes * $PercSnapResUsed) / (100 * 100)
If($PercSnapResUsed -le 100){ [Double]$SnapshotSpill = 0 }
else{ [Double]$SnapshotSpill = $SizeUsedBySnapshots - (($VolumeSize * $PercSnapRes) / 100) }
[Double]$SizeUsedByUserData = (($VolumeSize * $PercVolSizeUsed) / 100) - (($VolumeSize * $PercSnapRes) / 100) - $SnapshotSpill

[Double]$NewSnapResSize   = ($SizeUsedBySnapshots / $NewSnapResPerc) * 100
[Double]$NewVolumeSize    = (($SizeUsedByUserData + $NewSnapResSize) / $NewVolPercFull) * 100
[Double]$NewPercSnapRes   = ($NewSnapResSize / $NewVolumeSize) * 100
[String]$NewVolSizeString = [String]($NewVolumeSize)
[String]$NewSnapResString = [String]($NewPercSnapRes)

Wr "+++ Result +++" Magenta; Wr; Wr
Wr "New Volume Size              = " Cyan; Wr $NewVolSizeString; Wr
Wr "New Percent Snapshot Reserve = " Cyan; Wr $NewSnapResString; Wr; Wr

Wr "Clustershell Commands ::>" Green; Wr
Wr "vol size -vserver VSERVER -volume VOLNAME -new-size SIZE{&UNIT}" Cyan; Wr
Wr "vol modify -vserver VSERVER -volume VOLNAME -percent-snapshot-space PERCENT" Cyan; Wr; Wr
Wr "Press ENTER to exit ..." CYAN; Read-Host; EXIT


No comments:

Post a Comment