4

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"
4
  • 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. Commented Oct 28, 2015 at 13:34
  • 1
    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. Commented Oct 28, 2015 at 13:38
  • 1
    /r:1000 gives me no sense in log file. Use /r:0 to make easy subsequent investigation of incidental errors and their cause.
    – JosefZ
    Commented Oct 28, 2015 at 16:20
  • 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 Commented Oct 29, 2015 at 4:43

2 Answers 2

4

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"
6
  • I tried your code and it is showing me an error "FINDSTR: Cannot open D:\HAL\log\ErrorLog_20151029_1035.log" Commented Oct 29, 2015 at 5:20
  • I guess I have to name the log file exactly as what I used for displaying other details? Commented Oct 29, 2015 at 5:51
  • Yep... I named my log file incorrectly for exit code. Thanks. Commented Oct 29, 2015 at 5:56
  • 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 Commented Oct 29, 2015 at 6:08
  • Could you please check this link superuser.com/questions/1104796/… and let me know if you have an answer for this ? Commented Jul 25, 2016 at 10:05
1

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

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

3
  • I am testing it using /V But how do I log the failed files as well? Commented Oct 28, 2015 at 12:22
  • 2
    @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. Commented Oct 28, 2015 at 13:32
  • included the result using /v Commented Oct 28, 2015 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .