Run synchronization for data sources

Microsoft.Windows.SystemCenterDPM.TriggerSyncronization (Task)

This task triggers synchronization for all data sources protected by this DPM server that have active "Synchronization failures (3115)" alert.

Knowledge Base article:

Summary

Synchronization failures have been reported for data source protected by this DPM server.

Resolutions

Click Run to perform synchronization for all data sources under this DPM server for which synchronization failure was reported.

Element properties:

TargetMicrosoft.Windows.SystemCenterDPM.DPMServer
AccessibilityInternal
CategoryMaintenance
EnabledTrue
RemotableFalse
Timeout300

Member Modules:

ID Module Type TypeId RunAs 
Script WriteAction Microsoft.Windows.ScriptWriteAction Default

Source Code:

<Task ID="Microsoft.Windows.SystemCenterDPM.TriggerSyncronization" Accessibility="Internal" Enabled="true" Target="Microsoft.Windows.SystemCenterDPM.DPMServer" Timeout="300" Remotable="true">
<Category>Maintenance</Category>
<WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>DPM_Sync.vbs</ScriptName>
<Arguments>3</Arguments>
<ScriptBody><Script>
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oArgs = WScript.Arguments

if oArgs.Count &lt; 1 Then
call oAPI.LogScriptEvent("DPMTasks", 12, 1, "Expected 1 argument. There were only " &amp; oArgs.Count &amp; " arguments. Exiting script.")
Wscript.Quit -1
End If

strNoOfDays = oArgs(0)

Set oBag = oAPI.CreatePropertyBag()

Dim objShell
Set objShell=CreateObject("WScript.Shell")

'enter the PowerShell expression
'you need to use short filenames and paths

sysdrv=objShell.ExpandEnvironmentStrings("%temp%")


Dim objFSO, objFolder, objTextFile, objFile
Dim strDirectory, strFile, strText, psfile, strNewGuid

set x = createobject("Scriptlet.TypeLib")
strNewGuid=left(x.GUID,37)
strNewGuid=Right(strNewGuid,36)

strDirectory = sysdrv + "\dpm_mom_Sync" + strNewGuid
strFile = "\TriggerSync_DPM.ps1"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If

If objFSO.FileExists(strDirectory &amp; strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory &amp; strFile)
End If


Dim dpmShellPath
const HKEY_LOCAL_MACHINE = &amp;H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp;_
strComputer &amp; "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Microsoft Data Protection Manager\Setup"
strValueName = "InstallPath"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue

dpmShellPath = """" &amp; strValue &amp; "bin\dpmshell.psc1" &amp; """"
'MsgBox "The DPM InstallPath is: " &amp; strValue

set objFile = Nothing
set objFolder = Nothing

