none
Scheduling Robocopy to run at System Startup

    Question

  • I create a batch file as follows:

    rcopy.bat

    net use \\sourceserver\robocopy /user: 
    "C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" \\sourceserver\robocopy\ \\targetserver\robocopy\ /MIR /MON:1 /LOG+:c:\rcopy.log

    I setup the Windows Schedule task in Windows Server 2003 to run at System Startup, when I reboot the server and then login, I found the robocopy.exe cannot access the \\sourceserver\robocopy\ folder. Here is an extract from the rcopy.log file:

    ----------begin----------

    -------------------------------------------------------------------------------
    ROBOCOPY :: Robust File Copy for Windows :: Version XP010
    -------------------------------------------------------------------------------
    Started : Thu Aug 05 12:53:03 2010
    2010/08/05 12:53:03 ERROR 53 (0x00000035) Getting File System Type of Source \\sourceserver\robocopy\ 
    The network path was not found.

    Source - \\sourceserver\robocopy\ 
    Dest : \\targetserver\robocopy\ 
    Files : *.*

    Options : *.* /S /E /COPY:DAT /PURGE /MIR /MON:1 /R:1000000 /W:30 
    ------------------------------------------------------------------------------
    2010/08/05 12:53:03 ERROR 53 (0x00000035) Accessing Source Directory \\sourceserver\robocopy\
    The network path was not found.
    Waiting 30 seconds... Retrying...
    2010/08/05 12:53:34 ERROR 1326 (0x0000052E) Accessing Source Directory \\sourceserver\robocopy\
    Logon failure: unknown user name or bad password.
    Waiting 30 seconds... Retrying...
    2010/08/05 12:54:08 ERROR 1326 (0x0000052E) Accessing Source Directory \\sourceserver\robocopy\
    Logon failure: unknown user name or bad password.
    Waiting 30 seconds... Retrying...
    ----------end----------

    How do I resolve this ?
    Thursday, August 05, 2010 7:21 AM

Answers

  • The robocopy document have the following instructions for scheudling robocopy jobs with Windows Task scheduler:

     

    Scheduling Robocopy Jobs
    You can create Robocopy jobs that run regularly and automatically in the background to maintain local mirrors of remote directory trees. In Windows 2000, use the AT command, or use the SOON command with the Windows 2000 Schedule service. (The SOON command runs Soon.exe, a Windows® 2000 Resource Kit tool named Near-Future Command Scheduler.)
    By default, the Schedule service logs on as the system account for the local system, which has no network access. Scheduled jobs run in the same context as the Schedule service. To run a scheduled Robocopy job, however, Robocopy must connect to network drives, which requires some additional configuration. The following sections describe two ways to accomplish this.
    Using the Local System Account
    You can leave the Schedule service running in the context of the local system account. You can then schedule batch files by using the following commands:

     NET USE \\remoteserver\IPC$ /USER:userid password
     ROBOCOPY \\remoteserver\sourcepath \\localserver\destpath ...
     NET USE \\remoteserver\IPC$ /DEL

    Within each job, credentials with remote servers are validated by connecting to the IPC$ (Interprocess Communication) share on remote computers using an appropriate user account, rather than the local system account. The disadvantage of this approach is that user passwords are stored in the batch files; however, passwords can be protected by storing the batch files on an NTFS volume, and setting appropriate NTFS permissions on the batch files.
    Using a User Account
    You can configure the Schedule service to log on as a user account. Once the user account has been granted appropriate access to source and destination servers, you can schedule Robocopy jobs to copy files between them.
    To configure the Schedule service to log on as a user account
     1. In Services in Control Panel, click Schedule, and then click Startup.
     2. In the Startup Type box, click Automatic or Manual.
     3. In the Log On As box, select the account in which to run the service, and specify the correct logon password.


    Tip
    Because drive mappings can be changed by users, it is more reliable to use UNC names for source and destination directories in scheduled Robocopy jobs. For example:
    ROBOCOPY \\server1\share1\source\\server2\share2\dest

     

    But neither instruction works for me, it seems that the first option have missed out the points to mention the case that the "net use" doesn't work when the scheduled task is set to "Run As System Startup". The reason why I do this is because I want to run the schedule job ONCE (even without any user logged on) and I supposed that applying the /MON:1 switch will cause robocopy to be resident in the memory. If someone remote connect to the server running robocopy scheduled job and reboot it, the I would expect the next time the server boots up, it will run the robocopy scheduled task for me.

    I tried the second option above but when I found that the Task Scheduler Windows Service will NOT be automatically started after I logon with another user account. But again since what I want is to have the robocopy scheduled task runs even WITHOUT any user logon. This option did not fulfill what I want.

    Monday, August 09, 2010 2:39 AM

