Robocopy: Log names of skipped/Failed files

34,129

Solution 1

As per robocopy /? (or robocopy.exe description) and ROBOCOPY Exit Codes, use:

  • /V produce Verbose output, showing skipped files;
  • /R:0 (no retry) will speed up copying by skipping any in-use files and reduces description of any incidental particular error in log file to the only occurrence (this makes easier subsequent investigation or error cause);
  • if errorlevel 8 findstr "^[0-9,a-Z]" "D:\logs\log_%ts:~0,8%.log" explanation:
    • errorlevel greater than 7 indicates that there was at least one failure during the copy operation;
    • findstr "^[0-9,a-Z]" ... displays only logged errors, for instance
      2015/10/28 17:27:55 ERROR 32 (0x00000020) Copying File [source]\file.ext
      The process cannot access the file because it is being used by another process.
  • (cosmetic bug) /w:10 seems to be superabundant in case of /r:0.

The code:

@ECHO OFF
for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
robocopy [source] [target] /log+:D:\logs\log_%ts:~0,8%.log /e /xo /w:10 /r:0 /z /NP /V
if errorlevel 8 findstr "^[0-9,a-Z]" "D:\logs\log_%ts:~0,8%.log"

Solution 2

According to this article, you may want to try the /v option.

(...) Produces verbose output, and shows all skipped files.

Share:
34,129

Related videos on Youtube

Yash Saraiya
Author by

Yash Saraiya

Updated on September 18, 2022

Comments

  • Yash Saraiya
    Yash Saraiya over 1 year

    I am using the following batch file to run my robocopy command:

    @ECHO OFF
    for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
    robocopy [source] [target] /log+:D:\logs\log_%ts:~0,8%.log /e /xo /w:10 /r:1000 /z /NP
    robocopy [source] [target] /log+:D:\logs\log_%ts:~0,8%.log /e /xo /w:10 /r:1000 /z /NP
    

    This helped me log all the details I was looking for except that it did not logged the names of the skipped/failed files. Is there a script/robocopy command/any other way to log the names of the skipped/failed files to help me determine such files. It becomes really difficult to determine such files for a large volume of file transfer over the network.

    The closest I came to a similar question is this, but even that didn't had any accepted/working answers

    EDIT 1: As per the comment by Kamen Minkov, I included /v (verbose) in my robocopy command). When I purposefully failed the file transfer, it logged the error (retries history), but this makes the log file more and more harder to interpret. The same case was observed even without /v. I just want the failed transfer file name to be logged as failed once in my .txt log file

    EDIT 2: As per JosefZ's Answer, I ran the following code:

    @ECHO OFF
    for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
    robocopy [source] [target] /log+:D:\logs\log_%ts:~0,8%.log /e /xo /w:10 /r:0 /z /NP /V
    if errorlevel 8 findstr "^[0-9,a-Z]" "D:\logs\log_%ts:~0,8%.log"
    

    This gave me following error after transferring all the files (I unplugged the network cable to fail a few files, so there were failed files):

    FINDSTR: Cannot open D:\ABC\log\ErrorLog_20151029_1035.log

    EDIT 3: The above error occurred because I incorrectly mentioned the name of the log file for exit code. The correct code is (As answered by JosefZ):

    @ECHO OFF
    for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
    robocopy [source] [target] /log+:D:\ABC\log\log_%ts:~0,8%_%ts:~8,4%.log /e /xo /w:10 /r:2 /z /NP /V /TEE
    if errorlevel 8 findstr "^[0-9,a-Z]" "D:\ABC\log\log_%ts:~0,8%_%ts:~8,4%.log"
    
    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 over 8 years
      As I said in my answer on the question you link. A file skipped because it's the same is not a failure. Files listed in the log with no action beside them are the ones that were not copied (ie Skipped) because they are the same. Actual failures should be obvious as day. What makes you think you're actually experiencing a failure? Also keep in mind /XO is an exclusion of older files, so while they may seem to be "skipped", they won't be logged because they are not actually skipped, but instead excluded (completely) from processing - no processing = noting to log.
    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 over 8 years
      Perhaps edit your question and post an excerpt of your log file so we can see what you're experiencing, and give an example of what you expect to see that you are not.
    • JosefZ
      JosefZ over 8 years
      /r:1000 gives me no sense in log file. Use /r:0 to make easy subsequent investigation of incidental errors and their cause.
    • Yash Saraiya
      Yash Saraiya over 8 years
      I would still like to keep r:10 in case of loss of connectivity for a while... and yes r:1000 doesn't make sense.... my mistake
  • Yash Saraiya
    Yash Saraiya over 8 years
    I am testing it using /V But how do I log the failed files as well?
  • Ƭᴇcʜιᴇ007
    Ƭᴇcʜιᴇ007 over 8 years
    @YashSaraiya If you tested with /v you should include that information in your question (including results) so we're not suggesting things you've already tried.
  • Yash Saraiya
    Yash Saraiya over 8 years
    included the result using /v
  • Yash Saraiya
    Yash Saraiya over 8 years
    I tried your code and it is showing me an error "FINDSTR: Cannot open D:\HAL\log\ErrorLog_20151029_1035.log"
  • Yash Saraiya
    Yash Saraiya over 8 years
    I guess I have to name the log file exactly as what I used for displaying other details?
  • Yash Saraiya
    Yash Saraiya over 8 years
    Yep... I named my log file incorrectly for exit code. Thanks.
  • Yash Saraiya
    Yash Saraiya over 8 years
    What I observed while running your code is that the exit code is logging the errors on console and not in log file. Error's when the robocopy command is running is logged though
  • Yash Saraiya
    Yash Saraiya almost 8 years
    Could you please check this link superuser.com/questions/1104796/… and let me know if you have an answer for this ?
  • JosefZ
    JosefZ almost 8 years
    @yash sorry I'm out of order till next week.