Tuesday, January 20, 2009

Auto Grow DPM Protection Groups by Percentage Thresholds

Managing many DPM servers can turn into quite a time consuming activity, especially when it comes to allocating more disk space to Data Sources.  The Ctrl-P DPM blog has a real simple auto-grow script on their site, but I personally have had issues with it, as have many others on the Net.  It is also rather lacking in “bells and whistles” but for an everyday DPM admin, it sure would make life easier.  In my quest for ways to make my job easier, I found this absolutely AWESOME script that Owen Clashing wrote on his blog.

#This DPM powershell script helps automate the growing of replica and shadow copy volumes which need to be grown.
param([string] $DPMServerName, [string] $Mode, [int] $ReplicaThreshold, [int] $ReplicaGrowBy, [int] $RecoveryPointThreshold, [int] $RecoveryPointGrowBy)

###### Define variables for default values
$DefaultDPMServerName = $env:COMPUTERNAME # Assumes that the current computer is the DPM server
$DefaultMode = "A"
$DefaultReplicaThreshold = 90
$DefaultReplicaGrowBy = 5
$DefaultShadowCopyThreshold = 90
$DefaultShadowCopyGrowBy = 5
######

function Usage()
{
write-host
write-host "Usage::"
write-host "AutoGrowByPercentWithDefaults.ps1"
write-host "AutoGrowByPercentWithDefaults.ps1 -DPMServerName [DPMServername] -Mode [A|C]"
write-host
write-host "Run 'AutoGrowByPercentWithDefaults.ps1 -detailed' for detailed help"
write-host
write-host
}

if(("-?","-help") -contains $args[0])
{
Usage
exit 0
}

if(("-detailed") -contains $args[0])
{
write-host
write-host "Detailed Help : Use this script to automatically grow the replica and recovery point volume sizes"
write-host "Parameters:"
write-host "-DPMServerName [DPMServername] :: The name of the DPM server that is being targetted"
write-host "-Mode [A|C] :: A - Audit only (make no disk allocation changes); C - Change disk allocations"
write-host "-ReplicaThreshold [Replica Threshold %] :: Percentage usage above which disk space allocation for the replica volume will be triggered"
write-host "-ReplicaGrowBy [Replica Grow By %] :: Percentage by which to grow the replica volume"
write-host "-RecoveryPointThreshold [Recovery Point Threshold %] :: Percentage usage above which disk space allocation for the recovery point volume will be triggered"
write-host "-RecoveryPointGrowBy [Recovery Point Grow By %] :: Percentage by which to grow the recovery point volume"
write-host "Current default values:"
write-host "-DPMServerName $DefaultDPMServerName"
write-host "-Mode $DefaultMode"
write-host "-ReplicaThreshold $DefaultReplicaThreshold"
write-host "-ReplicaGrowBy $DefaultReplicaGrowBy"
write-host "-RecoveryPointThreshold $DefaultShadowCopyThreshold"
write-host "-RecoveryPointGrowBy $DefaultShadowCopyGrowBy"
write-host
exit 0
}

if(!$DPMServerName)
{
$DPMServerName = $DefaultDPMServerName
}

if(!$Mode)
{
$Mode = $DefaultMode
}
else
{
if (($Mode -ne "A") -or ($Mode -ne "C"))
{
Usage
exit 0
}
}

if(!$ReplicaThreshold)
{
$ReplicaThreshold = $DefaultReplicaThreshold
}

if(!$ReplicaGrowBy)
{
$ReplicaGrowBy = $DefaultReplicaGrowBy
}

# Note the inconsistency in the naming - Object model name Shadow Copy, GUI name Recovery Point
# We use the GUI names in naming the parameters to keep it familiar for the casual user.
if(!$RecoveryPointThreshold)
{
$ShadowCopyThreshold = $DefaultShadowCopyThreshold
}
else
{
$ShadowCopyThreshold = $RecoveryPointThreshold
}


if(!$RecoveryPointGrowBy)
{
$ShadowCopyGrowBy = $DefaultShadowCopyGrowBy
}
else
{
$ShadowCopyThreshold = $RecoveryPointGrowBy
}


switch ($Mode)
{
"A"
{
$ChangeHighlightColor = "Green"
write-host "In audit mode - No changes will be made to the disk allocations" -foregroundcolor $ChangeHighlightColor
}
"C"
{
$ChangeHighlightColor = "Red"
write-host "In change mode - Changes will be made to the disk allocations" -foregroundcolor $ChangeHighlightColor
}
}



$dpmserver = Connect-DPMServer $DPMServerName

if(!$dpmserver)
{
write-error "Unable to connect to $dpmservername"
exit 1
}

