2

I have a .bat file S:\BACKUP_db\copytofileserver.bat, which takes some files and zip them to the network drive. Its first command is to delete the old backup at specific network path, then pack the files in S:\BACKUP_db folder. See:

echo ================================================== >> log.txt
echo %date%, %time%: Backup started >> log.txt
set dow=%date:~0,3% >> log.txt

echo %time%: deleting existing backup... >> log.txt
del /F /S /Q /A "\\192.168.1.249\homes\backup\%dow%.7z"  >> log.txt
echo %time%: OK >> log.txt

echo %time%: packing and saving new backup... >> log.txt
if exist *.Backup S:\BACKUP_db\7za a -t7z -mx=1 "\\192.168.1.249\homes\backup\%dow%.7z" S:\Backup_db\*.Backup -m0=BCJ2 -m1=LZMA:d23 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3 >> log.txt
echo %time%: OK >> log.txt

echo %time%: deleting local backup files...  >> log.txt
del /F /S /Q /A S:\backup_db\*.Backup  >> log.txt
echo %time%: OK  >> log.txt

echo %date%, %time%: Backup finished >> log.txt

when I run this .bat file manually, it works like a charm (file is very big, cca 50 GB, when zipped it has cca 5 GB), however when I run this .bat file in windows scheduler job, it starts ok, deletes files in network location but then it is always stuck during execution of 7zip program. Windows scheduler says last run result= 0x41306.

Settings of the windows scheduler task seem correct: run only when user is logged on, "run with highest privileges" doesn't make a difference, etc.

Strange is, it worked before, now it is getting stuck and I have no idea why. Sometimes a 16MB zipped file is created at network destination, sometimes 2GB file, it seems random.

second round: well, this is what happend now - I set the bat file to run at specified time and observed black window with my commands being executed. It crashed again, the file was created: "\192.168.1.249\homes\qi\BackupQIostra\po .7z", it has 0.6 GB, it is supposed to have at least 5 GB. Also in the bat file I substituted all local paths with "%~dp0" as suggested, no change. Log file output:

================================================== 
po 04. 08. 2014, 11:00:00,40: Backup started 
11:00:00,44: deleting existing backup... 
Deleted file - \\192.168.1.249\homes\backup\po  .7z
11:00:00,49: OK 
11:00:00,50: packing and saving new backup... 

after this, I run the .bat file by double-click and observed what happens, zipping goes well, 5 GB file is created, log output is complete:

================================================== 
po 04. 08. 2014, 11:37:37,60: Backup started 
11:37:37,61: deleting existing backup... 
Deleted file - \\192.168.1.249\homes\backup\po  .7z
11:37:37,63: OK 
11:37:37,63: packing and saving new backup... 

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
Scanning

Creating archive \\192.168.1.249\homes\backup\po  .7z

Compressing  20225_20140804030000 - Copy.Backup
Compressing  20225_20140804030000.Backup

Everything is Ok
12:53:59,52: OK 
12:53:59,52: deleting local backup files...  
Deleted file - S:\BACKUP_db\20225_20140804030000 - Copy.Backup
Deleted file - S:\BACKUP_db\20225_20140804030000.Backup
12:54:02,18: OK  
po 04. 08. 2014, 12:54:02,18: Backup finished 
  • Getting a normal batch to run normally in the scheduler is always fun. "Why it be so weird" :-). If your indicating that it fully operated before via the scheduler, but fails at various times? What if it has something to do with files being open/locked? You have the zipping going to your log, but what did the zip program itself complain about? Also (I forget) sometimes the lack of a output window, a program expects to be able to talk to ? – Psycogeek Aug 2 '14 at 10:43
  • well, 7zip itself will make its output to the log file only after it is finished :( so when run from scheduler, the last thing I see in the log is the line: "time: packing and saving new backup..." and since it always creates a file in network location, I suppose it is running for some time and then something nasty happens and it crashes and log remains blank. – skroslak Aug 3 '14 at 7:09
  • troubleshoot. track it down to something smal like one line or a few lines that work differently – barlop Aug 4 '14 at 12:03
  • 7zip execution works differently, that I already know. I can't go deeper within that exe file :) Maybe I'll try to change compression program altogether and see if it is a problem with 7zip. – skroslak Aug 4 '14 at 15:40
  • 1
    Maybe you can make the zip action smaller and faster for testing purposes only, then keep testing it via the task scheduler run schedule, being different in its own way when run from there. – Psycogeek Aug 5 '14 at 4:42
1

it seems like delegating the task to hstart utility solved the issue. It is kind of workaround and I loose an ability to get any feedback from 7zip, but the bat file now works ok and completes the task.

so I replaced this: if exist *.Backup %~dp0\7za a -t7z -mx=1 "\192.168.1.249\homes\qi\BackupQIostra\%dow%.7z" %~dp0*.Backup -m0=BCJ2 -m1=LZMA:d23 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3 >> log.txt

with this: if exist .Backup "%~dp0hstart\hstart.exe" /NOCONSOLE /RUNAS /NOUAC /SHELL /WAIT /D="%~dp0" /BELOWNORMAL "%~dp07za a -t7z -mx=1 "\192.168.1.249\homes\qi\BackupQIostra\%dow%.7z" %~dp0.Backup -m0=BCJ2 -m1=LZMA:d23 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3" >> log.txt

BUT:

now when I observed it being run by scheduler, I noticed a strange thing. My .bat file is started, hstart runs 7zip command externaly and the main black command window which waits for completion of hstart/7zip task disappears after ~5mins! But the 7zip external command is still running, hidden, and completes correctly. Of course, the log file is not complete, still stack in the middle, since the main window crashed. So now I know for sure, that it is the main command window that is crashing.

0

I think current directory %systemroot%\System32 when start with service or sheduler. Probably need add:

CD S:\BACKUP_db\

  • Better yet is to use CD "%~dp0, which will work even if you move the files. You also should probably put %d0 on the line above (or below) that, to switch the same drive as the batch file. Grabbing the batch file's path is a good habit to get into. – trlkly Aug 2 '14 at 14:09
  • well, I'll try to run it like you guys suggest here, I'll post the results, though I'm a bit sceptical that the problem is in paths, because all commands are executed properly, just 7zip is being stopped randomly in the middle of the zipping process. – skroslak Aug 3 '14 at 7:11
0

I also got .bat file runned from sheduler. My problem was: at "Settings" tab it has "stop the task if it runs longer then:" and i changed that. But inside trigger it has the same thing. This what stopped my console application in 30 mins (set by default there). So it worked manually, but had 0x41306 error runned by shedule. I got here while searching for solution, hope it helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.