windows 7 task schedule / mysqldump

0

I've 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.

I've now tried to set up a scheduled task to do this weekly, but I've 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 it's pretty vague, but can anybody tell where I'd start looking for a reason/solution?

** EDIT **

Right, more progress - looks like it might be a path problem I've 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, I've set it run on the same user account I've been testing it on.

** EDIT 2 **

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

richzilla

Posted 2010-11-01T17:09:49.877

Reputation: 2 003

Answers

1

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.

Sathyajith Bhat

Posted 2010-11-01T17:09:49.877

Reputation: 58 436

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 – 2010-11-01T22:56:27.780

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 – 2010-11-01T23:46:28.233

0

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.

Aerik

Posted 2010-11-01T17:09:49.877

Reputation: 690

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 – 2010-11-01T22:57:56.920

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 – 2010-11-01T23:03:30.067

0

  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_ID=[id]  
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%
md %EXP_PATH%
md %EXP_TMP_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

Heungwoo

Posted 2010-11-01T17:09:49.877

Reputation: 1