strText=" $xmlfilepath = """ + strDirectory + """" &amp;_
Chr(10) &amp; " # This script triggers synchronization for all data sources on DPM having "&amp;_
Chr(10) &amp; " # active synchronization failure alert in the last n days, Alert Id 3115. "&amp;_
Chr(10) &amp; " # Author: NageshBK Date: 08-May-2008 "&amp;_
Chr(10) &amp; " if($args.count -ne 1) "&amp;_
Chr(10) &amp; " { "&amp;_
Chr(10) &amp; " Write-Host ""Usage: TriggerSync_DPM.ps1 &lt;Last N days&gt;"" "&amp;_
Chr(10) &amp; " Write-host ""Example: TriggerSync_DPM.ps1 3"" "&amp;_
Chr(10) &amp; " exit 0; "&amp;_
Chr(10) &amp; " } "&amp;_
Chr(10) &amp; "$dpmServerName = $env:computername " &amp;_
Chr(10) &amp; "$dpmServer = Connect-DPMServer $dpmServerName " &amp;_
Chr(10) &amp; "if (!$dpmServer) " &amp;_
Chr(10) &amp; "{ " &amp;_
Chr(10) &amp; " Write-Error ""Unable to connect to $dpmServerName"" " &amp;_
Chr(10) &amp; " exit 1 " &amp;_
Chr(10) &amp; "} " &amp;_
Chr(10) &amp; " $ErrorActionPreference = ""silentlycontinue"" "&amp;_
Chr(10) &amp; " $dpmName = $env:computername "&amp;_
Chr(10) &amp; " $noOfDays= $args[0]; "&amp;_
Chr(10) &amp; " $alertId = ""3115"" "&amp;_
Chr(10) &amp; " $logName = ""DPM Alerts"" "&amp;_
Chr(10) &amp; " # Find all DSs ids, which are having active synchronization failure alert in last $noOfDays "&amp;_
Chr(10) &amp; " $alertIdPos = 1 "&amp;_
Chr(10) &amp; " $dSIdPos = 5 "&amp;_
Chr(10) &amp; " $activeAlert = 1 "&amp;_
Chr(10) &amp; " $closedAlert = 2 "&amp;_
Chr(10) &amp; " $dsList = @{} "&amp;_
Chr(10) &amp; " Get-Datasource -DPMServerName $dpmName | where {$_.Protected} | foreach-object {$dsList[($($_.id.tostring()))]=1} "&amp;_
Chr(10) &amp; " $curDate = Get-Date "&amp;_
Chr(10) &amp; " $lastDate = $curDate.AddDays(0-$noOfDays) "&amp;_
Chr(10) &amp; " #Find all alerts in last $noOfDays days "&amp;_
Chr(10) &amp; " $alerts = get-eventlog $logName | where {($_.TimeGenerated -gt $lastDate) -and ($_.replacementStrings[$alertIdPos] -eq $alertId)} "&amp;_
Chr(10) &amp; " #Find all datasources with active alert "&amp;_
Chr(10) &amp; " $targetDsList = @{} "&amp;_
Chr(10) &amp; " foreach($a in $alerts) "&amp;_
Chr(10) &amp; " { "&amp;_
Chr(10) &amp; " $dsId = $a.replacementstrings[$dSIdPos] "&amp;_
Chr(10) &amp; " if(($a.eventID -eq $activeAlert) -and ($dsList.containskey($dsId))) { "&amp;_
Chr(10) &amp; " $targetDsList[$dsId] = 1 "&amp;_
Chr(10) &amp; " $dsList.remove($dsId) "&amp;_
Chr(10) &amp; " } elseif(($a.eventID -eq $closedAlert) -and ($dsList.containskey($dsId))) { "&amp;_
Chr(10) &amp; " $dsList.remove($dsId) "&amp;_
Chr(10) &amp; " } "&amp;_
Chr(10) &amp; " } "&amp;_
Chr(10) &amp; " $dSources = @(Get-Datasource -DPMServerName $dpmName | where {$targetDsList.contains($($_.id.tostring()))}) "&amp;_
Chr(10) &amp; " #Trigger synchronization and log results for all datasources with active alert "&amp;_
Chr(10) &amp; " $log = ""&lt;DPM Name=`""$dpmName`"" Job=`""Synchronization`""&gt;"" "&amp;_
Chr(10) &amp; " foreach($ds in $dSources) "&amp;_
Chr(10) &amp; " { "&amp;_
Chr(10) &amp; " $pg = Get-ProtectionGroup $dpmName | ?{$_.Protectiongroupid -eq $ds.ProtectionGroupId} "&amp;_
Chr(10) &amp; " $ProtectionType = $pg.PGProtectiontype "&amp;_
Chr(10) &amp; " if($ProtectionType -ieq ""DiskToDisk"" -or $ProtectionType -ieq ""DiskToDiskToTape"") { "&amp;_
Chr(10) &amp; " $log += ""`n&lt;Log PS=`""$($ds.ProductionServerName)`"" DS=`""$($ds.NAme)`"" "" "&amp;_
Chr(10) &amp; " $j=New-RecoveryPoint -Datasource $ds -Disk -DiskRecoveryPointOption ""OnlySynchronize"" "&amp;_
Chr(10) &amp; " if($j) { "&amp;_
Chr(10) &amp; " $res = ""Success""; "&amp;_
Chr(10) &amp; " $details = """"; "&amp;_
Chr(10) &amp; " } else { "&amp;_
Chr(10) &amp; " $res = ""Fail""; "&amp;_
Chr(10) &amp; " $details = $($error[0].ToString()); "&amp;_
Chr(10) &amp; " } "&amp;_
Chr(10) &amp; " $log += ""Result=`""$res`""&gt; ""; "&amp;_
Chr(10) &amp; " $log+= ""`n&lt;Details&gt; $details&lt;/Details&gt; &lt;/Log&gt;"" "&amp;_
Chr(10) &amp; " } "&amp;_
Chr(10) &amp; " } "&amp;_
Chr(10) &amp; " $log += ""`n&lt;/DPM&gt;"" "&amp;_
Chr(10) &amp; " Disconnect-DPMServer "&amp;_
Chr(10) &amp; " $xmlfile = [xml] $log "&amp;_
Chr(10) &amp; " $xmlfile.save((Join-path $xmlfilepath ""DPMSynchronization.xml"")) "

' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForWriting = 2


Set objTextFile = objFSO.OpenTextFile _
(strDirectory &amp; strFile, ForWriting, True)

' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close

psfile = strDirectory &amp; strFile


strCMD="powershell -PSConsoleFile " &amp; dpmShellPath &amp; " -nologo -command " &amp; psfile &amp; " " &amp; strNoOfDays
'Uncomment next line for debugging
'MsgBox("strCMD: " &amp; strCMD)

'use 0 to hide window
objShell.Run strCMD,0,true


set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(strDirectory &amp; "\DPMSynchronization.xml")

Set root = xmlDoc.documentElement

For each detail in root.childnodes

errorDetail = ""
If(detail.getAttribute("Result") = "Fail" ) Then
Set temperr = detail.firstchild
errorDetail = temperr.Text
End If
objDetails = objDetails + "Protected computer:" + detail.getAttribute("PS") + " Data source:" + detail.getAttribute("DS") + " - " + errorDetail + vbLF + vbLF
Next
'MsgBox("ObjectDetails:" + objDetails)
Call oBag.AddValue("Task Status",objDetails)

'Deleting the temp folders
objFSO.DeleteFolder(strDirectory)

Call oAPI.Return(oBag)</Script></ScriptBody>
<TimeoutSeconds>600</TimeoutSeconds>
</WriteAction>
</Task>