<

Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Mirror Windows files and folders with Robocopy

Published on
6,978 Points
3,778 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Join & Write a Comment

In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month