Jump to content









Photo

Powershell script to export DPM recovery points

PowerShell DPM Data Protection Manager System Center 2012 R2

  • Please log in to reply
No replies to this topic

#1 Panagiotis Pataridis

Panagiotis Pataridis

    Enterprise Admin!

  • Administrators
  • 1,218 posts

Posted 02 March 2016 - 06:32 PM

Αυτό είναι ένα μικρό script το οποίο έγραψα με τη συμβολή του Γιώργου Βαράκη (aka the Veteran IT!) το οποίο κάνει μια απλή αλλά πολύ σημαντική λειτουργία που δεν μπορεί να γίνει με κάποιο τρόπο από το GUI. "Βγάζει" τα τελευταία recovery points του Microsoft System Center Data Protection Manager σε ένα εξωτερικό δίσκο για αποθήκευση κάπου εκτός του Datacenter.  Και είναι πολύ σημαντικό ,καθώς ο DPM Server μπορεί να έχει μια δεύτερη εγκατάσταση σε ένα άλλο datacenter και μέσω της διαδικασίας chaining να μπορούμε να έχουμε και τα Backup της εταιρείας μας στο Continuity Plan , κάποιες φορές χρειαζόμαστε απλά να πάρουμε τα backups και να τα στείλουμε κάπου έξω από το κτίριο πολύ εύκολα (φυσικά κρυπτογραφώντας τα με Bitlocker!) .

<#This script will export the latest recovery point of each datasource in a Microsoft System Center 2012 R2 DPM installation to a disk. This disk can be an external disk for offsite storage.
In order for DPM to run the recovery procedure a DPM agent must be installed on the server hosting the external disk.
Below there is a Variable section in which you should specify the DPM server name , the target server name as well as the disk drive letter.
I have also added a small part in which you can remove previous versions of the backup as a a small retention policy.
You can also specify which protection groups you want exported , or the script will select all of them. I have not added a Sharepoint recovery because it is a bit more complicated than simply extracting the data.

AX Enjoy! 

#>

#Start by importing the System Center 2012 R2 Module
import-Module "C:\Program Files\Microsoft System Center 2012 R2\DPM\DPM\bin\dpmcliinitscript.ps1"

#------------------------------------------------------------------------------------------------------#
#Arm the variables
#Who's the DPM Server
$DPMServerName = "DPMServer"
#Who's the target server? (The server that has an agent installed and the usb hdd)
$DestinationServerName = "TargetServer"
#What's the disk location for the exports? (What is the drive letter on the usb drive?)
$DestinationLocation = "X:\DPM\"
#Create a datetime format for the folders
$Date = (get-date -DisplayHint date -Format yyyy-MM-dd).ToString()
#Protection groups for which we want the exports, if you do not specify it ,all protection groups will be selected , an example would be @("PG_ONE","PG_TWO","SQL") etc
$ProtectionGroupName=@()
#Get the older backups  to compare and delete
$files=get-childitem "\\TargetServer\e$\DPM"
#Set the retention period , recovery points (and files!any file! be warned!) older than the days specified will be deleted on the target hdd.
$Days="-2"
#------------------------------------------------------------------------------------------------------#
#Start by removing previous backups
#Set the exclusion date in minutes,hours or days
$Today=(Get-Date).AddDays($Days)  
#Start comparing files
Foreach ($File in $Files)
    {
     #If you find a file that is older than the expected date 
     if ($file.Creationtime -lt $Today)
          #Delete the sucker
          {remove-item $file.FullName}
    }

#OK, let's see what we got
#Create an array and connect to the DPM Server
$ProtectionGroups=@()
Connect-DPMServer $DPMServerName

#Get protection groups,if specified ,otherwise get all of the protection groups
If($ProtectionGroupName.Count -ne 0)
    {
        foreach($Name in $ProtectionGroupName)
        {
        $ProtectionGroups+=Get-DPMProtectionGroup -DPMServerName $DPMServerName |? {$_.Name -eq $Name}
        }
    }    
      Else
      {
      $ProtectionGroups=Get-DPMProtectionGroup -DPMServerName $DPMServerName 
      }
    
