Table of Contents

Windows Commands Cheat Sheet

robocopy - How to use robocopy command in Windows



Sample

robocopy /?    <- help

robocopy  "P:\photo\Smartphone_Takaaki\2019"  "H:\My Drive\Photo\Smartphone_Takaaki\2019" /mir /DCOPY:DAT

# Drive Copy  (D Drive to S Drive)
robocopy D: S: /mir /DCOPY:DAT  /XD "System Volume Information" "`$RECYCLE.BIN"


robocopy   "C:\data"  "\\192.168.0.10\C$\data"   /mir  /DCOPY:DAT

robocopy   "C:\cygwin\home\user01"  "\\192.168.0.10\c$\cygwin\home\user01"   /mir /DCOPY:DAT

robocopy "C:" "S:\Backup_C" /MIR /R:0 /W:0 /LOG:"c:\work\backup.log" /NP /NDL /TEE /XJD /XJF

robocopy P: S: /mir /R:0 /W:0 /NP /NDL  /XJD /XJF

robocopy S:\Backup_Sync_P P:  /mir /R:0 /W:0



Options

/mir Mirrors a directory tree
/mir = /e /purge
/e Mirrors a directory tree (don't delete target directory files)
/l For test
Specifies that files are to be listed only (and not copied, deleted, or time stamped).
/r:<N> Specifies the number of retries on failed copies. The default value of N is 1,000,000 (one million retries)
/w:<N> Specifies the wait time between retries, in seconds. The default value of N is 30 (wait time 30 seconds).
/log:<LogFile> Writes the status output to the log file (overwrites the existing log file).

Robocopy Microspft TechNet


Tips

WARNING: from Drive to Folder

To robocpy from Drive o Folder, You must command attrib for both “hidden attribute” and “system file attribute”.

robocopy P: S:\Backup_Sync_P /mir /R:0 /W:0 /NP /NDL  /XJD /XJF
attrib -H -S "S:\Backup_Sync_P"




Sample Batch File

From Drive To Folder

@echo off
echo ----------------------------------------------------------------
echo robocopy
echo ----------------------------------------------------------------
pause

robocopy P: S:\Backup_Sync_P /mir /R:0 /W:0 /LOG:"S:\robocopy_p2s.log" /NP /NDL /TEE /XJD /XJF

rem for both hidden attribute and system file attribute
attrib -H -S "S:\Backup_Sync_P"

Example

@echo off
@echo off
echo ----------------------------------------------------------------
echo sync
echo ----------------------------------------------------------------
pause
 
 
set ipaddress=192.168.0.4
set logfile=xcopy.log
 
 
echo > %logfile%                rem initializing log file
Date /t >> %logfile%
Time /t >> %logfile%
 
 
robocopy  "C:\data\manual_soft" "\\%ipaddress%\C$\data\manual_soft"    /mir
robocopy  "C:\data\manual_hard" "\\%ipaddress%\C$\data\manual_hard"    /mir
 
 
Date /t >> %logfile%
Time /t >> %logfile%
 
 
echo -
echo -
echo -
echo ----------------------------------------------------------------
echo Backup Finished!
echo ----------------------------------------------------------------
 
pause