Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ive created a batch file to create a dump of a database and save it in a file with the current date as part of the file name. The batch file works brilliantly and all the data is saved correctly.

Ive now tried to set up a scheduled task to do this weekly, but ive run into a problem, although the task runs, the file it creates is empty, as if it has not pulled any data from the remote database. I know its pretty vague, but can anybody tell where id start looking for a reason/solution?

** EDIT **

Right, more progress - looks like it might be a path problem ive put a pause in the batch file, and when run through the task scheduler, it says:'mysqldump is not a recognized program'. However when run through the command line on my user account it works fine, just to confirm, ive set it run on the same user account ive been testing it on.

** EDIT 2 **

Ive found a sort of solution: ive had to refer the mysqldump application by its absolute path. However i still cant understand why it can find mysqldump from the path when run directly from the command line, but not when automated through the task scheduler

share|improve this question

Maybe the network was unavailable ? You could try scheduling it to run every 5/10 minutes, and see if the commands / variables are going correct. You sure that the script runs correctly when run as a whole and not just single command at a time ?

On your edit 2: Seems like mysqldump is not present in the PATH environment variables. Try adding that, and try again.

share|improve this answer
its not a network problem, i can run the entire batch file from the command line and it works ok, and i get the same problem trying to back up from my local mysql server – richzilla Nov 1 '10 at 22:56
yep this is the problem, it is in the path. in the path ive got c:\xampp\mysql\bin` where bin contains all of the mysql binaries. when running the batch file from the command line, i just need to refer to the application name - mysqldump. When running from the task scheduler, it refuses to work unless i provide the batch file with the full path to mysqldump.exe` – richzilla Nov 1 '10 at 23:46

Have you tried running mysqldump (in your scheduled task) in verbose mode? (--verbose)

Also, perhaps look at what user your task is running as, make sure that user has permissions to run mysqldump and create a file in the target directory.

share|improve this answer
The user the task is running as is the same as the user folder all the files are concerned with, so it shouldnt be a permissions problem. – richzilla Nov 1 '10 at 22:57
Ive tried the verbose flag, again it works fine if i run batch file from the command line, but if i run it from through the task scheduler,a command prompt flashes up and then immediately dissappears, i never get a chance to see what it says. – richzilla Nov 1 '10 at 23:03
  1. If giving absolute path solved your problem, it is not possible to create empty file. Instead no file created with windows scheduler log shows job successful.

  2. Your script might works on command line, if path variable holds the path information to mysqldump.exe. Check it by giving "path" command to command line.

  3. For your reference here is sample batch file I've used for mysql backup.

@echo off
SET DB_USER_PASS=[password]
SET DATABASE=[database name]
SET EXP_PATH=[backup path]
SET EXP_TMP_PATH=[temp path]
SET FILE_NAME=[backup filename]
For /f "tokens=1-3 delims=- " %%a in ('date /t') do (set today=%%a-%%b-%%c)

del /S /Q %EXP_PATH%

C:\Bitnami\redmine-2.5.2-0\mysql\bin\mysqldump.exe -u%DB_USER_ID% -p%DB_USER_PASS% %DATABASE% > %EXP_TMP_PATH%\%FILE_NAME%_%today%.sql
move %EXP_TMP_PATH%\%FILE_NAME%_%today%.sql %EXP_PATH%\%FILE_NAME%_%today%.sql
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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