We help IT Professionals succeed at work.

batch file does not compete in 2008 R2 Scheduled Task

716 Views
Last Modified: 2012-02-15
We have a consultant that deals with this software.  They backup our database every night with  a scheduled task. The script for the backup is attached.  As of right now the script continues to run.  It never finishes.  They swear that the script is correct.  What we believe is going on is the script is waiting for a response and it never happens since this is a scheduled task.

They want to say it is something with the scheduled task and not their script.  I have done some troubleshooting myself.  I have another batch file that copies the date and time to another file and this scheduled task works just fine with the same exact settings as the backup task.
Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
No script was attached.

Also, have you run the same script manually from a command prompt so see what it displays and if it does indeed prompt for input?

~bp

Author

Commented:
Here is the script:

echo Time and Date are... >> shutdown.log
time /t >> shutdown.log
date /t >> shutdown.log



pause

rem INSERT SERVICE STOPS HERE
echo Stopping FSI_Firstvoice... >> shutdown.log
net stop FSI_Firstvoice >> shutdown.log
echo Stopping FairwayWebIF... >> shutdown.log
net stop FairwayWebIF >> shutdown.log

pause

echo Archiving old export... >> shutdown.log
move /Y E:\Oracle\ADMIN\golf\exp\NewExp10g.dmp E:\Oracle\ADMIN\golf\exp\NewExp10g.dmp.old >> shutdown.log
move /Y E:\Oracle\ADMIN\exp\NewExp10g.log E:\Oracle\ADMIN\golf\exp\NewExp10g.log.old >> shutdown.log

pause

echo Taking new export >> shutdown.log
"C:\Program Files (x86)\Active Network\FSI\DBexecute\DBExecute.exe" exp "sys/#Password# file=E:\Oracle\ADMIN\golf\exp\NewExp10g.dmp full=y compress=y log=E:\Oracle\ADMIN\golf\exp\NewExp10g.log" golf

pause

echo Shutting down database... >> shutdown.log
"C:\Program Files (x86)\Active Network\FSI\DBexecute\DBExecute.exe" init shutdown golf >> shutdown.log

pause

rem ENABLE STAGED BACKUPS BELOW IF CLIENT HAS AT LEAST 20Gb FREE SPACE
copy /B /V /Y E:\Oracle\ADMIN\golf\exp\* e:\backup\
copy /B /V /Y E:\Oracle\ORADATA\golf\* e:\backup\

pause

exit;


I can not test the script during normal hours because this will shutdown our database.  The script was tested outside of Task Scheduler by the consultant and they said it completed successfully.  I am not able to test this yet myself so I am unsure if it actually works properly.
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Well, right off, every PAUSE in the script will require a keypress to continue, so I don't think you want those in there for the scheduled version.

~bp
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
I absolutlely agree to Bill's response. Having those PAUSE commands is stupid - it's just impossible they tested in an automated setup.

Remove all PAUSE commands.
For test, insert
  exit /b
before the
  echo Shutting down database... >> shutdown.log
That will prevent the database from being shut down, and the cold backup via copy commands will not be performed. That is ok for testing purpose, and so you can see if it works in general within business hours (and it will). Then you only need to test with the exit /b removed again to see if all steps are completing.
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
And at the risk of overwhelming you, I wanted to share my preferred approach to capturing logging from scheduled BAT scripts.  Rather than try to capture things line by line in the script, just remove the logging inside the script, as in:
@echo off

echo Script "%~f0" starting at %DATE% %TIME%

rem INSERT SERVICE STOPS HERE
echo Stopping FSI_Firstvoice...
net stop FSI_Firstvoice
echo Stopping FairwayWebIF...
net stop FairwayWebIF

echo Archiving old export...
move /Y E:\Oracle\ADMIN\golf\exp\NewExp10g.dmp E:\Oracle\ADMIN\golf\exp\NewExp10g.dmp.old
move /Y E:\Oracle\ADMIN\exp\NewExp10g.log E:\Oracle\ADMIN\golf\exp\NewExp10g.log.old

echo Taking new export...
"C:\Program Files (x86)\Active Network\FSI\DBexecute\DBExecute.exe" exp "sys/#Password# file=E:\Oracle\ADMIN\golf\exp\NewExp10g.dmp full=y compress=y log=E:\Oracle\ADMIN\golf\exp\NewExp10g.log" golf

echo Shutting down database...
"C:\Program Files (x86)\Active Network\FSI\DBexecute\DBExecute.exe" init shutdown golf

rem ENABLE STAGED BACKUPS BELOW IF CLIENT HAS AT LEAST 20Gb FREE SPACE
copy /B /V /Y E:\Oracle\ADMIN\golf\exp\* e:\backup\
copy /B /V /Y E:\Oracle\ORADATA\golf\* e:\backup\

echo Script "%~f0" ended at %DATE% %TIME%

Open in new window

Then, when you create the scheduled job in the windows task scheduler, do the command line as follows:

c:\scripts\yourscript.bat >c:\scripts\yourscript.log 2>&1

This will run the BAT script, and send ALL the output generated from it to the log file.  This will include any ECHO statements in the script, the standard output from all commands run, as well as any error messages displayed.  I find this to be much more effective than the approach the consultant took.

~bp
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.