Saturday, September 8, 2018

Mr. Roboto er Robocopy

Robocopy, or "Robust File Copy", is a command-line directory and/or file replication command
From the source directory, find all shortcuts, and copy the shortcut contents to a destination directory [Wikipedia]

The most basic example
Copies files from Directory_A to Directory_B
> robocopy C:\Directory_A C:\Directory_B

Some info about Robocopy defaults:
It will only copy a file if the source and destination have different time stamps or different file sizes.
Also, data, attributes, and time stamps are copied. ACL permissions, owner information,
and auditing information are ignored. You can modify this behavior with the /copy flag.
Also note that the paths don't have a trailing backslash.

The following flurry of options will mirror files form a source directory to a destination directory, recursively, with status, summary and a log

> robocopy /b /e /xa:s /xjd /sl /a-:hs /mt /fp /mir /mt:2 /log:"C:/dev/transfer.log" /eta /tee /v /l "C:/dev/source" "D:/backup/dev/source"     

And a translation of the options:
/b      - backup mode (there's a /zb option for restart mode, but it's a whole lot slower); overwrite acls
/e      - copies subdirectories (including empty directories) in addition to files
/xa:s   - exclude system files
/xjd    - exclude junction points
/sl     - copy symbolic links as links
/a-:hs  - remove hidden/system attributes from files
/fp     - full path of files in output
/mir    - MIRror a directory tree (equivalent to /e plus /purge)
/mt[:n] - Do multi-threaded copies with n threads (default 8)
/log:transfer.log - redirect output to file
/eta    - time remaining
/tee    - duplicate log to console window
/v      - verbose output + skipped
/l      - list files only (and not copy, delete, or time stamp)

Remove the option /l when ready to run

Note that the option /sl allows symbolic links to be copied, which is useful if you are using npm for node modules management or your git repository has symbolic links.

The options /eta, /tee, /v can be removed to minimize output to the console

You can also place the command within a bat file to run on double click, or some other event.

backup.bat:

echo "R: ramdrive -> C: backup"

robocopy /b /e /xa:s /xjd /sl /a-:hs /mt /fp /mir /mt:2 /log:"C:/backup/robocopy/transfer.log" /eta /tee /v /l "R:/code" "C:/backup/code" 


pause


Microsoft documentation of Robocopy and other possible arguments

-End of document-
Thanks for reading

No comments:

Post a Comment