Windows 10: Robocopy syntax doesn't work in my batch file anymore Solved

Page 1 of 4 123 ... LastLast

  1. Posts : 104
    windows 10 professional 64-bit
       22 Mar 2018 #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 ComputerSystem Spec


  2. Posts : 8,168
    Windows 10 Pro x64 Build 1803
       23 Mar 2018 #2

    Hi phrab.

    This post will likely help.

    bat job started by Task Scheduler does not pause


    Ken
      My ComputerSystem Spec

  3.    23 Mar 2018 #3

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


  4. Posts : 7,625
    10 Home x64 (1803) (10 Pro on 2nd pc)
       23 Mar 2018 #4

    Samuria said: View Post
    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 ComputersSystem Spec


  5. Posts : 104
    windows 10 professional 64-bit
    Thread Starter
       23 Mar 2018 #5

    Caledon Ken said: View Post
    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 ComputerSystem Spec


  6. Posts : 8,168
    Windows 10 Pro x64 Build 1803
       24 Mar 2018 #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 ComputerSystem Spec

  7.    24 Mar 2018 #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 ComputerSystem Spec


  8. Posts : 104
    windows 10 professional 64-bit
    Thread Starter
       24 Mar 2018 #8

    Caledon Ken said: View Post
    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 ComputerSystem Spec


  9. Posts : 104
    windows 10 professional 64-bit
    Thread Starter
       24 Mar 2018 #9

    lx07 said: View Post
    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 ComputerSystem Spec


  10. Posts : 104
    windows 10 professional 64-bit
    Thread Starter
       26 Mar 2018 #10

    lx07 said: View Post
    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 ComputerSystem Spec


 
Page 1 of 4 123 ... LastLast

Related Threads
Hello, Happy new year. I have a couple PC's in my house running Windows 10 64bit. All these PC's run Windows from a SSD and have a 2nd HD installed. To save space on the SSD's I put the paging file for the virtual ram on the 2nd HD. So now,...
Solved Win+X doesn't work anymore in General Support
pressing Win+X doesn't show the power user menu for me anymore. right clicking Start button doesn't work either, but when I do it, the mouse cursor jumps several pixels up and to the right. I did sfc /scannow and it didn't fix the issue. does...
Scroll wheel doesn't work anymore in Drivers and Hardware
Hi, i've been searching this issue on Google with literal no topic about it so i'll just make the first one here: From a time i have an A4Tech V7 Gaming mouse that works perfect in Windows 7. Since a few weeks ago, after Microsoft deployed a...
I'm used to run files by drag'n'dropping them on top of one of the icons in quicklaunch. When I need to launch file with some app, while file is associated with another, or just use the other version of app. E.g. drag and drop png file on Paint icon...
I want to run Robocopy to copy my Money 2005 file every shutdown, I know Money has a backup facility but when my wife runs Money on her laptop (Using Homegroup) there is always a backup conflict with my PC and if I open Money and try to backup I get...
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 00:18.
Find Us