Friday, January 16, 2009

Script – Create Recovery Points

In the environment that I work, DPM protects the Exchange 2007 servers.  I have only one Exchange server in each protection group.  Each Exchange server has between 10-20 Storage Groups (or Data Sources).  If I want to initiate a backup on the entire server, it is a pain to select each storage group, click Create Recovery Point, and select either Full or Incremental, then click Close. 

The script below does all that for me.  It connects to the DPM server, lists the Protection Groups, asks if you want to run an Express Full, or Incremental backup, then initiates the jobs for each Data Source in the Protection Group (each Storage Group on the Exchange Server).

# DPM 2007 Powershell Script
# Script to initiate a Recovery Point for each Data Source in a Protection Group
# Initial Script from Technet, but Modified to give more choices
# Edited by Dan Burgess
# nerd@EverydayNerd.com

param([string] $dpmname, [string] $pgname, [string] $backupoption)
# Clear the screen
cls
#Get name of Localhost
$CompStat = Get-WmiObject win32_computersystem
$Localhst = $CompStat.Name

# Notify that connected to Localhost
write-host ""
write-host "Script: Create-RecoveryPoint" -foregroundcolor Blue -backgroundcolor white
write-host ""
write-host ""
Write-host "Connected to Localhost: $Localhst" -foregroundcolor Blue -backgroundcolor white
write-host ""
write-host ""

# Set DPM Servername
$dpmname = read-host "DPM Server Name (Enter for $Localhst):"
if ($dpmname -eq "")
{
$dpmname = $Localhst
write-host "Using Localhost $dpmname " -foregroundcolor green
write-host ""
write-host ""
}

# List Protection Groups on DPM server
$pglist = get-protectiongroup -DPMServerName $dpmname
write-host "Protection Groups on $dpmname :" -foregroundcolor green
write-output $pglist
write-host ""
write-host ""

#Enter name of Protection Group you wish to create Recovery Point
$pgname = read-host "Enter Protection Group Name:"
write-host ""
write-host ""

#List choices for JobChoice1 Variable
write-host "1: Express Full"
write-host "2: Incremental"
write-host ""

$JobChoice1 = read-host "Enter Backup type - 1 or 2 [Default is 1: Express Full]:"

switch ($JobChoice1)
{
1 { $backupoption = 'ExpressFull' }
2 { $backupoption = 'Incremental' }
default { $backupoption = 'ExpressFull' }
}
write-host ""
Write-host "You selected $backupoption" -foregroundcolor Blue -backgroundcolor white
write-host ""

trap{"Error in execution... $_";break}
&{
write-host "Getting ProtectionGroup $pgname in $dpmname..."
write-host ""
$clipg = Get-ProtectionGroup $dpmname | where { $_.FriendlyName -eq $pgname}
if($clipg -eq $abc)
{
write-host ""
Throw "No ProtectionGroup found"
write-host ""
}
else
{
write-host ""
write-host "Getting DataSource from Protection Group $pgname..." -foregroundcolor green
write-host ""

# Create variable of each Datasource from Protection Group
$backupds = @(Get-Datasource $clipg)

# Run the Job for each DataSource in Protection Group
foreach ($ds in $backupds)
{
write-host ""
write-host "Creating Recovery point for $ds..." -foregroundcolor Blue -backgroundcolor white
write-host ""

$job = New-RecoveryPoint -Datasource $ds -Disk -BackupType $backupoption
$jobtype = $job.jobtype
Write-host "$jobtype Job has been triggerred..." -foregroundcolor green
}
}
}



I’ve been playing around with this script for a while, and there is more that I want to do to it, but I figured I’d share it, and hope it helps someone out.  I’d love some input on how to make the script better!



One thing I’d really like to do, but have not been able to figure it out yet, is have a status update at the end, updating every 10 seconds showing the Server name, PGname, Status, and HasCompleted – until True.  Just a thought… would save me from having to RDP into all the DPM servers…

2 comments:

Kieran Walsh said...

Hi there
Would like to use your script,but when I run it I get an error that "get-protectiongroup" is not a recognised cmdlet.

Thanks

Kieran Walsh said...

Oops, found the answer myself. I need to run the command from the right place. I saved it to the C: drive and use this command to launch it:

C:\Windows\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft DPM\DPM\bin\dpmshell.psc1" -command ".'C:\createrecoverypoints.ps1'"

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!