Robocopy Cheat Sheet: Most Useful Options and a Backup Script Example
I have already written about this small and wonderful backup tool that copies files over the network or from disk to disk.
You often need to recall what a particular switch does. Here is a short Robocopy cheat sheet with the options I use most. The full list is always available with robocopy /?.
Basic syntax
robocopy source destination [file [file]...] [options]
Copy options
/Scopies subfolders, except empty ones./Ecopies subfolders, including empty ones./LEV:ncopies only the top n levels of the source folder tree./Zcopies files in restartable mode./Bcopies files in backup mode./ZBuses restartable mode, and if access is denied, switches to backup mode./COPY:flagssets what to copy (default is/COPY:DAT): D = data, A = attributes, T = timestamps, S = security (NTFS ACLs), O = owner info, U = auditing info./DCOPY:Tcopies folder timestamps./SECcopies files with security (same as/COPY:DATS)./COPYALLcopies all file info (same as/COPY:DATSOU)./PURGEdeletes destination files and folders that no longer exist in the source./MIRmirrors a directory tree (same as/Eplus/PURGE)./MOVmoves files (deletes them from the source after copying)./MOVEmoves files and folders (deletes them from the source after copying)./MON:nmonitors the source and runs again after n changes./MOT:mmonitors the source and runs again in m minutes if there are changes./RH:hhmm-hhmmsets the run hours, the time window when new copies may start./IPG:nsets an inter-packet gap (ms) to free up bandwidth on slow links./SLcopies symbolic links themselves instead of their targets.
File selection options
/Acopies only files with the Archive attribute set./Mcopies only files with the Archive attribute and resets it./XF file...excludes files matching the given names, paths, or wildcards./XD dir...excludes folders matching the given names or paths./XC,/XN,/XOexclude changed, newer, and older files./MAX:nand/MIN:nset the maximum and minimum file size in bytes./MAXAGE:nand/MINAGE:nset the maximum and minimum file age in days./XJexcludes junction points./FFTassumes FAT file times (2-second granularity), useful when copying to NAS devices.
Retry options
/R:nis the number of retries on failed copies (the default is 1 million)./W:nis the wait time between retries (the default is 30 seconds).
Always set /R and /W in scripts, otherwise one locked file can make Robocopy wait for days.
Logging options
/Lis list only: nothing is copied, deleted, or time-stamped. Use it to preview what/MIRwill do./Vproduces verbose output, showing skipped files./TS,/FPinclude source timestamps and full path names in the output./NPturns off the progress percentage./NFLand/NDLturn off file and directory names in the log./LOG:filewrites the status to a log file (overwriting it);/LOG+:fileappends to it./UNILOG:fileand/UNILOG+:filedo the same in Unicode./TEEwrites to both the console window and the log file./NJHand/NJSturn off the job header and the job summary.
Job options
/JOB:nametakes parameters from a job file./SAVE:namesaves the current parameters to a job file./QUITquits after processing the command line (to view the parameters).
Example from a backup script
echo Start backup time: %DATE% %TIME% >> g:\BC\backup_time.txt robocopy.exe S:\ g:\BC\MK\ /MIR /R:1 /W:1 /NP /TEE /LOG:g:\BC\00_sync.log echo End backup time: %DATE% %TIME% >> g:\BC\backup_time.txt
This mirrors drive S: to g:\BC\MK\, retries a failed file once after one second, shows the output in the console, and writes a log. The script also records the start and end times in a text file.
Robocopy is included with Windows since Vista, so you don’t have to install anything on modern systems.