0
@echo off
set day=%date:~7,2%
set month=%date:~4,2%
set year=%date:~10,4%
set today=%year%%month%%day%
mysqldump -u root -ppassword --host 192.168.1.1 DBNAME > C:\Users\Administrator\Documents\database\backup%today%.sql
echo Done!
exit

I have the above code in a bat file to back up my database. When I run this in cmd it backups the database no problem. When I ad it to the task scheduler that is where I get my problem. When I run it manually it says running for a long time and I dont know what is problem or if it is even running properly.

I see: enter image description here

Also in the destination folder I see a file but it has size of 0 but if i run this in cmd i get the correct size.

What is the cause of this in task scheduler

guradio
  • 15,524
  • 4
  • 36
  • 57
  • tasks are run under `local system account`. So trying to write under a `user account's directory` may fail due to not enough privileges. Set your task to run under a well known user account that has enough privileges to read the script and to write to destination folder. NOTE: Also, always use `full paths` or `unc paths` in task scheduler, not mapped drives. – elzooilogico Jan 24 '18 at 09:38
  • @elzooilogico by full path what you mean i have written the full path..also the account i use is the administrator..also the task was able to write. My thoughts are in the running of task because status says running for very long time but result is 0 kb – guradio Jan 24 '18 at 09:58
  • 1
    also try writing full path to `mysql` executable. Take into account that environment is per user based. may be the system cannot find it. something like `"c:\Program files (x86)\mysql\bin\mysqldump.exe" ...` NOTE. if there are spaces in exe's path, make sure you write it within quotation marks. – elzooilogico Jan 24 '18 at 10:00
  • @elzooilogico i see will try and see what happens :) i runs in cmd because i am in the folder of bin when i run the script didnt think of it will try it asap – guradio Jan 24 '18 at 10:13
  • 1
    @guradio Read the answer on [Executing BAT files in scheduled task](https://stackoverflow.com/a/41821620/3074564). The batch file is executed by Windows task scheduler in a completely different environment than when you with your user account run this batch file in a cmd window in your environment. You have to take the different environment into account in code of batch file. See also [%date% produces different result in batch file when run from Scheduled Tasks in Server 2016](https://stackoverflow.com/a/44670322/3074564). – Mofi Jan 24 '18 at 11:40
  • @Mofi noted will read on it – guradio Jan 24 '18 at 12:00
  • @elzooilogico can you provide it as answer when i write the entire path I got what I wanted – guradio Jan 25 '18 at 02:19

0 Answers0