Friday, March 15, 2013

Flowing Fix: How to quickly mirror your data to a second hard drive

Robust File Copy (or Robocopy)  is a command-line command to replicate directories. It is a standard feature in Windows since Windows Vista and Windows Server 2008.

To help us use  the "robocopy" command more readily we create simple batch files

1) In Windows, open Notepad and enter the following information into the new text file:


set log=C:\tmp\LogName.log
set opts=/NP /XJ /R:0 /COPY:DAT /E /LOG+:%log% /TEE
del /F /Q %log%
robocopy "C:\yourSourceFolder" "F:\yourDestinationFolder" %opts%


Note: "C:\yourSourceFolder"  and "F:\yourDestinationFolder" should be replaced with your source and destination folders. 

2) Then, save this text file and change the extension to ".bat" to create a DOS batch file.

3) To run, just double click on the .bat file

About the batch file you just created:
First line: defines the name and location to store the log file.
Second line: sets the options required to mirror the data 
     /NP -  turns off the progress of copying of the copying operation
     /XJ  -  excludes junction points (important for user folders on Windows 7, etc.)
     /R:0  -  sets the retries for failed copies to zero
     /COPY:DAT  -  Specifies the file properties to be copied, DAT is Data, Attributes, and Time stamps
     /E  -  Copies subdirectories (including empty directories)
     /LOG+:  -  Writes the status output to the log file (appends the output to the existing log file)
     /TEE  -  Writes the status output to the console window, as well as to the log file.
Third line: deletes the log file before running.
Fourth line: executes "robocopy" to copy the data from "C:\yourSourceFolder" to "F:\yourDestinationFolder" using the options provide on line two of the batch file.

For more information about robocopy and list of options refer to http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx