<

Go Premium for a chance to win a PS4. Enter to Win

x

Mirror Windows files and folders with Robocopy

Published on
7,028 Points
3,828 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
Comment
Author:TheCleaner
1 Comment
 
LVL 8

Expert Comment

by:Senior IT System Engineer
Thanks for posting man, so how to make the Robocopy skip the files and folder that already exist or created in the destination folder ?

So when I execute the same script the Robocopy app just copy the differences only ? or the deltas.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Join & Write a Comment

Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month