#If you found something , proceed ,else inform the user that nothing was found on the end of this script
If($ProtectionGroups.Count -ne 0)
{

#Let's see what's inside the Protection Groups
foreach ($ProtectionGroup in $ProtectionGroups)
    {
        #Get the Datasource information , because each protection group might have different protected sources 
        $Datasources=  Get-datasource -ProtectionGroup $ProtectionGroup
        
        #Start the processing 
        foreach($Datasource in $Datasources)
            {
            
            #Get the last recovery point for the selected datasource,we only need that to restore
            $LastRecoveryPoint = Get-DPMRecoveryPoint -DataSource $Datasource | sort -Property RepresentedPointInTime -Descending | select -first 1
                    
            #Start filtering the datasource so that we get the correct type to proceed with recovery, as each type has a different cmdlet set
            #If you find a hyperv datasource
            If($Datasource.ObjectType -match "Hyper-V")
                 {
                 #Construct the foder path using the variables, since all of the VM protected workloads use an Offile\ or Online\ we only need the LastRecoveryPoint.Name 
                 $DestinationLocationFinal=$DestinationLocation+$Datasource.ProductionServerName+"\"+ $LastRecoveryPoint.Name+" "+ $Date
                 
                 #Specify recovery options for the selected Type
                 $RecoveryOption = New-DPMRecoveryOption -HyperVDataSource -TargetServer $DestinationServerName -RecoveryLocation CopyToFolder -RecoveryType Restore -TargetLocation $DestinationLocationFinal
                                  
                 #Recover the sucker
                 Recover-RecoverableItem -RecoverableItem $LastRecoveryPoint -RecoveryOption $recoveryOption   
                 }
            If($Datasource.ObjectType -match "Volume")
                 {
                 #Construct the foder path using the variables, this is a bit more complicated as volume based datasources use a Drive:\ scheme, we need to trim out the ":\" part to construct a working NTFS path
                 $DatasourceName=$LastRecoveryPoint.name.Trim(":\")
                 $DestinationLocationFinal=$DestinationLocation+$Datasource.ProductionServerName+"\"+ $DatasourceName+" "+ $Date
                 
                 #Specify recovery options for the selected Type
                 $RecoveryOption = New-DPMRecoveryOption -FileSystem  -TargetServer $DestinationServerName -RecoveryLocation CopyToFolder -AlternateLocation $DestinationLocationFinal -RestoreSecurity -OverwriteType NoOverwrite -RecoveryType Restore
                                  
                 #Recover the sucker
                 Recover-RecoverableItem -RecoverableItem $LastRecoveryPoint -RecoveryOption $recoveryOption   
                 }
             If($Datasource.ObjectType -match "Exchange")
                 {
                 #Construct the foder path using the variables
                 $DestinationLocationFinal=$DestinationLocation+$Datasource.ProductionServerName+"\"+ $LastRecoveryPoint.Name+" "+ $Date
                 
                 #ok , lets find the recoverable item
                 $RecoverableItem=Get-DPMRecoverableItem -RecoverableItem $LastRecoveryPoint -BrowseType Child
                 
                 #Specify recovery options for the selected Type
                 $RecoveryOption = New-DPMRecoveryOption -Exchange -TargetServer $DestinationServerName -TargetLocation $DestinationLocationFinal -ExchangeOperationType NoOperation -RecoveryLocation CopyToFolder -RecoveryType Restore 
                                  
                 #Recover the sucker
                 Recover-RecoverableItem -RecoverableItem $RecoverableItem[0] -RecoveryOption $recoveryOption   
                 }
             If($Datasource.ObjectType -match "SQL")
                 {
                 #Construct the foder path using the variables
                 $DestinationLocationFinal=$DestinationLocation+$Datasource.ProductionServerName+"\"+ $LastRecoveryPoint.Name+" "+ $Date
                 
                 #Specify recovery options for the selected Type
                 $RecoveryOption = New-DPMRecoveryOption -SQL -TargetServer $DestinationServerName -RecoveryLocation CopyToFolder -RecoveryType Restore -TargetLocation $DestinationLocationFinal
                                  
                 #Recover the sucker
                 Recover-RecoverableItem -RecoverableItem $LastRecoveryPoint -RecoveryOption $recoveryOption   
                 }
             If($Datasource.ObjectType -match "System")
                 {
                 #Construct the foder path using the variables
                 $DestinationLocationFinal=$DestinationLocation+$Datasource.ProductionServerName+"\"+ $LastRecoveryPoint.Name+" "+ $Date
                 
                 #Specify recovery options for the selected Type
                 $RecoveryOption = New-DPMRecoveryOption -SystemProtectionDatasource -TargetServer $DestinationServerName -RecoveryLocation CopyToFolder -RecoveryType Restore -TargetLocation $DestinationLocationFinal
                                 
                 #Recover the sucker
                 Recover-RecoverableItem -RecoverableItem $LastRecoveryPoint -RecoveryOption $recoveryOption   
                 }
             
             
             }

    }
    }
    Else
    {
    #Inform the user that nothing was found! 
    Write-Host "No Protection Groups found!" -ForegroundColor Yellow
    }


<# 
$Editor=

Panagiotis Pataridis

Senior IT Consultant

MCSE,MCSA,MCITP

MVP on Enterprise Mobility (Remote Desktop Services)

MS-vTSP on Desktop Experience


$SubjectMatterExpert=

George Varakis

MCSE,MCSA,MCITP

Enterprise Services Manager
#>






Also tagged with one or more of these keywords: PowerShell, DPM, Data Protection Manager, System Center 2012 R2

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users