All replies

  • I am going to ask the obvious here.. if you run the scheduled task (i.e right click run) does it work? Can you run the task under different credentials?
    Thursday, August 05, 2010 7:36 AM
  • The line

    net use \\sourceserver\robocopy /user:
    "C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" \\sourceserver\robocopy\ \\targetserver\robocopy\ /MIR /MON:1 /LOG+:c:\rcopy.log

    makes no sense. It appears to be a mix of "net use" and "robocopy.exe", with a dangling "/user" parameter but no user name. The problem would become apparent if, as NastyMatt suggests, you run the batch file from the Command Prompt.

    Thursday, August 05, 2010 8:26 AM
  • The line "net use \\sourceserver\robocopy /user:" doesn't make sense. You try to map a drive to \\Sourceserver\Robocopy but you fail to set which drive letter to use and "/User:" is not specified correctly, either leave it out or add username and password.

    The robocopy command line is looking fine, but according to the log the source is not a valid network path??? Can you access \\Sourceserver\Robocopy\ the share from the server?


    /Lasse
    Thursday, August 05, 2010 8:55 AM
  • When running your task as system make sure your the domainname\computername account has access to the share you are connecting to.

    /Thomas 

    Thursday, August 05, 2010 9:55 AM
  • My original batch file is:

    ---start---

    net use \\sourceserver\robocopy /user:username password

    "C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" \\sourceserver\robocopy\ \\targetserver\robocopy\ /MIR /MON:1 /LOG+:c:\rcopy.log

    ---end---

    I added angle brackets around username and password and somehow they caused the username & password disappeared in the post and I was not aware of it.

    Friday, August 06, 2010 1:43 AM
  • When I execute the net user \\sourceserver\robocopy\ /user:user password in the Command prompt, it runs successfully.

    Friday, August 06, 2010 1:46 AM
  • Change the command

    net use \\sourceserver\robocopy /user:username password

    to

    if not exist c:\Logs md c:\Logs
    net use \\sourceserver\robocopy /user:username password 1>c:\Logs\test.txt 2>&1

    so that you can examine the result of the command in c:\Logs\test.txt.

    Friday, August 06, 2010 6:02 AM
  • It have nothing to with with whether I added the "if not exist" or not. The problem is when the batch file is executed during System Startup in the Windows Scheduler, the net use command just failed to function.

    I have tried this:

    net use \\sourceserver\robocopy\ /user:username password

    dir \\sourceserver\robocopy > log.txt

     

    When the above commands were executed in the Command Prompt, it works perfectly, but when it is scheduled to run at System Startup in Windows Scheduler, I got nothing in the log.txt file.

    Friday, August 06, 2010 6:29 AM
  • If you run "net use \\sourceserver\robocopy /user:username password" on the server, is it then possible to access \\sourceserver\robocopy\?

    You could try to use driveletters instead of UNC paths and create a batchjob like this:

    Net use z: \\sourceserver\robocopy\ /user:username password

    Net use y: \\targetserver\robocopy\ /user:username password

    Robocopy.exe Z: Y: /MIR /MON:1 /LOG+:c:\rcopy.log


    /Lasse
    Friday, August 06, 2010 6:37 AM
  • Of course I can access \\sourceserver\robocopy \ after I executed the "net use \\sourceserver\robocopy /user:username password" on the server in the Command prompt.

     

    I have tried adding a drive letter and the same error occurs when I executed the batch file in the Windows Scheduler and set to Run As System Startup.

    Friday, August 06, 2010 6:39 AM
  • I have never tried using the run "At System Startup", but I assume it runs the job BEFORE a user is logged on to the server? If that's the case, which permissions does the user you are using with net use have?


    /Lasse
    Friday, August 06, 2010 8:07 AM
  • You need to be more careful when debugging your code. I suggested you should use this code:

    1>c:\Logs\test.txt 2>&1

    you modified it to

    > log.txt

    Your simplified approach suffers from two major problems:
    a) It fails to capture error output
    b) It does not specify a full path for the lot file. The file could be anywhere - it is probably in the System 32 folder.

    I recommend you repeat your tests, this time with proper logging so that you can see all messages generated by your commands.

    Friday, August 06, 2010 8:32 AM
  • If you run the script at system startup and the net use fails, then maybe the netcard and ip have yet to be initialized. Check if you can contact the sourceserver before you attempt to connect to it.

    psudo code:

    while NOT Ping(sourceserver) AND count < 10 { wait 5 seconds; count++; }

    if Ping(sourceserver) { robocopy stuff }

    /Thomas

    Friday, August 06, 2010 11:16 AM
  • You need to be more careful when debugging your code. I suggested you should use this code:

    1>c:\Logs\test.txt 2>%1

    you modified it to

    > log.txt

    Your simplified approach suffers from two major problems:
    a) It fails to capture error output
    b) It does not specify a full path for the lot file. The file could be anywhere - it is probably in the System 32 folder.

    I recommend you repeat your tests, this time with proper logging so that you can see all messages generated by your commands.


    You are right that I forgot there exists the 2> re-direction in DOS Command Prompt which I used it very often in UNIX.
    Monday, August 09, 2010 2:30 AM
  • The robocopy document have the following instructions for scheudling robocopy jobs with Windows Task scheduler:

     

    Scheduling Robocopy Jobs
    You can create Robocopy jobs that run regularly and automatically in the background to maintain local mirrors of remote directory trees. In Windows 2000, use the AT command, or use the SOON command with the Windows 2000 Schedule service. (The SOON command runs Soon.exe, a Windows® 2000 Resource Kit tool named Near-Future Command Scheduler.)
    By default, the Schedule service logs on as the system account for the local system, which has no network access. Scheduled jobs run in the same context as the Schedule service. To run a scheduled Robocopy job, however, Robocopy must connect to network drives, which requires some additional configuration. The following sections describe two ways to accomplish this.
    Using the Local System Account
    You can leave the Schedule service running in the context of the local system account. You can then schedule batch files by using the following commands:

     NET USE \\remoteserver\IPC$ /USER:userid password
     ROBOCOPY \\remoteserver\sourcepath \\localserver\destpath ...
     NET USE \\remoteserver\IPC$ /DEL

    Within each job, credentials with remote servers are validated by connecting to the IPC$ (Interprocess Communication) share on remote computers using an appropriate user account, rather than the local system account. The disadvantage of this approach is that user passwords are stored in the batch files; however, passwords can be protected by storing the batch files on an NTFS volume, and setting appropriate NTFS permissions on the batch files.
    Using a User Account
    You can configure the Schedule service to log on as a user account. Once the user account has been granted appropriate access to source and destination servers, you can schedule Robocopy jobs to copy files between them.
    To configure the Schedule service to log on as a user account
     1. In Services in Control Panel, click Schedule, and then click Startup.
     2. In the Startup Type box, click Automatic or Manual.
     3. In the Log On As box, select the account in which to run the service, and specify the correct logon password.


    Tip
    Because drive mappings can be changed by users, it is more reliable to use UNC names for source and destination directories in scheduled Robocopy jobs. For example:
    ROBOCOPY \\server1\share1\source\\server2\share2\dest

     

    But neither instruction works for me, it seems that the first option have missed out the points to mention the case that the "net use" doesn't work when the scheduled task is set to "Run As System Startup". The reason why I do this is because I want to run the schedule job ONCE (even without any user logged on) and I supposed that applying the /MON:1 switch will cause robocopy to be resident in the memory. If someone remote connect to the server running robocopy scheduled job and reboot it, the I would expect the next time the server boots up, it will run the robocopy scheduled task for me.

    I tried the second option above but when I found that the Task Scheduler Windows Service will NOT be automatically started after I logon with another user account. But again since what I want is to have the robocopy scheduled task runs even WITHOUT any user logon. This option did not fulfill what I want.

    Monday, August 09, 2010 2:39 AM
  • I am going to ask the obvious here.. if you run the scheduled task (i.e right click run) does it work? Can you run the task under different credentials?


    When I manually right click the scheduled task (which is already set to "Run As System Startup") and run it, it does executed once successfully (which means the net use command works). The robocopy job is also stay resident in memory since I added the /MON:1, but when I delete the files in \\targetserver\robocopy\ folder and wait for 1 minute, robocopy does not mirror the files from \\sourceserver\robocoopy\ folder to \\targetserver\robocopy\ at all. So my \\targetserver\robocopy\ will ALWAYS be empty after I have deleted all the files.

    I have tried using a different user credentials and the result is the SAME.

    Monday, August 09, 2010 3:02 AM
  • You need to be more careful when debugging your code. I suggested you should use this code:

    1>c:\Logs\test.txt 2>%1

    you modified it to

    > log.txt

    Your simplified approach suffers from two major problems:
    a) It fails to capture error output
    b) It does not specify a full path for the lot file. The file could be anywhere - it is probably in the System 32 folder.

    I recommend you repeat your tests, this time with proper logging so that you can see all messages generated by your commands.


    I have performed the testing again by including the following line:

    net use \\sourceserver\robocopy /user:username password

    dir \\sourceserver\robocopy 1> output.txt 2> error.txt

    When I executed the task with "Run As System Startup", I found that output.txt is empty and error.txt contains the line "The network path was not found."

    Monday, August 09, 2010 3:23 AM
  • I repeat what I wrote before:

    You need to be more careful when debugging your code. I suggested you should use this code:

    1>c:\Logs\test.txt 2>&1

    you modified it to

    > log.txt

    Your simplified approach suffers from two major problems:
    a) It fails to capture error output
    b) It does not specify a full path for the lot file. The file could be anywhere - it is probably in the System 32 folder.

    If you are not very careful in trouble-shooting then you keep running around in circles.

    Monday, August 09, 2010 6:12 AM
  • I repeat what I wrote before:

    You need to be more careful when debugging your code. I suggested you should use this code:

    1>c:\Logs\test.txt 2>%1

    you modified it to

    > log.txt

    Your simplified approach suffers from two major problems:
    a) It fails to capture error output
    b) It does not specify a full path for the lot file. The file could be anywhere - it is probably in the System 32 folder.

    If you are not very careful in trouble-shooting then you keep running around in circles.


    I missed out the path in my original post. I have actually wrote it as:

    net use \\sourceserver\robocopy /user:username password

    dir \\sourceserver\robocopy 1> c:\output.txt 2> c:\error.txt

     

    And the result is:

    c:\output.txt - no data written

    c:\error.txt - The network path was not found.

     

    Monday, August 09, 2010 9:20 AM
  • The answer is fairly obvious: Expand the error logging to both commands :

    net use \\sourceserver\robocopy /user:username password 1> c:\output.txt 2> c:\error.txt
    dir \\sourceserver\robocopy 1>> c:\output.txt 2>> c:\error.txt

    My preferred option is actually to use one single log file so that you know which error message belongs to which command:

    net use \\sourceserver\robocopy /user:username password 1> c:\output.txt 2>&1
    dir \\sourceserver\robocopy 1>> c:\output.txt 2>>&1

    Monday, August 09, 2010 10:02 AM
  • The answer is fairly obvious: Expand the error logging to both commands :

    net use \\sourceserver\robocopy /user:username password 1> c:\output.txt 2> c:\error.txt
    dir \\sourceserver\robocopy 1>> c:\output.txt 2>> c:\error.txt

    My preferred option is actually to use one single log file so that you know which error message belongs to which command:

    net use \\sourceserver\robocopy /user:username password 1> c:\output.txt 2>&1
    dir \\sourceserver\robocopy 1>> c:\output.txt 2>>&1


    I already know where the error message belongs to which command, it is the "net use" command which I mentioned already in previous message. Because there is ONLY  1 "net use" command line before the "dir" statement.

    Anyway, I have changed to use another approach to start robocopy in the Windows Task Scheduler. Thanks anyway.

    Tuesday, August 10, 2010 12:58 AM