Pages

torsdag 30. mai 2013

DPM: Run Weekly ExpressFull with data integrity check

It is important that your backup is consistent with the source. When backing up SQL server databases, you should to a periodic data integrity check. I like to do this on a weekly schedule. I use a PowerShell script for this and schedule it with Task Scheduler. The script looks like this:
 Param(  
  [string]$DPMServer  
 )  
 # Import the DPM PowerShell module  
 $installPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Data Protection Manager\Setup" "UIInstallPath").UIInstallPath  
 $dpmModuleFullPath = $installPath + "Modules\DataProtectionManager\DataProtectionManager.psd1"  
 Import-Module $dpmModuleFullPath  
 # Use local host if DPM Server is not specified  
 If(!$DPMServer) {$DPMServer = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName}  
 # Failed to connect To DPM server  
 If (!(Connect-DPMServer $DPMServer)) {Exit 1}  
 $pglist = Get-DPMProtectionGroup -DPMServerName $DPMServer | Where-Object {$_.IsPGDisconnected -eq $False}  
 # No Protection group found  
 If(!$pglist) {Exit 2}  
 ForEach ($pg in $pglist) {  
  $pgname = $pg.FriendlyName  
  # Get all datasources with active protection and of type starting with SQL Server  
  $dslist = Get-DPMDatasource -ProtectionGroup $pg | Where-Object {$_.Protected -eq $True -and $_.Type.Name -like 'SQL Server*'}  
  If($dslist) {   
   ForEach ($ds in $dslist) {  
    $dstype = $ds.Type.Name  
    $dsname = $ds.Name  
    # Create Recovery Point Job ExpressFull with dataintegritycheck  
    New-DPMRecoveryPoint -Datasource $ds -Disk -BackupType ExpressFull -WithDataIntegrityCheck  
   }  
  }  
 }  
 Exit 0  

To schedule this, say to run at 02:00 every Saturday of every week, use this command on your DPM server:
schtasks.exe /Create /F /TN "DPM Start SQL RP With CC" /SC "WEEKLY" /RU "SYSTEM" /D SAT /ST 02:00 /TR "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -nologo -file \"c:\scripts\StartSQLRPWithCC.ps1\""