Mirror a content source folder with robocopy, logging and retries
A robocopy command that mirrors a content source folder to a share, with a test run, a log file and limited retries.
LanguageBatch
What it does to the systemMakes changes. Test it on one computer first.
This copies a content source folder to a new server or share and keeps the copy the same as the original. Use it when you move your SCCM source files.
Run the test command first. It lists what robocopy plans to do and changes nothing.
Batch
rem 1. TEST RUN. /L lists the planned changes and copies or deletes nothing.
robocopy "D:\Sources\Apps" "\\server02\Sources$\Apps" /MIR /R:3 /W:10 /NP /L /LOG:"C:\Logs\robocopy-apps-test.log" /TEE
rem 2. REAL RUN. Same command without /L.
robocopy "D:\Sources\Apps" "\\server02\Sources$\Apps" /MIR /COPY:DAT /DCOPY:DAT /R:3 /W:10 /MT:8 /NP /LOG+:"C:\Logs\robocopy-apps.log" /TEE
rem What the switches do:
rem /MIR copy all subfolders and DELETE files in the target that are not in the source
rem /COPY:DAT copy file data, attributes and time stamps
rem /DCOPY:DAT copy folder attributes and time stamps
rem /R:3 /W:10 retry a failed file 3 times and wait 10 seconds between tries
rem /MT:8 copy 8 files at the same time
rem /NP leave the percent progress out of the log
rem /LOG+: add to the log file (/LOG: starts a new log file)
rem /TEE show the output on screen and write it to the log
How to use it
- Change the first path to your source folder and the second path to your target folder.
- Create the log folder
C:\Logs. Robocopy does not create it. - Run the test command. Open the test log and read every line marked
*EXTRA File. Those files get deleted in the real run. - Run the real command when the test log looks right.
- Check the summary table at the end of the log. The Failed column must be 0.
Good to know
- Warning:
/MIRdeletes every file and folder in the target that is not in the source. If you swap the two paths, or point at the wrong target, you lose data. - Always set
/Rand/W. The default is one million retries with a 30 second wait, so one locked file can stall the job. - A robocopy exit code below 8 means the copy worked. 8 or higher means at least one file failed.
robocopy
mirror
content source
file copy
logging
More Command line
Install the SCCM client with ccmsetup.exe and the most used switches
Open the SCCM client control panel and Software Center from the command line
Repair the WMI repository the careful way
Reset Windows Update components
Run DISM and SFC health repair in the right order
Run msiexec for a silent install, a silent uninstall and a verbose log