fredag 25 oktober 2013

PowerShell script for adding specific catalouge protection to a Protection Group

This blogpost is with regards to Mukul Singh Shekhawat and Balaji Hariharan

Lately I got a question from a friend of mine working for the PFE organization at Microsoft. The question was how to create a PowerShell script that will add an explicit catalogue present on a volume to a protection group.

Here is the script:
 
$dpmname = "DPMServername.somedomain.com"
$psname = "PSservername.somedomain.com"
$dsname = "G:\"
$poname = "G:\ProtectableFolder"
$pgname = "MyCLIPG"
 
function CreatePG
{
                param($dpmname, $psname, $dsname, $poname, $pgname)
 
                write-host "Creating a D->D PG --> $pgname..."
 
                trap{"Error in execution... ";break}
                &{           
                                Write-Host "Getting PS: $psname from DPM: $dpmname"
                                $ps = Get-ProductionServer -DPMServerName $dpmname | where { ($_.machinename,$_.name) -contains $psname }
                               
                                Write-Host "Running Inquiry on PS: $psname for datasource $dsname"
                                $ds = Get-Datasource -ProductionServer $ps -Inquire | where { ($_.logicalpath,$_.name) -contains $dsname }
                              
                                Write-Host "Getting Child-datasource $poname from datasource $dsname"
                                $po = Get-ChildDatasource -ChildDatasource $ds -Inquire | where { ($_.logicalpath,$_.name) -contains $poname }
 
                                write-host "Create New PG ..."
                                $pg = New-ProtectionGroup -DPMServerName $dpmname -Name $pgname
 
                                write-host "Adding child datasource..."
                                Add-childDatasource -ProtectionGroup $pg -ChildDatasource $po
 
                                write-host "Setting Protection Type..."
                                Set-ProtectionType -ProtectionGroup $pg -ShortTerm disk
 
                                write-host "Setting Policy Objective...retention range - 10Days, synchronizationFrequency 15"
                                Set-PolicyObjective -ProtectionGroup $pg -RetentionRangeInDays 10 -SynchronizationFrequency 15
                                
                                write-host "Setting Policy Schedules ..."
                                $ShadowCopysch = Get-PolicySchedule -ProtectionGroup $pg -ShortTerm| where { $_.JobType -eq "ShadowCopy" }
                                Set-PolicySchedule -ProtectionGroup $pg -Schedule $ShadowCopysch -DaysOfWeek mo -TimesOfDay 02:00
 
                                write-host "Setting Disk Allocation, with optimization (will take a few minutes to complete)"
                                Get-DatasourceDiskAllocation -Datasource $ds -Calculatesize
                                Set-DatasourceDiskAllocation -Datasource $ds -ProtectionGroup $pg
 
                                write-host "Setting Replica Creation Method ..."
                                Set-ReplicaCreationMethod -ProtectionGroup $pg -NOW
 
                                write-host "Commiting PG"
                                Set-protectiongroup $pg
 
                }
}
 
function waitforIRtoComplete
{
 
                param($waittime)
 
                write-host "Wait for IR to complete"           
 
                $val = $waittime/30
 
                while($val -gt 0)
 
                {
 
                                Write-host "Wait for IR to complete... $val"
 
                                start-sleep 30
 
                                $val--
 
                }           
 
}
 
Connect-DPMServer -DPMServerName $dpmname;
 
createPG $dpmname $psname $dsname $poname $pgname;
 
waitforIRtoComplete 120; 
 
 
 

Inga kommentarer:

Skicka en kommentar