Options Summary
Source options |
|
copy subfolders including empty subfolders |
|
copy ALL file info (DATSOU) |
Copy options |
|
list only - don't actually copy |
|
number of retries, default is 1 million |
|
wait time, default is 30 seconds |
Destination options |
|
mirror - tend to avoid using |
Logging options |
|
no progress displayed, i.e. no %age copied |
|
overwrite log file |
|
append to log file |
|
include full path of files in output |
|
no file list in log |
|
no directory list is log |
|
output to console and log file |
Advanced options |
|
exclude files listed |
|
exclude directories listed |
|
verbose output, shows skipped files |
|
Multithreaded, default is 8 - don't normally use |
Requirements and Recommendations
The scripts, options, filenames are merely personal choices.
Source and Destination folders can be either local filesystem references (e.g.D:\path\to\directory) or UNC path (e.g. \\Server\share\path\to\directory).
Log file suffix either Date stamp, Date and Time stamp or Job Id.
The log file path (e.g. C:\support\logs\) should exist. Robocopy makes a log file if it doesn't exist but does not create a log directory.
Should always use the log only (/L) option until ready to perform the copy at which point remove /L from the command options. |
Base Command
robocopy <source> <destination> /COPYALL /L /E /R:1 /W:1 /FP /V /NP /TEE /LOG:C:\support\logs\robocopy-<suffix>.log
|
Simple Batch Version
@echo off
SET SDIR=<type or paste Absolute directory path or Full UNC path>
SET DDIR=<type or paste Absolute directory path or Full UNC path>
:: File suffix either datestamp, datetimestamp or job id - uncomment as required
SET FILESUFFIX=%date:10,4%%date:7,2%%date:~4,2%
::SET FILESUFFIX=%date:10,4%%date:7,2%%date:4,2%-%time:0,2%%time:3,2%%time:6,2%
::SET FILESUFFIX=jobid
SET LOGFILE=C:\support\logs\robocopy-%FILESUFFIX%.log
:: Common parameters: /L,/V,/B,/MIR, /MT:# - add/remove as required
:: Remove /L to perform copy
SET MAIN_OPTIONS=/COPYALL /L /E /R:1 /W:1 /FP /V /NP
SET FILE_OPTIONS=/XD "RECYCLER" "System Volume Information" /
:: Default is to append to log file "+"
:: /TEE is not require if running as scheduled task
SET LOG_OPTIONS=/TEE /LOG+:"%LOGFILE%"
robocopy.exe "%SDIR%" "%DDIR%" %MAIN_OPTIONS% %FILE_OPTIONS% %LOG_OPTIONS%
|
Expanded Batch Version
@echo off
:: After completing job, uncomment the following 2 lines so the script cannot be run accidentally
:: echo Script has been actioned, remove/comment 'exit command' if you really want to run
:: exit /b
:: Data migration - <JOBID>
:: Source
:: * S:\Source\path\to\directory
:: * \\SOURCESERVER>\Users$\username
:: * \\SOURCESERVER>\share\path\to\location
:: Destination
:: * D:\Destination\path\to\directory
:: * \\DESTINATIONSERVER\Users$\username
:: * \\DESTINATIONSERVER\share\path\to\location
SET JOB=JOBID
:: change from "listonly" to run robocopy command
SET TYPE=listonly
::SET TYPE=run
:: Either host could be %computername% for more flexibility
SET SHOST=SERVERNAME
SET DHOST=SERVERNAME
:: SET ISOFORMAT=time || SET ISOFORMAT=date
SET ISOFORMAT=date
if %ISOFORMAT%==date (
SET FILESTAMP=%date:10,4%%date:7,2%%date:~4,2%
else (
SET FILESTAMP=%date:10,4%%date:7,2%%date:4,2%-%time:0,2%%time:3,2%%time:6,2%
)
:: If migrating user home folder set USER and then generate directories.
:: Otherwise can simply use static UNC or absolute paths
SET USER=FirstName.LastName
SET SDIR=\\%SHOST%\Users$\%USER%\<SRC FOLDER>
SET DDIR=\\%DHOST%\Users$\%USER%\<DST FOLDER>
:: Change drive letter as required
::SET SDIR=\\%SHOST%\d$\<SRC FOLDER>
::SET DDIR=\\%DHOST%\d$\<DST FOLDER>
:: Note: /L is used for testing, and log filename will be appended with "-test"
:: LOGDIR must exist, change as appropriate
SET LOGDIR=C:\support\logs
if %TYPE%==listonly (
SET LOGFILE=%JOB%-%FILESTAMP%-test.log
SET LOGONLY=/L
) ELSE (
SET LOGFILE=%JOB%-%FILESTAMP%.log
SET LOGONLY=
)
:: Robocopy options - for a single folder
:: Common parameters: /L,/V,/B,/MIR, /MT:# - add/remove as required
SET MAIN_OPTIONS=/COPYALL %LOGONLY% /E /R:1 /W:1 /FP /V /NP
SET FILE_OPTIONS=/XD "RECYCLER" "System Volume Information" /XF ~.* thumbs.db desktop.ini
:: Default is to append to log file "+"
:: /TEE is not require if running as scheduled task
SET LOG_OPTIONS=/TEE /LOG+:"%LOGDIR%\%LOGFILE%"
robocopy.exe "%SDIR%" "%DDIR%" %MAIN_OPTIONS% %FILE_OPTIONS% %LOG_OPTIONS%
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by PeterCeeAU