简体   繁体   中英

Batch starts to run in Windows Scheduler, but does not execute all lines

I have a very simple batch that backs up a set of folders. I run the batch manually without any issue, but when I schedule it to run it start to run fine but never completes. It creates the appropraite dated folder and stops before it ever copies any folders/files.

Here is the code from the .bat

for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"

set datestamp=%MM%-%DD%-%YYYY%
echo datestamp: "%datestamp%"

md F:\MyArchives\%datestamp%
xcopy U:\Kristi\Project\*.* F:\MyArchives\%datestamp%\ /f/s

I have it set to run as my user name whether I am logged on or not. I have it set to run the highest privileges. It is sched for 1:45 am every day. I have checked Wake the computer to run this task. I am running Windows 7 Enterprise

When I look at the history in Scheduler, it states the following:

  • Task Triggered on Scheduler
  • Task Engine received message to start task
  • Tast Started
  • Action started
  • Created Task Process
  • Action completed
  • Task completed

I am at a loss. I have searched this site extensively and I have also googled it until I am blue in the face.

I have also exported the Task xml file and it is listed below:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2014-11-04T10:50:29.1301378</Date>
    <Author>AMERICAS\jfges</Author>
    <Description>Backs up the Projects folder to the Passport Drive every night.  This will create a dated folder that will need to be deleted eventually for space.  Batch is to run every night</Description>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2014-11-04T01:45:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>AMERICAS\jfges</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>false</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
    <WakeToRun>true</WakeToRun>
    <ExecutionTimeLimit>PT8H</ExecutionTimeLimit>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT10M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Users\jfges\Desktop\backup.bat</Command>
    </Exec>
  </Actions>
</Task>

I have tried to provide you guys with everything that I have seen anyone ask for on similar questions that I have read on here. I REALLY hope that someone is able to help me with this.

The only other thing that I can think to tell you is that I am trying to back up approx 17G of data each night. I wouldn't think that would matter since it is not even starting to copy the data over, but I thought I would mention it.

Any help would be greatly apprectiated!

There could be some reasons this doesn't work.
1. try to run the batch from cmd to see if it works (I assume you did that already)
2. xcopy to/from netword drive need mapping/privileges set - so do that
3. try adding "" around folders/path data as this might help, even with short names (even if having no space in their names)
4. you might need to use runas if no user is logged on (unsure in case of xcopy but if I remember right you'll need this)
5. Last but not least, check Event Viewer eventvwr.msc for the error. Hopefully you'll find indication of what went wrong. If not, make the task visible and try to repeat

If still struggling, "schedule the batch" to run when Windows starts (to see if Task Manager messes up something)
If all fails, please update the question accordingly (ie with the new data/information you collected).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM