Command line

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

  1. Change the first path to your source folder and the second path to your target folder.
  2. Create the log folder C:\Logs. Robocopy does not create it.
  3. Run the test command. Open the test log and read every line marked *EXTRA File. Those files get deleted in the real run.
  4. Run the real command when the test log looks right.
  5. Check the summary table at the end of the log. The Failed column must be 0.

Good to know

  • Warning: /MIR deletes 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 /R and /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
✉

Get new articles in your inbox

SCCM guides, AI tools, automation tips — sent when published. No spam.