|
Source options
|
|
/E |
copy subfolders including empty subfolders
|
/COPYALL |
copy ALL file info (DATSOU)
|
|
Copy options
|
|
/L |
list only - don't actually copy
|
/R:n |
number of retries, default is 1 million
|
/W:n |
wait time, default is 30 seconds
|
|
Destination options
|
|
/MIR |
mirror - tend to avoid using
|
|
Logging options
|
|
/NP |
no progress displayed, i.e. no %age copied
|
/LOG:file |
overwrite log file
|
/LOG+:/file |
append to log file
|
/FP |
include full path of files in output
|
/NFL |
no file list in log
|
/NDL |
no directory list is log
|
/TEE |
output to console and log file
|
|
Advanced options
|
|
/XF file [file] |
exclude files listed
|
/XD dir [dir] |
exclude directories listed
|
/V |
verbose output, shows skipped files
|
/MT[:n] |
Multithreaded, default is 8 - don't normally use
|
robocopy *<source>* *<destination>* /COPYALL /L /E /R:1 /W:1 /FP /V /NP /TEE /LOG:C:\support\logs\robocopy-*<suffix>*.log
@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%
@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%
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.