Robocopy is a robust file copying program built into Windows similar to UNIX rsync. It is a much better method of copying large datasets or lots of files across volumes, and is a great tool for backing up data. It has the ability to resume copies if inturrupted, various options and logging during copying.

Full Microsoft robocopy documentation can be found here: https://technet.microsoft.com/en-us/library/cc733145.aspx

COE IT has created a script (below) that can be modified and used to your specificatations to aid graduate students who wish to have an easy way to back up files from local computer storage to external disks, or to our backup server "attic". 

-----------------------------
@ECHO OFF
SETLOCAL SET _source=C:\temp
SET _dest=E:\backup
SET _what=/COPYALL /B /E
:: /COPYALL :: COPY ALL file info
:: /E :: copy all subdirs, even empty ones
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /XD <Directory>[...] :: excludes directories that match the specified names and paths
:: /XF <FileName>[...] :: excludes files that match the specified names or paths. Note that FileName can include wildcard characters (* and ?)
SET _options=/LOG:C:\temp\robocopy-example-log.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging 
ROBOCOPY %_source% %_dest% %_what% %_options%
-----------------------------end-------------------------

Each SET line applies options to a variable. The values of each of those variables is applied to the robocopy command in the last line of the script, to run the program with the options specified.

@ECHO OFF
SETLOCAL

Above are the first two lines of the script. Don't modify them, they are needed for the script to run properly.

SET _source=C:\temp

This is where you set the source directory that you want robocopy to copy from.

SET _dest=E:\backup

This is where you set the destination directory that you want robocopy to copy files/folders to. You can also specify a UNC path such as: \\server\folder

SET _what=/COPYALL /B /E

This is where you set switches on want robocopy to copy, how to deal with security settings and how to deal with specific files. Common switches are:

/COPYALL Copy all file information
/E Copy all subdirectories, even empty ones
/B Copy files in Backup mode
/SEC Copy files with SECurity
/XD <Directory>[...] Excludes directories that match the specified names and paths
/XF <FileName>[...] Excludes files that match the specified names or paths

Note that FileName can include wildcard characters (* and ?)

Additional Examples:

a) SET _what=/COPYALL /B /E /XD $RECYCLE.BIN /XD "System Volume Information" /XF Thumbs.db /XF pagefile.sys

/XD $RECYCLE.BIN Excludes the directory $RECYCLE.BIN (this is where Windows puts recycled files)
/XD "System Volume Information" Excludes the direcotry "System Volume Information"
/XF Thumbs.db Excludes files named Thumbs.db
/XF pagefile.sys Excludes files named pagefiles.sys

b) SET _options=/LOG:C:\temp\robocopy-example-log.txt /NFL /NDL

This is where you specify the log file that robocopy will create and what you want robocopy to log. The log file (robocopy-example-log.txt in this example) will be created in the same directory that the script is stored. The folder path specified must already exist or your will get an error. Also avoid spaces in the path name. Depending on how verbose you specify in the log options and how much you are copying, this file can get very large. Common switches include:

/R:n Number of Retries
/W:n Wait time between retries
/LOG Output log file
/NFL No file logging
/NDL No dir logging

c) ROBOCOPY %_source% %_dest% %_what% %_options%

This line will call robocopy with the options you specified in the SET lines.

Create a Scheduled Task

  1. Search for and open "Computer Management"
  2. Expand "Task Scheduler"
  3. Right click inside the tasks list and choose "Create New Task"

General Tab
Give your task a name and description on what it does, for the Security options, make sure that your user account is set to run the task, and that the radio button for "Run only when user is logged on" is selected



Triggers Tab
Create a new trigger
Select when you want the task to begin, "On a schedule" is a good option to start
Change the Settings to how often you want to run the task and when (date and time) you want it to start and reoccur
Advanced settings allow some additional options
Click OK when finished to create the task

Actions Tab
Create a new action
Action: Choose "Start a program"
Settings: Program/script: "C:\temp\robocopy-example.bat"
This is telling Windows to run "C:\temp\robocopy-example.bat" in Windows command prompt. Change the path and filename inside the quotes to match where your script is located and what it is named. It is recommended to keep the path/filename short and avoid spaces.

Conditions Tab
Additional options should you choose to use them. Defaults generally are fine for most tasks.


Settings Tab
Additional options should you choose to use them. Defaults generally are fine for most tasks.