$PGList = @(Get-ProtectionGroup $DPMServerName)

foreach($PG in $PGList)
{
# Use a modifiable protection group only if we are in change mode
# A non-modifiable protection group object is significantly faster
if ($Mode -eq "C")
{
$MPG = Get-ModifiableProtectionGroup $PG
}
else
{
$MPG = $PG
}

$dslist=@(get-datasource $MPG)
foreach ($ds in $dslist)
{
$ReplicaUsedPercent = ($ds.ReplicaUsedSpace/$ds.ReplicaSize)
$ShadowCopyUsedPercent = ($ds.ShadowCopyUsedSpace/$ds.ShadowCopyAreaSize)
"------------------------------------------------------------------------"
#"Protection Group: $PG.Name"
"$ds"

# $ds.ReplicaSize = -1 when there is no replica component to the backup
# Only process if there is replica disk space allocated
if ($ds.ReplicaSize -ne -1)
{
"Replica Used % : {0:P2}" -f $ReplicaUsedPercent

if($ReplicaUsedPercent -gt $ReplicaThreshold/100)
{
$ReplicaGrowByActual = ($ReplicaGrowBy/100)*$ds.ReplicaSize
$NewReplicaSize = $ds.ReplicaSize + $ReplicaGrowByActual
"Replica Grow % : {0:P2}" -f $($ReplicaGrowBy/100)
write-host $("Replica Grow Actual (GB) : {0:N2}" -f $($ReplicaGrowByActual/1GB)) -foregroundcolor $ChangeHighlightColor
"Replica New Total (GB) : {0:N2}" -f $($NewReplicaSize/1GB)

if ($Mode -eq "C")
{
Set-DatasourceDiskAllocation -Manual -Datasource $ds -ProtectionGroup $MPG -ReplicaArea $NewReplicaSize
}
}
else
{
"Replica Grow % : 0.00 %"
"Replica Grow Actual (GB) : 0.00"
"Replica New Total (GB) : {0:N2}" -f $(($ds.ReplicaSize)/1GB)
}
}
else
{
"No disk space allocated for replica"
}

# $ds.ShadowCopyAreaSize = -1 when there is no shadow copy component to the backup
# Only process if there is shadow copy disk space allocated
if ($ds.ShadowCopyAreaSize -ne -1)
{
"Recovery Point Used % : {0:P2}" -f $ShadowCopyUsedPercent

if($ShadowCopyUsedPercent -gt $ShadowCopyThreshold/100)
{
$ShadowCopyGrowByActual = ($ShadowCopyGrowBy/100)*$ds.ShadowCopyAreaSize
$NewShadowCopySize = $ds.ShadowCopyAreaSize + $ShadowCopyGrowByActual
"Recovery Point Grow % : {0:P2}" -f $($ShadowCopyGrowBy/100)
write-host $("Recovery Point Grow Actual (GB): {0:N2}" -f $($ShadowCopyGrowByActual/1GB)) -foregroundcolor $ChangeHighlightColor
"Recovery Point New Total (GB) : {0:N2}" -f $($NewShadowCopySize/1GB)

if ($Mode -eq "C")
{
Set-DatasourceDiskAllocation -Manual -Datasource $ds -ProtectionGroup $MPG -ShadowCopyArea $NewShadowCopySize
}
}
else
{
"Recovery Point Grow % : 0.00 %"
"Recovery Point Grow Actual (GB): 0.00"
"Recovery Point New Total (GB) : {0:N2}" -f $($ds.ShadowCopyAreaSize/1GB)
}
}
else
{
"No disk space allocated for recovery point"
}
}

# Update the protection group if we are in change mode
if ($Mode -eq "C")
{
Set-ProtectionGroup $MPG
}
}

Disconnect-DPMServer $DPMServerName

"------------------------------------------------------------------------"



I LOVE the –MODE switch, allowing me to run the script, and see the results, without actually changing any disk allocations.  I’ve added this script to the DPM servers that I manage, and have the task scheduler run it twice a day.  No more failed jobs due to lack of disk space!  Yeah!

1 comments:

BA said...

Great post, Did you just configure task schedular to run the script?

Welcome!

I use Microsoft System Center Data Protection Manager 2007 on a daily basis, and although it is a great product, it takes a lot to master. I have created this blog to share my experiences with DPM with other System Administrators out there. All of my experience with DPM is in the role of protecting Microsoft Exchange 2007, and SQL server (the DPM database itself).

There have been many issues that I've run across, and not been able to find answers for on the Internet, so I'm going to "pay it forward" to the IT community!

Hope you find this blog informative!