RestoreConflicted.VBS


02 / JAN, 2008 NOTE: NEW VERSION OF THIS SCRIPT AVAILABLE HERE

——–

 

‘==========================================================================


‘ NAME: RestoreConflicted.VBS

‘  AUTHOR: James Carr, EPS, Microsoft Corporation
‘  AUTHOR: Ned Pyle, EPS, Microsoft Corporation


‘  COMMENT: Disaster Recovery script for pulling DFSR data out of ConflictAndDeleted
‘           and putting it back into a usable directory tree, preserving paths
‘           names, and security descriptor info.

‘  USAGE: Replace the 3 variables in the “operator edited” section below
‘         with valid paths. The Script will copy the contents of the CandDFolder
‘         to a specified path, returning files to original names and adding back
‘         their folder structure at the time of deletion.

‘         It is important to note that duplicate conflicts will not copy – check
‘         the restoreconflicted.log to see which files need manual intervention
‘         (this is done to prevent the accidental restore of an older conflicted copy)

‘         Finally: this tool can only copy files that were preserved in ConflictAndDeleted
‘         by quota (by default, 660MB). If the quota prevented all files from being saved
‘         this script is not going to help for those that were trimmed out.

‘  VERSION HISTORY:

‘   1.01 / 09/25/06 –
‘         Added support for whitespace in shelled XCOPY commands (thanks to sabinn, kapilme for catching) 

‘   1.00 / 08/25/06 –
‘   First working version


‘ This script is provided “AS IS” with no warranties, and confers no rights.
‘ For more information please visit
http://www.microsoft.com/info/cpyright.mspx to find terms of use.

‘==========================================================================


Dim Source
Dim Dest
Const quote = “”””

‘ Startup XML
Set objXMLDoc = CreateObject(“Microsoft.XMLDOM”)
objXMLDoc.async = False

‘ Set File Move Environment
Set objShell = WScript.CreateObject(“WScript.Shell”)

 

‘=======================================================================
‘ Section must be operator-edited to provide valid paths
‘=======================================================================

‘ Change path to specify location of C&D Manifest
objXMLDoc.load(“C:replicatedfolderDfsrPrivateConflictAndDeletedManifest.xml”)

‘ Change path to specify location of conflicted files
CandDFolder = (“C:replicatedfolderDfsrPrivateConflictAndDeleted”)

‘ Change path to specify output folder
OutputFolder = (“c:dfsr_repair_tree”)

‘========================================================================

 

set objRootNodes = objXMLDoc.documentElement.ChildNodes

For Each objRootNode In objRootNodes
  
  Set objChildNodes = objRootNode.ChildNodes
  For Each objChildNode in objChildNodes
      
       If objChildNode.nodeName = “Path” then
   StrFullPath = objChildNode.firstChild.nodeValue
       end if
 
             
       If objChildNode.nodeName = “NewName” then
 
   GuidName = objChildNode.firstChild.nodeValue

          If GuidName <> “” then  
             
              Length = Len(StrFullPath)
              StrExtract = Mid(strFullPath, 7, Length-6) 

              Source = CandDFolder & GuidName
              Dest = OutputFolder & strExtract

       wscript.echo “CMD /C XCOPY ” & quote & Source & quote & ” ” & quote & Dest & quote & ” ” & “/Q /H /R /O”
       objShell.Run “CMD /C ECHO F | XCOPY ” & quote & Source & quote & ” ” & quote & Dest & quote & ” ” & “/Q /H /R /O /F >> restoreconflicted.log”,0,TRUE

      
          end if
        
       end if

  Next

Next