How to Configure Robocopy to Log Only Copy Errors for Efficient File Transfer Monitoring


2 views

Robocopy (Robust File Copy) is a powerful command-line tool included in Windows that provides more reliable file copying than the basic COPY or XCOPY commands. One of its most useful features is comprehensive logging, which can be customized to meet specific monitoring needs.

By default, Robocopy logs all file operations with various levels of detail:


Robocopy C:\Source D:\Destination /E /LOG:C:\Logs\CopyLog.txt

This command logs every file operation including successes, which can create excessively large log files during large copy operations.

To focus solely on errors (failed copy operations), we can use these parameters:


Robocopy C:\Source D:\Destination /E /LOG:C:\Logs\ErrorLog.txt /NP /NS /NC /NFL /NDL

Where:

  • /NP - No progress percentage
  • /NS - No file size information
  • /NC - No file classes
  • /NFL - No file list (suppresses listing copied files)
  • /NDL - No directory list (suppresses listing scanned directories)

For even more precise error logging, combine with the /R and /W parameters to handle retry behavior:


Robocopy C:\Source D:\Destination /E /LOG+:C:\Logs\ErrorLog.txt /R:1 /W:1 /TEE /NP /NS /NC /NFL /NDL

Key additions:

  • /R:1 - Retry once on failure
  • /W:1 - Wait 1 second between retries
  • /TEE - Output to console and log file
  • /LOG+: - Append to existing log file

Here's a complete batch script for scheduled error logging:


@echo off
set SOURCE=C:\CriticalData
set DEST=D:\Backup
set LOG=C:\Logs\CopyErrors_%date:~-4,4%%date:~-10,2%%date:~-7,2%.log

Robocopy %SOURCE% %DEST% /MIR /ZB /R:3 /W:5 /LOG:%LOG% /TEE /NP /NS /NC /NFL /NDL

if %ERRORLEVEL% GEQ 8 (
    echo Severe errors occurred during copy >> %LOG%
    exit /b 1
) else (
    exit /b 0
)

A properly configured error log will only show:

  • Files that failed to copy (access denied, locked, etc.)
  • Directories that couldn't be created
  • Summary statistics showing total errors
  • Final exit code (important for automation)

When dealing with millions of files, even minimal logging can impact performance. Consider these optimizations:


Robocopy C:\Source D:\Destination /E /LOG:NUL /NJH /NJS /FP /NDL /NFL

Then redirect stderr only to capture failures:


Robocopy C:\Source D:\Destination /E 2>C:\Logs\ErrorsOnly.log

When dealing with multi-terabyte file transfers, Robocopy's default verbose logging creates unnecessary noise. What sysadmins truly need is surgical precision - logging only failed copy operations while suppressing successful transfers.

robocopy \\source\share \\destination\share /mir /np /njh /njs /ndl /nc /ns /log:errors.log /tee /r:1 /w:1 /xf *.tmp /xd Recycler /xd "$RECYCLE.BIN"

Key parameters explained:

  • /njh /njs - Suppresses job header and summary
  • /ndl /nc /ns - Omits directory names, file classes, and file sizes
  • /np - Removes progress percentage clutter
  • /r:1 /w:1 - Single retry attempt with 1-second wait

For mission-critical transfers, combine with PowerShell error trapping:

$logPath = "C:\RobocopyErrors_$(Get-Date -Format 'yyyyMMdd').log"
Start-Process robocopy -ArgumentList @(
    "\\fs01\departments",
    "\\backup01\departments",
    "/mir",
    "/njh","/njs","/ndl","/nc","/ns",
    "/tee",
    "/log+:$logPath",
    "/xf","*.lock",
    "/xd","Temporary*"
) -Wait -NoNewWindow

Extract meaningful failure patterns with:

Select-String -Path $logPath -Pattern '(FAILED|ERROR|MISSING)' | 
    Group-Object -Property {$_.Line.Substring(0,15).Trim()} | 
    Sort-Object -Property Count -Descending

For a 12TB medical imaging archive migration, this configuration reduced log files from 1.2GB to 87KB - capturing only the 19 files that failed transfer due to permission issues.