ROBOCOPY Log File Question


  1. Posts : 386
    Windows 10 Pro (x64) 22H2 (OS Build 19045.3996)
       #1

    ROBOCOPY Log File Question


    Hi Folks,

    I have been tinkering on and off with the Robocopy command to copy essential documents and files to an SD Card automatically, several times a day (this after my wife's laptop with SSD went belly-up and she lost her most recent work).

    At the moment, there is a 'Pause' command to allow me to look at how Robocopy is behaving. All *seemed* to be well until I happened to glance at the screen one day and I saw an error flash by (which I subsequently tacked down) - this, however, isn't my issue.

    What I noticed was that when scolling back up the screen log not everything was included - only the last parts of the whole operation - and I couldn't find the infomation about the error I had spotted - so I ran the batch file again and used Fn + Pause at the appropriate time to see the error.

    The above is background to my question ...

    Reading up about Robocopy, I found the command /log: <logfile> where the status output can be directed into a text file.

    The question I have is this.

    My batch file has 25 lines in it - such as

    Set BackupDrive=M:

    Robocopy "C:\Users\Phil\Downloads" "%BackupDrive%\Downloads" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3

    Robocopy "C:\Users\Phil\Music" "%BackupDrive%\My Music" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3

    Robocopy "C:\Users\Phil\Pictures" "%BackupDrive%\My Pictures" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3

    Robocopy "C:\Users\Phil\Videos" "%BackupDrive%\My Videos" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3


    I have saved a text document (called "SD-logfile") in the location on C: drive that I have used for the backup batch file - namely: /log: C:\Users\Phil\Documents\COMPUTER STUFF\AUTO BACKUP to SD CARD

    Do I have to append "/log: C:\Users\Phil\Documents\COMPUTER STUFF\AUTO BACKUP to SD CARD\SD-Logfile"
    to each and every one of the 24 command lines (four samples of which are shown above).

    or

    Can I just issue this command once (like the Set backupDrive command) using something like Log=C:\Users\Phil\Documents\COMPUTER STUFF\AUTO BACKUP to SD CARD\SD-Logfile?

    If I can do it just the once, could someone show me what form that command should take (I'm a complete noob at witing scripts and batch files).

    Thanks in advance,

    Art

    Using this batch file on 3 different PCs - one using Win 10 and two using Win 7. Currently writing this on a Win 7 laptop.
      My Computers


  2. Posts : 1,656
    Windows 10 Pro x64
       #2

    Have a look at this which explains how to use the log command a bit more :

    ROBOCOPY - Create Backup Script - Windows 7 Help Forums
      My Computers


  3. Posts : 386
    Windows 10 Pro (x64) 22H2 (OS Build 19045.3996)
    Thread Starter
       #3

    Thanks Golden,

    Inbetween posting my original post and your reply, I've been playing and discovered that I have to add the log file location to each line in my batch file.

    This is annoying in that it means that I need a separate log text file for each command line (all 24 of them).
    [and yes, I do know in the grand scheme of things that a 24-line batch file is small potatoes, so it isn't really a deal-breaker, just cumbersome IMHO]

    What I'd like to be able to do is Pipe (is that the correct term?) the output log that appears in the command window into a single text file - so that whatever appeared in the command window log appears in the text file (I hope I've explained that such that you understand what I mean).

    Is this possible?

    Seems to be odd that without the /log switch that the Robocopy command lists what it has done (copied/skipped, etc) yet when you want to send the info to a text file via the /log switch, it does this line by line and writes the info to the text file - overwriting what was there previously - unless you specify a different text file for each line in the batch file.

    Would the use of the /v switch prevent overwriting of previous lines in the batch file?

    Hope the above makes sense.

    Art
      My Computers


  4. Posts : 16,980
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #4

    Art,

    Yes, you can use "Redirection" - see Redirection - RobVDW

    You would need to use the > symbol on the first command [to create the log then write to it] and then the >> symbol on all subsequent comamnds [to add to the existing file]

    So, for example,
    Code:
    Set BackupDrive=M:
    Set LogFile="C:\Users\Phil\Desktop\RoboCopy.log"
    Robocopy "C:\Users\Phil\Downloads" "%BackupDrive%\Downloads" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >%LogFile%
    Robocopy "C:\Users\Phil\Music" "%BackupDrive%\My Music" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >>%LogFile%
    Robocopy "C:\Users\Phil\Pictures" "%BackupDrive%\My Pictures" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >>%LogFile%
    Robocopy "C:\Users\Phil\Videos" "%BackupDrive%\My Videos" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >>%LogFile%

    RoboCopy logs are tedious but contain both the overall result sets
    ROBOCOPY Log File Question-robocopy-log-example.png
    and individual elements that can help track down problems.

    You can call the log file whatever you want. I tend to name logs using the file extension .log so I know what they are. They still open in Notepad just as they would if they were .txt files.

    Denis
      My Computer


  5. Posts : 386
    Windows 10 Pro (x64) 22H2 (OS Build 19045.3996)
    Thread Starter
       #5

    Try3 said:
    Art,

    Yes, you can use "Redirection" - see Redirection - RobVDW
    Many thanks once again Denis. I wish I had a fraction of your knowledge!

    I looked at the above webpage and it made no sense whatsoever (which is totally my fault/lack of knowledge), but thank you nonetheless!

    You would need to use the > symbol on the first command [to create the log then write to it] and then the >> symbol on all subsequent comamnds [to add to the existing file]

    So, for example,
    Code:
    Set BackupDrive=M:
    Set LogFile="C:\Users\Phil\Desktop\RoboCopy.log"
    Robocopy "C:\Users\Phil\Downloads" "%BackupDrive%\Downloads" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >%LogFile%
    Robocopy "C:\Users\Phil\Music" "%BackupDrive%\My Music" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >>%LogFile%
    Robocopy "C:\Users\Phil\Pictures" "%BackupDrive%\My Pictures" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >>%LogFile%
    Robocopy "C:\Users\Phil\Videos" "%BackupDrive%\My Videos" /S /R:3 /MT:1 /DCOPY:DAT /XA:SH /MIR /W:3 >>%LogFile%
    That example made much more sense :)

    I realise that the resulting log file may be quite long (possibly VERY long) - but I'd rather look at one log file with everything in it than having to look at over twenty different log files! After all, all that I'm interested in is to see if there are any errors and I can use Ctrl+F to find the word 'Error' in the Notepad document - whatever the length.

    RoboCopy logs are tedious but contain both the overall result sets
    ROBOCOPY Log File Question-robocopy-log-example.png
    and individual elements that can help track down problems.

    You can call the log file whatever you want. I tend to name logs using the file extension .log so I know what they are. They still open in Notepad just as they would if they were .txt files.

    Denis
    That's a good idea. Currently the 24 different logs are called "Download Log.txt", "Music Log.txt", etc but a single file called 'SD-Backup.log" would make far more sense.

    It would be easy to search for too when Dr Altzheimer forgets what the log file is called and where he put it!

    Once again, many thanks Denis.

    Kind regards and stay safe,

    Art
      My Computers


  6. Posts : 1,656
    Windows 10 Pro x64
       #6

    ArthurDent said:
    Is this possible?
    Art
    Yes....use the /log+ command:

    Code:
    robocopy E:\Data1 G:\Backups\Data1 /e /mir /np /log:backup_log.txt
    robocopy F:\Data2 G:\Backups\Data2 /e /mir /np /log+:backup_log.txt
    robocopy F:\Data3 Q:\Backups\Data3 /e /mir /np /log+:backup_log.txt

    The first /log initialises the backup_log.txt, subsequent /log+ commands simply append to backup_log.txt. That way, everything is written to one single log file.
      My Computers


  7. Posts : 16,980
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #7

    And there is one difference between the log files made -
    The log+ method records data transfer speed in the log file.
    The Redirection method [>] does not.

    Denis
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:53.
Find Us




Windows 10 Forums