CLI script: Create protection groups for Disk based backups

Published Feb 14 2019 08:15 PM 36 Views
First published on TECHNET on Mar 18, 2008

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"



%3CLINGO-SUB%20id%3D%22lingo-sub-340376%22%20slang%3D%22en-US%22%3ECLI%20script%3A%20Create%20protection%20groups%20for%20Disk%20based%20backups%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-340376%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Mar%2018%2C%202008%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EThe%20following%20script%20creates%20a%20protection%20group%20with%20disk%20based%20protection%2C%20for%20a%20simple%20folder.%20It%20can%20be%20easily%20extended%20to%20add%20more%20data%20sources%20of%20different%20kinds%20%E2%80%93%20like%20Microsoft%20Exchange%2C%20SQL%2C%20Sharepoint%2C%20System%20state%20or%20Virtual%20Servers.%20The%20Synchronization%20frequency%20and%20retention%20ranges%20etc.%20can%20be%20easily%20modified%20to%20suit%20your%20needs.%26nbsp%3B%20Also%2C%20since%20we%20are%20protecting%20a%20sub-folder%20in%20a%20volume%2C%20we%20are%20using%20the%20CalculateSize%20parameter%20in%20Get-DataSourceDiskAllocation%2C%20which%20would%20calculate%20the%20exact%20size%20needed%20for%20all%20the%20items%20in%20that%20folder.%20This%20is%20not%20needed%20when%20protecting%20an%20application%20like%20Exchange%2FSQL%20or%20protection%20the%20entire%20File%20system%20volume.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E----------------------------------------------%20Start%20of%20Script%20---------------------------------------------------%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%23%20To%20D2D%20create%20PG%20and%20do%20the%20initial%20replication%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%23%20This%20script%20is%20for%20creating%20Disk%20to%20Disk%20PG%20for%20File%20System%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%23%20For%20details%20contact%20mukuls%5Bat%5Dmicrosoft%5Bdot%5Dcom%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%23%20Create%20a%20.ps1%20file%20with%20this%20script%20and%20run%20under%20DPM%20Management%20Shell%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%23%20Customize%20these%20values%20as%20per%20your%20environment%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24dpmname%20%3D%20%22DPMServername.somedomain.com%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24psname%20%3D%20%22PSservername.somedomain.com%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24dsname%20%3D%20%22G%3A%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24poname%20%3D%20%22G%3AProtectableFolder%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24pgname%20%3D%20%22MyCLIPG%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Efunction%20CreatePG%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eparam(%24dpmname%2C%20%24psname%2C%20%24dsname%2C%20%24poname%2C%20%24pgname)%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Creating%20a%20D-%26gt%3BD%20PG%20--%26gt%3B%20%24pgname...%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Etrap%7B%22Error%20in%20execution...%20%22%3Bbreak%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%26amp%3B%7B%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EWrite-Host%20%22Getting%20PS%3A%20%24psname%20from%20DPM%3A%20%24dpmname%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24ps%20%3D%20Get-ProductionServer%20-DPMServerName%20%24dpmname%20%7C%20where%20%7B%20(%24_.machinename%2C%24_.name)%20-contains%20%24psname%20%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EWrite-Host%20%22Running%20Inquiry%20on%20PS%3A%20%24psname%20for%20datasource%20%24dsname%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24ds%20%3D%20Get-Datasource%20-ProductionServer%20%24ps%20-Inquire%20%7C%20where%20%7B%20(%24_.logicalpath%2C%24_.name)%20-contains%20%24dsname%20%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EWrite-Host%20%22Getting%20Child-datasource%20%24poname%20from%20datasource%20%24dsname%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24po%20%3D%20Get-ChildDatasource%20-ChildDatasource%20%24ds%20-Inquire%20%7C%20where%20%7B%20(%24_.logicalpath%2C%24_.name)%20-contains%20%24poname%20%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Create%20New%20PG%20...%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24pg%20%3D%20New-ProtectionGroup%20-DPMServerName%20%24dpmname%20-Name%20%24pgname%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Adding%20child%20datasource...%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EAdd-childDatasource%20-ProtectionGroup%20%24pg%20-ChildDatasource%20%24po%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Setting%20Protection%20Type...%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESet-ProtectionType%20-ProtectionGroup%20%24pg%20-ShortTerm%20disk%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Setting%20Policy%20Objective...retention%20range%20-%2010Days%2C%20synchronizationFrequency%2015%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESet-PolicyObjective%20-ProtectionGroup%20%24pg%20-RetentionRangeInDays%2010%20-SynchronizationFrequency%2015%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Setting%20Policy%20Schedules%20...%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24ShadowCopysch%20%3D%20Get-PolicySchedule%20-ProtectionGroup%20%24pg%20-ShortTerm%7C%20where%20%7B%20%24_.JobType%20-eq%20%22ShadowCopy%22%20%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESet-PolicySchedule%20-ProtectionGroup%20%24pg%20-Schedule%20%24ShadowCopysch%20-DaysOfWeek%20mo%20-TimesOfDay%2002%3A00%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Setting%20Disk%20Allocation%2C%20with%20optimization%20(will%20take%20a%20few%20minutes%20to%20complete)%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EGet-DatasourceDiskAllocation%20-Datasource%20%24ds%20-Calculatesize%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESet-DatasourceDiskAllocation%20-Datasource%20%24ds%20-ProtectionGroup%20%24pg%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Setting%20Replica%20Creation%20Method%20...%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESet-ReplicaCreationMethod%20-ProtectionGroup%20%24pg%20-NOW%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Commiting%20PG%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESet-protectiongroup%20%24pg%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Efunction%20waitforIRtoComplete%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eparam(%24waittime)%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewrite-host%20%22Wait%20for%20IR%20to%20complete%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%24val%20%3D%20%24waittime%2F30%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewhile(%24val%20-gt%200)%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EWrite-host%20%22Wait%20for%20IR%20to%20complete...%20%24val%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-340376%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20Mar%2018%2C%202008%20The%20following%20script%20creates%20a%20protection%20group%20with%20disk%20based%20protection%2C%20for%20a%20simple%20folder.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-340376%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESystem%20Center%20Data%20Protection%20Manager%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 11 2019 08:01 AM
Updated by: