CLI script: Create protection groups for Disk based backups

The following script creates a protection group with disk based protection, for a simple folder. It can be easily extended to add more data sources of different kinds – like Microsoft Exchange, SQL, Sharepoint, System state or Virtual Servers. The Synchronization frequency and retention ranges etc. can be easily modified to suit your needs.  Also, since we are protecting a sub-folder in a volume, we are using the CalculateSize parameter in Get-DataSourceDiskAllocation, which would calculate the exact size needed for all the items in that folder. This is not needed when protecting an application like Exchange/SQL or protection the entire File system volume.

 

———————–———————– Start of Script —————————-———————–

# To D2D create PG and do the initial replication

# This script is for creating Disk to Disk PG for File System

# For details contact mukuls[at]microsoft[dot]com

# Create a .ps1 file with this script and run under DPM Management Shell

 

# Customize these values as per your environment

 

$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”