Creates a protection group, with disk-based protection, for a simple folder. It can be extended to different data sources like Microsoft Exchange, SQL, SharePoint, system state or virtual servers. The synchronization frequency and retention ranges can be modified to suit different needs.

Because the script protects a sub-folder in a volume, the code uses the CalculateSize parameter in Get-DataSourceDiskAllocation; this calculates the exact size needed for all the items in that folder. This parameter is not needed when protecting an application like Exchange/SQL or protection the entire file system volume.

This script was contributed by the System Center Data Protection Manager (DPM) team.

Visual Basic
Edit|Remove
# 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"
        start-sleep 30
        $val--
    }
}
Connect-DPMServer -DPMServerName $dpmname;
createPG $dpmname $psname $dsname $poname $pgname;
waitforIRtoComplete 120;