<

Mirror Windows files and folders with Robocopy

Published on
7,494 Points
4,294 Views
2 Endorsements
Last Modified:
So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake.

You can use Robocopy from the Windows Server 2003 Resource kit tools to accomplish this.  (The resource kit tools can be found here:  http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en)

The following command will MIRROR a source directory with a remote directory.  Be CAUTIOUS because the following will not only copy source files over, but if source files/folders get removed it will then remove them from the remote/destination directory (hence the term "mirror").
 
"C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" "\\SOURCESERVER\FOLDERTOMIRROR" "\\DESTINATIONSERVER\DESTINATIONFOLDER" /MIR /LOG+:"c:\robocopylogs\mirror.log.txt"

Open in new window

 

1. Create Log Directory


Create c:\robocopylogs to hold the log files

2. Modify command with inputs


Change the above command snippet inputs (ie. change \\SOURCEFOLDER\FOLDERTOMIRROR to reflect your source folders/files to mirror) You will need to change source and destination for your needs.  It can be a folder or files.  A folder will end up mirroring everything in that folder (files/subfolders/subfiles).

3. Run Command


Put the command into notepad and save the file as a .bat.  Then doubleclick the batch file to run the command.  The log file in the command will be appended to each time.

4. Optional: Schedule command


You can use Task Scheduler to schedule the mirror to take place daily, etc.  I won't go into Task Scheduler here though.

Example Command:
 
"C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" \\orgdc01\shared\hc12\12common \\fwmnas\ipd\software\hc12\12common /MIR /LOG+:"c:\copylogs\cpyhc12.log.txt"

Open in new window

Example Output:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Wed Dec 17 08:19:51 2008

   Source : \\orgdc01\shared\hc12\12common\
     Dest : \\fwmnas\ipd\software\hc12\12common\

    Files : *.*
	    
  Options : *.* /S /E /COPY:DAT /PURGE /MIR /R:1000000 /W:30 

------------------------------------------------------------------------------

	                   0	\\orgdc01\shared\hc12\12common\
	                   0	\\orgdc01\shared\hc12\12common\os\
	                   5	\\orgdc01\shared\hc12\12common\os\12c128\
	                   5	\\orgdc01\shared\hc12\12common\os\12dp256\
	                   6	\\orgdc01\shared\hc12\12common\os\12dp512\
	    Newer     		     219	iosdp512.la
  0%  
100%  
	                   1	\\orgdc01\shared\hc12\12common\os\can\

------------------------------------------------------------------------------

                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         6         0         6         0         0         0
    Files :        17         1        16         0         0         0
    Bytes :   225.3 k       219   225.1 k         0         0         0
    Times :   0:00:09   0:00:03                       0:00:00   0:00:05

    Speed :                  63 Bytes/sec.
    Speed :               0.003 MegaBytes/min.

    Ended : Wed Dec 17 08:20:40 2008

Open in new window

2
Author:TheCleaner
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free