Robocopy syntax doesn't work in my batch file anymore

Page 1 of 4 123 ... LastLast

  1. Posts : 947
    windows 10 professional 64-bit, 22H2
       #1

    Robocopy syntax doesn't work in my batch file anymore


    I created the following text file & then changed the extension to .bat. The syntax is:
    Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /Z /W:5 /TS /MOT:180 /R:10

    I also created a shortcut for it on my desktop.

    If I paste this into Powershell or Powershell (run as administrator), it works fine. When I first created it, I could double click it & it would run fine. In order to get the batch file to work now, I have to right click it & choose "Run as administrator". Can anyone explain what's happening?

    I should add that I left off an additional option: /RH: 0130-0140 that allows it to run only between 0130 & 0140 AM. However, it hasn't run for 2 days. It used to be that I would simply edit the batch file by pressing enter after /R:10 so that the whole thing read:

    Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /Z /W:5 /TS /MOT:180 /R:10
    /RH: 0130-0140

    This would allow me to run it manually. Then I could delete the "return" & have it run only 130-140. In any event, I don't know why it doesn't work any more. Any help would be appreciated!

    I may have found the answer, but I'd appreciate some knowledgeable advice. I changed the name of the batch file from Copy.bat to Robocopy.bat. Apparently, Windows doesn't like that. When I changed it to any other name, it worked. Can someone please explain that?

    Thank you in advance!
      My Computers


  2. Posts : 30,187
    Windows 11 Pro x64 Version 23H2
       #2

    Hi phrab.

    This post will likely help.

    bat job started by Task Scheduler does not pause


    Ken
      My Computer


  3. Posts : 8,105
    windows 10
       #3

    A bat file is old MS-DOS command file you should have a .cmd extension for Windows file
      My Computer


  4. Posts : 31,644
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #4

    Samuria said:
    A bat file is old MS-DOS command file you should have a .cmd extension for Windows file
    You can use .bat or .cmd interchangeably in Windows NT or above and CMD.EXE will treat them identically, with one important distinction.
    Mark Zbikowski (MSFT) said:
    The differences between .CMD and .BAT as far as CMD.EXE is concerned are:
    With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC in .CMD
    files will set ERRORLEVEL regardless of error. .BAT sets ERRORLEVEL
    only on errors.
    https://groups.google.com/forum/#!ms...k/LIEViGNmkK0J
      My Computers


  5. Posts : 947
    windows 10 professional 64-bit, 22H2
    Thread Starter
       #5

    Caledon Ken said:
    Hi phrab.
    This post will likely help.
    bat job started by Task Scheduler does not pauseKen
    Thank you so much for your reply, Ken. I have some additional questions please. I got my batch file to work manually by changing the name of it...it's now "ThunderbirdCopy.bat".

    I am not well versed in batch files, so I thought (apparently incorrectly) that the /MOT:180 /R:10 would make it monitor & start automatically.

    After going to the thread you posted above, I guess I have 2 choices:
    1) I can manually start it & then leave it running, so that at 1:30AM it will monitor the source to see if there's changes & then copy. This seems to be a stupid choice, as it would be running constantly & never stop.
    2) I could use Task Scheduler to run it starting at 1:30AM, which is what I've done.
    Question 1: Is this the correct way to do this?
    Question 2: The thread above mentioned using cmd /c for elevated Powershell.
    A. What is an elevated Powershell?
    B. Is there an advantage to using Powershell over just the command line.
    Question 3: Would the syntax for the elevated Powershell then be:
    cmd /c ""Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /Z /W:5 /TS /MOT:180 /R:10""
    i.e. I'm not sure how to invoke Powershell automatically.
    C. In any event, if I use Task Scheduler to start the batch file at 1:30AM, is there an option to stop it after it's run?

    Sorry for all these questions, but I really appreciate your help!
      My Computers


  6. Posts : 30,187
    Windows 11 Pro x64 Version 23H2
       #6

    Yes I would use Task manager to start this file.

    Elevated in simple terms you are giving it additional permissions.

    https://www.computerhope.com/jargon/e/elevated.htm

    As I understand it you would just use the file as you use it today. When you run it through Task Manager it will invoke Powershell.

    Yes I believe the syntax is right. You added the extra quotes surrounding the entire line as you had quotes within your command. I did not look at your robocopy parameters.
      My Computer


  7. Posts : 5,478
    2004
       #7

    I think you are making your robocopy parameters far too complicated.

    I don't see the point in scheduling the job to run at 01:30 for 3 hours to look for changes. What will happen? Surely you scheduled it at a time when nothing was happening. Why not just run it to do the backup of changed files and then stop (that is what I do).

    With regards to the robocopy switches:
    You specify /Z to copy files in restartable mode. Why? You would only use this for massive files over dodgy connections. Drop it.
    You have the /TS to log timestamps but you don't specify a log file. The switch is therefore pointless.
    You have reduced the wait time on error from the default 30 seconds to 5. And retries to 10. This means if it can't find your backup it will try again for 50 seconds. I'd set both to zero - it is a local drive and you either connected it or forgot to.

    Then you are monitoring to see if any changes have happened in the 180 minutes after you submit the job. This means if you submit the job for 01:30 it will see if any changes occur before 03:30. This may be what you want but I doubt it.

    You also are not copying all security flags - the default is /COPY:DAT - I'd change that to /COPYALL (to include (S=Security=NTFS ACLs, O=Owner info, U=aUditing info)

    Therefore I'd change this:
    Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /Z /W:5 /TS /MOT:180 /R:10 to:
    Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /COPYALL /R:0 /W:0

    There is no advantage running robocopy by powershell than cmd incidentally - the result is exactly the same. However splitting out the parameters into arrays and forcing quote marks around paths is a bore in powershell.

    I do use powershell for this though: this is my robocopy script (triggered via task scheduler when I put my laptop in the dock) to give you an idea.
    PHP Code:
    $backupDrive='E'
    $backupLocation=$backupDrive+':\X201 Backup'

    $backupDirectories = @(    
    ,(
    'D:\Music','*.*')
    ,(
    'C:\Users\Hali\Documents\Calibre Library','*.*')
    ,(
    'C:\Users\Hali\OneDrive','*.*')
    )

    # Check if dock connected
    if (Test-Path $backupLocation) {
        For(
    $i=0;$i -lt $backupDirectories.Count$i++) {
            
    $source=$backupDirectories[$i][0]
            
    $files=$backupDirectories[$i][1]
                        
            if(
    Test-Path $source) {
                
    $sourceDrive=(get-item $source).PSDrive.Name
                $unqualifiedPath
    =split-path -noqualifier $source
                $destination
    ="$backupLocation\$sourceDrive$unqualifiedPath"
                
                
    $logfile="""$backupLocation\Backup Logs\Backup $(get-date -f yyyy-MM-dd' 'HH-mm-ss-fffff) $(split-path -leaf $source).log"""
                
                
    # Robocopy options
                
    $copyOptions = @('/B','/COPYALL','/MIR')
                
    $selectionOptions = @()
                
    $retryOptions = @('/R:0','/W:0')
                
    $loggingOptions = @('/NFL','/NDL',"/LOG:$logfile",'/TEE')
                
    $jobOptions = @()
                
                
    $CmdLine = @('"{0}"' -f $source) +@('"{0}"' -f $destination) +@($files) +$copyOptions +$selectionOptions +$retryOptions +$loggingOptions +$jobOptions
                
    'robocopy.exe' $CmdLine
            
    }            
        }            

    You should also note that if you use the /MT switch with /LOG you will get hundreds or thousands of pages saying "100%100%100%100%" etc in your logfile.

    According to TechNet (in 2009): Robocopys /MT option disables /NP option it will be fixed soon but that was nearly a decade ago.
    Last edited by lx07; 24 Mar 2018 at 10:49. Reason: logfile issues
      My Computer


  8. Posts : 947
    windows 10 professional 64-bit, 22H2
    Thread Starter
       #8

    Caledon Ken said:
    Yes I would use Task manager to start this file.

    Elevated in simple terms you are giving it additional permissions.

    https://www.computerhope.com/jargon/e/elevated.htm

    As I understand it you would just use the file as you use it today. When you run it through Task Manager it will invoke Powershell.

    Yes I believe the syntax is right. You added the extra quotes surrounding the entire line as you had quotes within your command. I did not look at your robocopy parameters.
    Thank you so much Ken for answering my questions. You've been a great help!
      My Computers


  9. Posts : 947
    windows 10 professional 64-bit, 22H2
    Thread Starter
       #9

    lx07 said:
    I think you are making your robocopy parameters far too complicated.

    I don't see the point in scheduling the job to run at 01:30 for 3 hours to look for changes. What will happen? Surely you scheduled it at a time when nothing was happening. Why not just run it to do the backup of changed files and then stop (that is what I do).

    With regards to the robocopy switches:
    You specify /Z to copy files in restartable mode. Why? You would only use this for massive files over dodgy connections. Drop it.
    You have the /TS to log timestamps but you don't specify a log file. The switch is therefore pointless.
    You have reduced the wait time on error from the default 30 seconds to 5. And retries to 10. This means if it can't find your backup it will try again for 50 seconds. I'd set both to zero - it is a local drive and you either connected it or forgot to.

    Then you are monitoring to see if any changes have happened in the 180 minutes after you submit the job. This means if you submit the job for 01:30 it will see if any changes occur before 03:30. This may be what you want but I doubt it.

    You also are not copying all security flags - the default is /COPY:DAT - I'd change that to /COPYALL (to include (S=Security=NTFS ACLs, O=Owner info, U=aUditing info)

    Therefore I'd change this:
    Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /Z /W:5 /TS /MOT:180 /R:10 to:
    Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /COPYALL /R:0 /W:0

    There is no advantage running robocopy by powershell than cmd incidentally - the result is exactly the same. However splitting out the parameters into arrays and forcing quote marks around paths is a bore in powershell.
    Thank you very very much!! This is fantastic! I've learned a lot in such a short time.
      My Computers


  10. Posts : 947
    windows 10 professional 64-bit, 22H2
    Thread Starter
       #10

    lx07 said:
    I think you are making your robocopy parameters far too complicated.

    I don't see the point in scheduling the job to run at 01:30 for 3 hours to look for changes. What will happen? Surely you scheduled it at a time when nothing was happening. Why not just run it to do the backup of changed files and then stop (that is what I do).

    With regards to the robocopy switches:
    You specify /Z to copy files in restartable mode. Why? You would only use this for massive files over dodgy connections. Drop it.
    You have the /TS to log timestamps but you don't specify a log file. The switch is therefore pointless.
    You have reduced the wait time on error from the default 30 seconds to 5. And retries to 10. This means if it can't find your backup it will try again for 50 seconds. I'd set both to zero - it is a local drive and you either connected it or forgot to.

    Then you are monitoring to see if any changes have happened in the 180 minutes after you submit the job. This means if you submit the job for 01:30 it will see if any changes occur before 03:30. This may be what you want but I doubt it.

    You also are not copying all security flags - the default is /COPY:DAT - I'd change that to /COPYALL (to include (S=Security=NTFS ACLs, O=Owner info, U=aUditing info)

    Therefore I'd change this:
    Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /Z /W:5 /TS /MOT:180 /R:10 to:
    [c]Robocopy "C:\Users\Phil\AppData\Roaming\Thunderbird\Profiles\MyProfile" "E:\Backups\Thunderbird\Profiles\MyProfile" /MIR /COPYALL /R:0 /W:0...
    Thought I had this, but my batch file isn't working properly. When I use the /COPYALL switch, it doesn't work. If I use:
    /MIR /COPYALL /R:0 /W:0
    -OR-
    /MIR /COPYALL /R:0 /W:0 /MT:25
    it just flashes, but doesn't copy anything.

    If I use:
    /MIR /R:0 /W:0
    -OR-
    /MIR /R:0 /W:0 /MT:25
    it works.

    Can you figure out what I'm doing wrong? Thank you again for your time & patience!

    Additional: I ran the command from a command prompt & got this message:
    ERROR : You do not have the Manage Auditing user right.
    ***** You need this to copy auditing information (/COPY:U or /COPYALL).

    Since this is my own computer & my user profile has administrator rights, how can I add the "Manage Auditing user right"? Thank you again!

    Additional: Sorry for panicking. The syntax works on my WinXP machine & I found the tutorial on adding user rights, so it appears to work now in Windows 10. It will run at 1:15AM tomorrow morning. I'll post back if it doesn't work. Sorry for all the additional questions that I should have researched before posting. Many thanks!
    Last edited by phrab; 26 Mar 2018 at 12:16.
      My Computers


 

  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 04:26.
Find Us




Windows 10 Forums