This task triggers synchronization for all data sources protected by this DPM server that have active "Synchronization failures (3115)" alert.
Synchronization failures have been reported for data source protected by this DPM server.
Click Run to perform synchronization for all data sources under this DPM server for which synchronization failure was reported.
Target | Microsoft.Windows.SystemCenterDPM.DPMServer |
Accessibility | Internal |
Category | Maintenance |
Enabled | True |
Remotable | False |
Timeout | 300 |
ID | Module Type | TypeId | RunAs |
---|---|---|---|
Script | WriteAction | Microsoft.Windows.ScriptWriteAction | Default |
<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>
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oArgs = WScript.Arguments
if oArgs.Count < 1 Then
call oAPI.LogScriptEvent("DPMTasks", 12, 1, "Expected 1 argument. There were only " & oArgs.Count & " 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 & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If
Dim dpmShellPath
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Microsoft Data Protection Manager\Setup"
strValueName = "InstallPath"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue
dpmShellPath = """" & strValue & "bin\dpmshell.psc1" & """"
'MsgBox "The DPM InstallPath is: " & strValue
set objFile = Nothing
set objFolder = Nothing
strText=" $xmlfilepath = """ + strDirectory + """" &_
Chr(10) & " # This script triggers synchronization for all data sources on DPM having "&_
Chr(10) & " # active synchronization failure alert in the last n days, Alert Id 3115. "&_
Chr(10) & " # Author: NageshBK Date: 08-May-2008 "&_
Chr(10) & " if($args.count -ne 1) "&_
Chr(10) & " { "&_
Chr(10) & " Write-Host ""Usage: TriggerSync_DPM.ps1 <Last N days>"" "&_
Chr(10) & " Write-host ""Example: TriggerSync_DPM.ps1 3"" "&_
Chr(10) & " exit 0; "&_
Chr(10) & " } "&_
Chr(10) & "$dpmServerName = $env:computername " &_
Chr(10) & "$dpmServer = Connect-DPMServer $dpmServerName " &_
Chr(10) & "if (!$dpmServer) " &_
Chr(10) & "{ " &_
Chr(10) & " Write-Error ""Unable to connect to $dpmServerName"" " &_
Chr(10) & " exit 1 " &_
Chr(10) & "} " &_
Chr(10) & " $ErrorActionPreference = ""silentlycontinue"" "&_
Chr(10) & " $dpmName = $env:computername "&_
Chr(10) & " $noOfDays= $args[0]; "&_
Chr(10) & " $alertId = ""3115"" "&_
Chr(10) & " $logName = ""DPM Alerts"" "&_
Chr(10) & " # Find all DSs ids, which are having active synchronization failure alert in last $noOfDays "&_
Chr(10) & " $alertIdPos = 1 "&_
Chr(10) & " $dSIdPos = 5 "&_
Chr(10) & " $activeAlert = 1 "&_
Chr(10) & " $closedAlert = 2 "&_
Chr(10) & " $dsList = @{} "&_
Chr(10) & " Get-Datasource -DPMServerName $dpmName | where {$_.Protected} | foreach-object {$dsList[($($_.id.tostring()))]=1} "&_
Chr(10) & " $curDate = Get-Date "&_
Chr(10) & " $lastDate = $curDate.AddDays(0-$noOfDays) "&_
Chr(10) & " #Find all alerts in last $noOfDays days "&_
Chr(10) & " $alerts = get-eventlog $logName | where {($_.TimeGenerated -gt $lastDate) -and ($_.replacementStrings[$alertIdPos] -eq $alertId)} "&_
Chr(10) & " #Find all datasources with active alert "&_
Chr(10) & " $targetDsList = @{} "&_
Chr(10) & " foreach($a in $alerts) "&_
Chr(10) & " { "&_
Chr(10) & " $dsId = $a.replacementstrings[$dSIdPos] "&_
Chr(10) & " if(($a.eventID -eq $activeAlert) -and ($dsList.containskey($dsId))) { "&_
Chr(10) & " $targetDsList[$dsId] = 1 "&_
Chr(10) & " $dsList.remove($dsId) "&_
Chr(10) & " } elseif(($a.eventID -eq $closedAlert) -and ($dsList.containskey($dsId))) { "&_
Chr(10) & " $dsList.remove($dsId) "&_
Chr(10) & " } "&_
Chr(10) & " } "&_
Chr(10) & " $dSources = @(Get-Datasource -DPMServerName $dpmName | where {$targetDsList.contains($($_.id.tostring()))}) "&_
Chr(10) & " #Trigger synchronization and log results for all datasources with active alert "&_
Chr(10) & " $log = ""<DPM Name=`""$dpmName`"" Job=`""Synchronization`"">"" "&_
Chr(10) & " foreach($ds in $dSources) "&_
Chr(10) & " { "&_
Chr(10) & " $pg = Get-ProtectionGroup $dpmName | ?{$_.Protectiongroupid -eq $ds.ProtectionGroupId} "&_
Chr(10) & " $ProtectionType = $pg.PGProtectiontype "&_
Chr(10) & " if($ProtectionType -ieq ""DiskToDisk"" -or $ProtectionType -ieq ""DiskToDiskToTape"") { "&_
Chr(10) & " $log += ""`n<Log PS=`""$($ds.ProductionServerName)`"" DS=`""$($ds.NAme)`"" "" "&_
Chr(10) & " $j=New-RecoveryPoint -Datasource $ds -Disk -DiskRecoveryPointOption ""OnlySynchronize"" "&_
Chr(10) & " if($j) { "&_
Chr(10) & " $res = ""Success""; "&_
Chr(10) & " $details = """"; "&_
Chr(10) & " } else { "&_
Chr(10) & " $res = ""Fail""; "&_
Chr(10) & " $details = $($error[0].ToString()); "&_
Chr(10) & " } "&_
Chr(10) & " $log += ""Result=`""$res`""> ""; "&_
Chr(10) & " $log+= ""`n<Details> $details</Details> </Log>"" "&_
Chr(10) & " } "&_
Chr(10) & " } "&_
Chr(10) & " $log += ""`n</DPM>"" "&_
Chr(10) & " Disconnect-DPMServer "&_
Chr(10) & " $xmlfile = [xml] $log "&_
Chr(10) & " $xmlfile.save((Join-path $xmlfilepath ""DPMSynchronization.xml"")) "
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForWriting = 2
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForWriting, True)
' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close
psfile = strDirectory & strFile
strCMD="powershell -PSConsoleFile " & dpmShellPath & " -nologo -command " & psfile & " " & strNoOfDays
'Uncomment next line for debugging
'MsgBox("strCMD: " & strCMD)
'use 0 to hide window
objShell.Run strCMD,0,true
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(strDirectory & "\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) </ScriptBody>
<TimeoutSeconds>600</TimeoutSeconds>
</WriteAction>
</Task>