Monitored Robocopy Replication

Replace DFS with a monitored robocopy script.

DFS has been a great system you would use to replicate files from one site to another; however one of the biggest limitations is the inability of monitoring it, IE – daily log to show that:

  • It is still working
  • To show WHAT is getting replicated

As a replacement I have taken a step backwards and setup a robocopy script as a scheduled task to mirror a source in a different location and a second script to send you the logs. Plain and simple.

The robocopy script is as follows:

@ECHO OFF
SETLOCAL

::SET _source=”c:Example Source Folder”
SET _source=
SET _dest=”d:Example Destination Folder”
SET _dest=f:

SET _what=/COPYALL /B /SEC /A-:H /MIR /XD “C:System Volume Information”
:: /COPYALL :: COPY ALL file info

:: /B :: copy files in Backup mode.
:: /SEC :: Copy security Descriptors
:: /MIR :: MIRror a directory tree
:: /XD  :: Copy except for the following folders
:: /XF  :: Exclude file(s) – ie the log file
:: /A   :: Set attributes

SET _options=/R:3 /W:5 /LOG:C:robolog.txt /NP /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file; can be placed of a network share
:: /NFL :: No file logging
:: /NDL :: No dir logging
:: /NP  :: No Progress – does not show progress bar

ROBOCOPY %_source% %_dest% %_what% %_options%

Now that we have replication, lets get some logging:

Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = “Replication logs”
objMessage.From = “sender@contoso.com”
objMessage.To = “recipient@contoso.com”
objMessage.TextBody = “Please find attached you backup logs.”
objMessage.AddAttachment “c:robolog.txt”
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver“) = “servername
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25
objMessage.Configuration.Fields.Update
objMessage.Send