robocopy30 Apr 2015 • Leave Comments
Robust File Copy for Windows command
robocopy can mirror or incrementally backup files/directories, with versitle parameters.
The basic usage of
robocopy is like:
robocopy <source-dir> <dest-dir> [file [file] ...] [options] # robocopy d:\work e:\back *.txt *.doc *.bmp *.tif /s
Attention please: Windows does not differentiate letter case. Hence,
/Shave the same effect.
By default, file/directory to copy can be wildcards like
* (default to
*.*; omitted usually). Read Robocopy 指令範例參考 (MIR問題很多，小心使用) or check
robocopy will copy any name where the Timestamp or file size differs:
- Timestamp refers to any of Creation Date, Last Modified Date or Last Access Date.
- It does not care about whether the source or the dest is newer.
- It does not count on any hash functions.
- In order to avoid unnecessary copy, we should tune arguments accordingly.
The following is an example that mirrors a disk parittion:
# /MIR = /E /PURGE F:\>robocopy D:\ E:\ /MIR /XO F:\>robocopy D:\ E:\ /MIR /XO /COPY:DAT /DCOPY:DAT [/MINAGE:1] /MAXLAD:7 /XA:SH /XD "System Volume Information" "$RECYCLE.BIN" /R:3 /W:10 /MT:16 /UNILOG+:F:\robocopy.log /TEE /Z
/MIRmirrors a directory tree, equivalent to
/XOskips older files from the source.
/COPY:DATScopies Data, Attributes, Timestamp and NTFS Security ACLs fo files.
By default, Security info of NTFS is not copied. However, the system may deny this for security considerations.
/DCOPY:DATcopies Data, Atrributes and Timestamp of directories.
By default, Timestamp is not copied.
/MAXAGE:nexclude files according to their Last Modified Date.
MINAGE:1guarantees that files being updated today won't copied. On the contrary, MAXAGE skip files old enough.
ncan be the number of days or date in
YYYYMMDDformat. It should adapt to the bakcup cron job.
/MAXLAD:nexclude files according to their Last Access Date.
/XA:SHexcludes files with Hidden or System attributes.
In return, we have
/IA:to copy only files with the specified attributes.
/XD <dir>excludes specific directories.
In return, we have
/XFto exclude specific files.
/R:3retries 3 times on failed copies. By default, it is 1 million.
/W:10wait for 10 seconds between retries.
/MT:16creats 16 concurrent threads to copy files.
/UNILOG+:F:\robocopy.logredirects log to file with UNICODE encoding.
/Zruns in restartable mode such that we can resume the transfer in case it is interrupted.
The Linux alternative of
rsync. Please check fmt.pdf.