Robocopy syntax to copy all NEW or EDITED files from source to destination dir:

robocopy "%src%" "%dest%" /E /W:1 /R:1 /XC /log+:"robocopy_log.txt"

Description of the parameters:

  • /E = Copies subdirectories. Note that this option includes empty directories. If you wish to exclude empty directories, use /S.
  • /W:1 = Specifies the wait time between retries, in seconds. The default value of N is 30 (wait time 30 seconds).
  • /R:1 = Specifies the number of retries on failed copies. The default value of N is 1,000,000 (one million retries).
  • /XC = Excludes changed files.
  • /log+: = Writes the status output to the log file (appends the output to the existing log file).

Windows batch script to setup a scheduled task to run the robocopy command:

@echo off
title Robocopy Backup
echo.
echo Initial configuration for automatic backup with Robocopy + Task Scheduler
echo.

echo Step 1 - setup Robocopy:
echo.
set /p src=Backup FROM dir: 
set /p dest=Backup TO dir: 
(
echo cd %userprofile%\Desktop
echo robocopy "%src%" "%dest%" /E /W:1 /R:1 /XC /log+:"robocopy_log.txt"
)> %userprofile%\robocopy.bat

echo.
echo Step 2 - setup Task Scheduler:
echo.
schtasks /create /tn "Robocopy Backup" /tr "%userprofile%\robocopy.bat" /SC HOURLY
echo.
echo Done
echo.

pause

Copy & paste the text into a text editor and save it as a .bat file to make it executable.

When running this script you will setup a scheduled task which runs the robocopy.bat file every hour. Really great and time-saving if you work in a local folder on your C drive and wish to periodically take incremental backups to a network storage for instance.


Next Post Previous Post